小编yes*_*man的帖子

在单元测试时你如何等待任务?

在C#测试项目中,我有这个测试:

[TestMethod]
public void TestIfListFilled()
{
    // arrange
    byte stuffTypeID = 0;
    List<Stuff> locationList = null;

    // act
    locationList = GetStuffListAsync(stuffTypeID);

    // assert
    Assert.IsTrue(locationList.Count > 0);
}
Run Code Online (Sandbox Code Playgroud)

并且该GetStuffListAsync方法具有以下签名:

Task<List<Stuff>> GetStuffListAsync(Byte stuffTypeID)
Run Code Online (Sandbox Code Playgroud)

现在,我的第一个猜测是await在我的测试方法中添加一个方法调用之前.但是,我无法添加async到我的testmethod的签名,或者Visual Studio将开始抱怨.在执行断言之前,我该怎么做才能填充列表?

c#

1
推荐指数
1
解决办法
129
查看次数

为什么这个jQuery选择器找不到任何东西?

我在div里面有一个div.这个内部div有一个数据属性.我试图应用这个问题的答案找到内部div,但我没有运气.我究竟做错了什么?

var content = $('#mapElements').find('.mapMarker [data-depotid="b04b4184"]').data('depotguid');

$('#result').text(content);
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id='mapElements'>
  <div class="mapMarker" data-depotid="b04b4184">This is the text from mapMarker, and if the depotID appears below this text the code works!</div>
</div>

<div id='result'></div>
Run Code Online (Sandbox Code Playgroud)

javascript jquery

1
推荐指数
1
解决办法
59
查看次数

NewtonSoft SerializeObject 忽略 TypeNameHandling

按照官方文档

string jsonTypeNameAll = JsonConvert.SerializeObject(stockholder, Formatting.Indented, new JsonSerializerSettings
{
    TypeNameHandling = TypeNameHandling.All
});

Console.WriteLine(jsonTypeNameAll);
// {
//   "$type": "Newtonsoft.Json.Samples.Stockholder, Newtonsoft.Json.Tests",
//   "FullName": "Steve Stockholder",
//   "Businesses": {
//     "$type": "System.Collections.Generic.List`1[[Newtonsoft.Json.Samples.Business, Newtonsoft.Json.Tests]], mscorlib",
//     "$values": [
//       {
//         "$type": "Newtonsoft.Json.Samples.Hotel, Newtonsoft.Json.Tests",
//         "Stars": 4,
//         "Name": "Hudson Hotel"
//       }
//     ]
//   }
// }
Run Code Online (Sandbox Code Playgroud)

我已经复制粘贴了这段代码。

    public static string Convert<T>(T cacheObject)
    {
        return JsonConvert.SerializeObject(cacheObject, Formatting.Indented, new JsonSerializerSettings
        {
            TypeNameHandling = TypeNameHandling.All
        });
    }
Run Code Online (Sandbox Code Playgroud)

但是,如果我用 调用它Convert(DateTime.Now),我会得到一个序列化的 …

c# json.net

1
推荐指数
1
解决办法
1793
查看次数

PHP隐藏表单作为get请求处理

在PHP页面上,我的页面上有隐藏字段的按钮:

<form action="admin.php">
        <input name="action" value="delete" type="hidden">
        <input name="id" value="13" type="hidden">
        <input value="Delete user" type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)

在页面admin.php我有这个:

switch ($_POST['action'])
{
    case 'delete' :
        if ($_SESSION['role'] == 2)
        {
            if ($user->deleteUser($_POST['id']))
            {
                $_SESSION['alert'] = "User deleted.";
                $_SESSION['alert_type'] = "success";
            } else
            {
                $_SESSION['alert'] = "Something went wrong while deleting the user.";
                $_SESSION['alert_type'] = "error";
            }
        } else
        {
            $_SESSION['alert'] = "You are not allowed to delete a user. You need to be an admin.";
            $_SESSION['alert_type'] = "error";
        }
        $data = $user->getProfiles(); …
Run Code Online (Sandbox Code Playgroud)

html php post get hidden-field

0
推荐指数
1
解决办法
399
查看次数

PHP realpath无法阻止目录遍历

我收到了其他人的系统代码,该系统在浏览器中显示带有照片的文件夹.

例如,这是网站上可能的网址:

gallery.php?action=view&folder=Cars
Run Code Online (Sandbox Code Playgroud)

目前,您可以用../../../../../替换"Cars",这将很乐意显示Linux根文件夹.幸运的是,该网站目前处于离线状态.

我尝试使用realpath来解决这个问题.这是我到目前为止所拥有的:

case 'view' :
$name = realpath(dirname(__FILE__) . "/Content/Gallery/" . $_GET['folder']);

echo $name;

$data = $file->getPictures($name);
require 'Views/Gallery.view.php';
break;
Run Code Online (Sandbox Code Playgroud)

我在第三行添加了echo以查看URL是什么.在上面的url中,一切都很好,echo输出:

/var/www/Content/Gallery/Cars 
Run Code Online (Sandbox Code Playgroud)

到现在为止还挺好.但是,如果我输入/../../../../../../../../而不是"Cars",$ name变为/并且页面仍显示根文件夹.英语不是我的第一语言,所以我可能误解了真实路径的工作方式或工作原理.根据我的理解,它从给定的URL中删除../的任何实例.

有人可以告诉我我做错了什么吗?

php directory-traversal realpath

0
推荐指数
1
解决办法
1577
查看次数

按随机顺序循环遍历所有元素一次

我有这个数组:

var numberArray = [1, 2, 3]
Run Code Online (Sandbox Code Playgroud)

使用 jQuery,以随机顺序循环遍历该数组中的所有元素一次的最简单方法是什么?有效序列为3,2,1, 2,3,1, 无效序列为1,1,1, 或2,2,3

jquery

0
推荐指数
1
解决办法
1780
查看次数