我可以将ApprovalTests与PDF一起使用吗?我尝试使用FileLauncher,但似乎相同的PDF在文件(位)级别略有不同.或者我错误地使用了它?
[TestMethod]
[UseReporter(typeof(FileLauncherReporter))]
public void TestPdf()
{
var createSomePdf = PdfCreate();
ApprovalTests.Approvals.Verify(new FileInfo(createSomePdf.FileName));
}
Run Code Online (Sandbox Code Playgroud) 我可以设置如下的断点(星号表示断点)吗?
var x = ifThis ?
* This() :
That() ;
Run Code Online (Sandbox Code Playgroud)
环境是C#和Visual Studio 2015.
(我刚告诉一位同事,我有可能,但似乎有所纠正)
目前,我使用ASP.NET Identity 2.0生成密码哈希.
是否可以使用新的ASP.NET Identity 3.0验证这些密码?
enum如何使用 Powershell 单元测试框架Pester进行测试?
我从测试者那里得到的似乎是一个字符串,而不是我自己的enum。
测试结果出现错误。我得到的Apple不是我的 enum [FruitType]::Apple。
...
Expected {[FruitEnum]::Apple}, but got {Apple}.
6: $res.TheFruit | Should -Be [FruitEnum]::Apple
...
Run Code Online (Sandbox Code Playgroud)
这里的 Powershell 模块将枚举设置为“公共”,并导出一个方法,该方法返回带有我的 Fruit 枚举的对象。
enum FruitEnum{
Apple
}
function Get-Fruit{
return @{
TheFruit = [FruitEnum]::Apple
}
}
Export-ModuleMember -Function Get-Fruit
Run Code Online (Sandbox Code Playgroud)
Pester 测试调用using以获取枚举,调用测试者并检查结果。
using module .\Fruit.psm1
Import-Module .\Fruit.psm1 -Force
Describe "Get-Fruit" {
It "returns an enum" {
$res = Get-Fruit
$res.TheFruit | Should -Be [FruitEnum]::Apple
}
}
Run Code Online (Sandbox Code Playgroud) 哪个版本build.exe是什么?
我有一台仅安装 Visual Studio 2017 (v15) 的机器。
然后我有2个msbuild.exe文件。一个在框架文件夹中,另一个在 Visual Studio 文件夹中。
除了版本不同,输出也不同。版本号不仅格式不同,信息类型也不同;框架版本与Visual Studio 版本。在不知道更好的情况下,Visual Studio 似乎有自己的 msbuild.exe,而不是从框架的派生而来。
C:\Windows\Microsoft.NET\Framework\v4.0.30319>msbuild /version
Microsoft (R) Build Engine version 4.7.3062.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.
4.7.3062.0
Run Code Online (Sandbox Code Playgroud)
对比
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin>msbuild /version
Microsoft (R) Build Engine version 15.6.85.37198 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
15.6.85.37198
Run Code Online (Sandbox Code Playgroud) 我已经遵循了SO示例代码和官方文档,但是我更改了我的Aspnet核心2.1项目中的密码长度没有任何变化.
我总是收到消息"密码必须至少为6,最多100个字符."
在public void ConfigureServices(IServiceCollection services)我尝试过
services.Configure<IdentityOptions>(options =>
{
options.Password.RequiredLength = 1;
});
Run Code Online (Sandbox Code Playgroud)
在各个地方,或添加到 AddDefaultIdentity<>
services.AddDefaultIdentity<IdentityUser>(options =>
options.Password.RequiredLength = 1;
)
.AddEntityFrameworkStores<ApplicationDbContext>();
Run Code Online (Sandbox Code Playgroud)
但无济于事.
我使用的是非脚手架版本,因此我无法访问HTML或cshtml文件.
我有一个嵌套的classFluentAssertions可以断言它们。
然后我class改为struct测试失败。
(如果我更改IEnumerable<ItemStruct> MyItems { get; set; }为ItemStruct MyItem { get; set; }在两种情况下比较都会成功。所以我想这与 IEnumerable 有关。)
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
namespace CowsCannotReadLogs.FileHandling.UnitTest
{
[TestClass]
public class TestFluentAssertionStruct
{
public struct DataStruct
{
public IEnumerable<string> MyItems { get; set; }
}
// Fails.
[TestMethod]
public void TestSimpleStruct()
{
var data1 = new DataStruct { MyItems = new[] { "A" } };
var data2 = new DataStruct …Run Code Online (Sandbox Code Playgroud) 不忽略xmlns属性是bug还是每个设计?
(蛋糕版本0.33.0)
使用这样的Xml(过于简化的nuspec文件):
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<!-- Continuously updated elements -->
<version>3.0.0</version>
</metadata>
</package>
Run Code Online (Sandbox Code Playgroud)
我天真地打个招呼就
var x = XmlPeek( "my.nuspec", "/package/metadata/version/text()" );
得到了结果x==null。
所以我这样指定名称空间:
var settings = new XmlPeekSettings{
Namespaces = new Dictionary<string, string> {{
"ps", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"
}}
};
var x = XmlPeek( "my.nuspec", "/ps:package/ps:metadata/ps:version/text()", settings);
Run Code Online (Sandbox Code Playgroud)
并得到x==3.0.0我预期的结果。
我的 API 返回一个object, 填充了匿名类型。我可以GET通过 HTTP 并解析为 json。
但是......我对同一方法的单元测试无法解析匿名类型。
使用 Dotnet 框架 4.7.2。
下面的代码显示了一个项目中
的调用者和另一个项目中的被调用者,
有 2 次不同的失败尝试。第二个是从 SO和这里复制的,没有评论它不起作用。但是……不适合我。
错误信息是:
System.InvalidCastException:无法将
类型为“<>f__AnonymousType1`2[System.String,System.String]”的对象转换
为类型“<>f__AnonymousType0`2[System.String,System.String]”。
在哪里可以看到类型是不同的。
但是 IIRC 前段时间有一个 dotnet 更新解决了这个问题,让它们“平等”。
我试图通过从 dotnet 框架 web api 返回匿名类型来解决用例。
(还有其他解决方案,如动态、反射、类型或更多端点,但这是另一个问题)
请注意,此测试用例不涉及 HTTP,它纯粹是 dotnet 框架问题。
public class MyController: ApiController
{
public object Get(string id)
{
return new { Key = id, Value = "val:" + id };
}
}
Run Code Online (Sandbox Code Playgroud)
[Fact]
public void MyTest
{ …Run Code Online (Sandbox Code Playgroud) 如何将ISearchResponse转换 为C#类对象.
我正在尝试转换为类对象,其中我的类名称将是动态的.
ISearchResponse<dynamic> bResponseNewLoop =
objElastic.Search<dynamic>(s => s
.Index("index1")
.Type("DOCTYPE")
.From(0)
.Size(10)
.Source(sr => sr.Include(RequiredFields)));
Run Code Online (Sandbox Code Playgroud)
从上面的Response,我想将响应对象转换为类对象和我正在从xml文件中恢复的类名.
c# ×6
asp.net-core ×2
asp.net ×1
cakebuild ×1
enums ×1
msbuild ×1
nest ×1
pester ×1
powershell ×1
testing ×1
unit-testing ×1