public void MultipleServiceCanBeOptionalResolved() { // Arrange var services = new ServiceCollection(); var resolver = services.BuildServiceProvider(); var mvcResolver = new MicrosoftMvcDependencyResolver(resolver); // Act var actual = mvcResolver.GetServices(typeof(IFakeService)); // Assert Assert.Empty(actual); }
public void SingleServiceCanBeResolved() { // Arrange var services = new ServiceCollection(); services.AddTransient <IFakeService, FakeService>(); var resolver = services.BuildServiceProvider(); var mvcResolver = new MicrosoftMvcDependencyResolver(resolver); // Act var actual = mvcResolver.GetService(typeof(IFakeService)); // Assert Assert.NotNull(actual); Assert.IsType <FakeService>(actual); }
public void ControllerWithServiceCanBeResolved() { // Arrange var services = new ServiceCollection(); services.AddTransient <IFakeService, FakeService>(); services.AddMvcControllers(Assembly.GetExecutingAssembly()); var resolver = services.BuildServiceProvider(); var mvcResolver = new MicrosoftMvcDependencyResolver(resolver); // Act var actual = mvcResolver.GetService(typeof(FakeController)) as FakeController; // Assert Assert.NotNull(actual); Assert.IsType <FakeService>(actual.FakeService); }