Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# NUnit:断言集合具有具有特定属性值的项_C#_Asp.net Core_Nunit - Fatal编程技术网

C# NUnit:断言集合具有具有特定属性值的项

C# NUnit:断言集合具有具有特定属性值的项,c#,asp.net-core,nunit,C#,Asp.net Core,Nunit,我使用NUnit断言服务已正确添加到ASP.Net核心中的IServiceCollection 我正在尝试确保servicecollection有一个ServiceDescriptorServiceDescriptor,ServiceType的类型为MyClass。我如何用NUnit语法重写这个断言 IServiceCollection collection = ...; Assert.NotNull(collection.SingleOrDefault(sd => sd.ServiceT

我使用NUnit断言服务已正确添加到ASP.Net核心中的
IServiceCollection

我正在尝试确保servicecollection有一个ServiceDescriptor
ServiceDescriptor
,ServiceType的类型为
MyClass
。我如何用NUnit语法重写这个断言

IServiceCollection collection = ...;
Assert.NotNull(collection.SingleOrDefault(sd => sd.ServiceType == typeof(MyService)));
我想它看起来是这样的:

Assert.That(collection, Has.One.?????);
你想要

Assert.That(集合,Has.One.With.Property(“ServiceType”).EqualTo(typeof(MyService));

“With”是可选的,但似乎可以让它读得更好。

谢谢。如果“Property”方法能够做到这一点就太好了:
.Property(sd=>sd.ServiceType)
Yup,这是一个长期的增强请求。