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

时间:2019-06-28 09:07:16

标签: c# asp.net-core nunit

我正在使用NUnit断言已将服务正确添加到ASP.Net核心中的 _ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | | / ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | | /_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___| |___/ Angular CLI: 8.0.6 Node: 10.16.0 OS: linux x64 Angular: 8.0.3 ... animations, common, compiler, compiler-cli, core, forms ... language-service, platform-browser, platform-browser-dynamic ... router Package Version ----------------------------------------------------------- @angular-devkit/architect 0.800.6 @angular-devkit/build-angular 0.800.6 @angular-devkit/build-optimizer 0.800.6 @angular-devkit/build-webpack 0.800.6 @angular-devkit/core 8.0.6 @angular-devkit/schematics 8.0.6 @angular/cli 8.0.6 @ngtools/webpack 8.0.6 @schematics/angular 8.0.6 @schematics/update 0.800.6 rxjs 6.4.0 typescript 3.4.5 webpack 4.30.0

我正在尝试确保servicecollection具有一个IServiceCollection类型的ServiceDescriptor服务。我该如何用NUnit语法重写此断言?

MyClass

我认为它看起来像这样:

IServiceCollection collection = ...;
Assert.NotNull(collection.SingleOrDefault(sd => sd.ServiceType == typeof(MyService)));

1 个答案:

答案 0 :(得分:2)

你想要

Assert.That(collection, Has.One.With.Property("ServiceType").EqualTo(typeof(MyService)));

“ With”是可选的,但看起来使其读起来更好。