I'm using NUnit to assert that a service is properly added to the IServiceCollection
in ASP.Net core.
I'm trying to make sure the servicecollection has one ServiceDescriptor
with ServiceType of type MyClass
. How would I rewrite this assertion in NUnit syntax?
IServiceCollection collection = ...;
Assert.NotNull(collection.SingleOrDefault(sd => sd.ServiceType == typeof(MyService)));
I assume it would look something like this:
Assert.That(collection, Has.One.?????);
You want
Assert.That(collection, Has.One.With.Property("ServiceType").EqualTo(typeof(MyService)));
The "With" is optional but seems to make it read better.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.