public void CreateSearchProviderException() { var serviceCollection = new ServiceCollection(); serviceCollection.AddTransient <ISearchProvider <ISearchRequestModel, ISearchResultModel> >(sp => throw new Exception()); var serviceProvider = serviceCollection.BuildServiceProvider(); var factory = new MicrosoftDependencyInjectionSearchServiceFactory(serviceProvider); Assert.Throws(typeof(SearchException), () => factory.CreateSearchProvider <ISearchRequestModel, ISearchResultModel>()); }
public void CreateSearchProviderSucceed() { var serviceCollection = new ServiceCollection(); var expected1 = new Mock <ISearchProvider <ISearchRequestModel, ISearchResultModel> >(); var expected2 = new Mock <ISearchProvider <ISearchRequestModel, ISearchResultModel> >(); serviceCollection.AddTransient(sp => expected1.Object); serviceCollection.AddTransient(sp => expected2.Object); var serviceProvider = serviceCollection.BuildServiceProvider(); var factory = new MicrosoftDependencyInjectionSearchServiceFactory(serviceProvider); var result = factory.CreateSearchProvider <ISearchRequestModel, ISearchResultModel>(); CollectionAssert.AreEquivalent(new [] { expected1.Object, expected2.Object }, result); }