我正在寻找一种方法来禁用用户而不是从系统中删除它们,这是为了保持相关数据的数据完整性.但似乎ASPNET身份只提供删除帐户.
有一个新的锁定功能,但似乎可以控制锁定以禁用用户,但只有在尝试了一定数量的错误密码后才能锁定用户.
还有其他选择吗?
我需要从给定的数组形成一个字符串.
假设array [1] = gvk,array [2] = gvk1和array [3] = gvk2,那么我需要将这些值转换为如下字符串:
Mystring = gvk | gvk1 | gvk2
在VS 2013上,我无法让这个异步测试失败.
我有xUnit 1.8.0.1539(从nuget安装),xUnit Test Runner VS扩展(0.99.5).目前所有的AFAIK.
我碰巧在单元测试中也有Moq,AutoFixture和FluentAssertions引用,但我认为不重要(但我承认它以防万一).
我已经在我的解决方案的其他方面完成了异步单元测试,并且它们可以工作.
我错过了这些新创建的测试,我不知道我错过了什么或做错了什么.
注意 SUT代码并不完整.在我编写代码以使测试变为绿色之前,我只是想先获得红灯.
这是测试代码:
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;
namespace MobileApp.Proxy.Test
{
public class WhenRetrievingPriceDataFromClient
{
[Fact]
public async Task GroupReportIsReturnedWithSomeData()
{
// arrange
var sut = new Client();
// act
var actual = await sut.GetReportGroupAsync();
// assert
// Xunit test
Assert.Null(actual);
Assert.NotNull(actual);
// FluentAssertions
actual.Should().BeNull();
actual.Should().NotBeNull();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是SUT代码:
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
using MobileApp.Proxy.Properties;
namespace MobileApp.Proxy
{
public class Client
{
public async …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的Web API设置单元测试.我已经在网上找到了一些我在网上找到的零碎的测试代码.我已经发送了测试请求并收到响应,但我仍然坚持测试响应.
所以这就是我到目前为止所拥有的.这是使用xunit测试包,但我不认为这对我想要实现的目标很重要.
(为代码混搭道歉)
[Fact]
public void CreateOrderTest()
{
string baseAddress = "http://dummyname/";
// Server
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute("Default", "api/{controller}/{action}/{id}",
new { id = RouteParameter.Optional });
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
HttpServer server = new HttpServer(config);
// Client
HttpMessageInvoker messageInvoker = new HttpMessageInvoker(new InMemoryHttpContentSerializationHandler(server));
// Order to be created
MotorInspectionAPI.Controllers.AccountController.AuthenticateRequest requestOrder = new MotorInspectionAPI.Controllers.AccountController.AuthenticateRequest() {
Username = "Test",
Password = "password"
};
HttpRequestMessage request = new HttpRequestMessage();
request.Content = new ObjectContent<MotorInspectionAPI.Controllers.AccountController.AuthenticateRequest>(requestOrder, new JsonMediaTypeFormatter());
request.RequestUri = new Uri(baseAddress + "api/Account/Authenticate");
request.Headers.Accept.Add(new …Run Code Online (Sandbox Code Playgroud) 我有这么简单的代码:
var entry = new DirectoryEntry("WinNT://DOMAIN/MachineName, Computer");
Console.WriteLine(entry.Guid);
Run Code Online (Sandbox Code Playgroud)
实际上,路径由命令行提供.编译这个简单的控制台应用程序用于测试,在我的测试中,我发现:
未处理的异常:System.IO.FileNotFoundException:找不到网络路径.
在System.DirectoryServices.Interop.UnsafeServices.DirectoryEntry.RefreshCache()的System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.GetInfo()处于System.DirectoryServices.DirectoryEntry.FillCache(String propertyName)的System.DirectoryServices.DirectoryEntry.get_NativeGuid()处于System.DirectoryServices D:\ GetDirectoryEntryProperties\Program.cs中的GetDirectoryEntryProperties.Program.Main(String [] args)中的.DirectoryEntry.get_Guid():第15行
有任何想法吗?
我是所有机器的管理员,但我确实有另一个由Device Lock服务引起的问题导致了UnauthorizedAccessException审讯,但在这种情况下我甚至无法读取机器的Guid.
事件日志显示没有任何用处.
卢克
我正在使用AutoFixture,Moq和XUnit扩展([Theory]属性),如本博客文章http://blog.ploeh.dk/2010/10/08/AutoDataTheorieswithAutoFixture中所述.
我注意到大多数单元测试看起来像这样:
[Theory, AutoMoqData]
public void Test(
[Frozen] Mock<IServiceOne> serviceOne,
[Frozen] Mock<IServiceTwo> serviceTwo,
MyClass classUnderTest)
{
// Arrange
serviceOne
.Setup(m => m.Get(It.IsAny<int>()));
serviceTwo
.Setup(m => m.Delete(It.IsAny<int>()));
// MyClass has a constructor with arguments for IServiceOne, and IServiceTwo
// classUnderTest will use the two mocks specified above
// Act
var result = classUnderTest.Foo();
// Assert
Assert.True(result);
}
Run Code Online (Sandbox Code Playgroud)
与总是装饰模具相反[Frozen],是否有办法设置夹具以始终冻结模具?
这是AutoMoqData属性:
public class AutoMoqDataAttribute : AutoDataAttribute
{
public AutoMoqDataAttribute()
: base(new Fixture().Customize(new AutoMoqCustomization()))
{
} …Run Code Online (Sandbox Code Playgroud) 我有以下测试代码.但无法在Test Explorer或Resharper中看到测试.我错过了什么?我已经公开了这个类,我尝试过清理项目,我在测试设置中尝试了两种默认体系结构.我正在运行Windows 7. xUnit 1.9.2,Resharper 8.1完整版
using Xunit;
namespace MonkeyFace.Specs.Registration
{
public class ValidApplicationReceived
{
[Trait("A valid application is submitted","")]
[Fact(DisplayName= "A user is added to the system")]
public void User_is_Add_To_System()
{
Debug.Print("hi");
Assert.Equal(1,1);
}
Run Code Online (Sandbox Code Playgroud) 以下代码演示了我的问题:
public class DynamicExample
{
public void DoSomething()
{
var x = new ExpandoObject();
dynamic d = x;
d.GetString = (Func<string>)(() => "Some Value");
d.GetString().SomeStringExtension(); // Doesn't work - expected
((string)d.GetString()).SomeStringExtension(); // Works - expected
Build(d).SomeStringExtension(); // Doesn't work - unexpected?
}
private static string Build(dynamic d)
{
return (string)d.GetString();
}
}
public static class StringExtensions
{
public static int SomeStringExtension(this string s)
{
return s.Length;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,为什么编译器在将内联类型转换为扩展方法调用并将其转换为单独的方法之间存在差异?
我正在为我的WinRT项目编写一些单元测试(使用xunit).
我准备了带有json内容的文本文件.我把这个文件放到我的Test项目中,现在我想读取文件,解析json并检查一些东西.它适用于MS Test,但没有使用xUnit.
当我用xUnit运行测试时,我收到:
System.InvalidOperationException该进程没有包标识.(HRESULT异常:0x80073D54)
[Fact]
public async Task ProjectFile()
{
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
folder = await folder.GetFolderAsync("SampleData");
var file = await folder.GetFileAsync("companies.txt");
Assert.NotNull(file);
var result = await Windows.Storage.FileIO.ReadTextAsync(file);
Assert.True(result.Length > 0);
}
Run Code Online (Sandbox Code Playgroud)
我的IDE:
有人可以在这帮吗?
在本地桌面和 Azure 中运行时,我看到一个不同的 Unicode 字符作为“de-CH”文化的数字组分隔符。
当以下代码在我的桌面上以 .NET Core 3.1 或 .NET Framework 4.7.2 运行时,它的输出2019看起来像一个撇号但不一样。
在 Azure 中运行时,例如在https://try.dot.net或(稍作修改)在 .NET Core 3.1(基于 Windows 的应用服务)上运行的 Azure 函数中0027,它会生成标准 ASCII 撇号。
using System;
using System.Linq;
using System.Globalization;
Console.WriteLine(((int)(CultureInfo
.GetCultureInfo("de-CH")
.NumberFormat
.NumberGroupSeparator
.Single())) // Just getting the single character as an int
.ToString("X4") // unicode value of that character
);
Run Code Online (Sandbox Code Playgroud)
这样做的结果是,尝试使用“de-CH”文化在本地桌面上解析字符串4'200.000(撇号是 Unicode 的0027地方)失败,但它在 Azure 中有效。
为什么会有差异?
c# ×6
xunit.net ×5
unit-testing ×3
xunit ×3
.net ×2
asp.net ×1
asynchronous ×1
autofixture ×1
azure ×1
c#-4.0 ×1
dynamic ×1
file-io ×1
localization ×1
moq ×1
postgresql ×1
resharper ×1
tdd ×1