// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddMediatR(typeof(Startup), typeof(ChangePasswordCommand)); services.AddTransient <IUserBehaviorService, UserBehaviorService>(); services.AddTransient <IUserBehaviorGateway, UserBehaviorGateway>(); services.AddTransient <HttpClient, HttpClient>(); services.AddTransient <IExternalEventPublisherServ, ExternalEventPublisherServ>(); var policy = Policy .Handle <Exception>() .WaitAndRetryAsync(retryCount: 3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (_, __, retryCount, context) => { context["retryCount"] = retryCount; }); services.AddSingleton(policy); services.AddTransient <IEventGridGateway, EventGridGateway>(); var eventGridClient = new EventGridClient(new TopicCredentials("SomeTopicKey")); services.AddSingleton <IEventGridClient>(eventGridClient); services.AddTransient <IPasswordHistoryRepository, PasswordHistoryRespository>(); services.AddSingleton <ISimpleInMemoryDb>(SimpleInMemoryDb.InitializeDbWithDefaultSeedData()); }
/// <summary> /// This method could be place in its own class so it could be reused by several integration tests. /// </summary> /// <param name="eventGridGatewayMock"></param> /// <returns></returns> private ServiceProvider ConfigureDi(Mock <IEventGridGateway> eventGridGatewayMock) { var services = new ServiceCollection(); services.AddMediatR(typeof(ChangePasswordCommandTests), typeof(ChangePasswordCommand)); services.AddTransient <IExternalEventPublisherServ, ExternalEventPublisherServ>(); services.AddTransient <ChangePasswordCommand.ChangePasswordHandler, ChangePasswordCommand.ChangePasswordHandler>(); services.AddTransient <IUserBehaviorService, UserBehaviorService>(); var userBehaviorGateway = new Mock <IUserBehaviorGateway>(); userBehaviorGateway.Setup(mock => mock.IsPlatinumUser(It.IsAny <string>())).Returns("false"); services.AddTransient(_ => userBehaviorGateway.Object); services.AddTransient <IPasswordHistoryRepository, PasswordHistoryRespository>(); services.AddSingleton <ISimpleInMemoryDb>(SimpleInMemoryDb.InitializeDbWithDefaultSeedData()); var policy = Policy .Handle <Exception>() .WaitAndRetryAsync(retryCount: 3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (_, __, retryCount, context) => { context["retryCount"] = retryCount; }); services.AddSingleton(policy); services.AddTransient(_ => eventGridGatewayMock.Object); var eventGridClient = new EventGridClient(new TopicCredentials("SomeTopicKey")); services.AddSingleton <IEventGridClient>(eventGridClient); services.AddSingleton(Options.Create(new EventGridSettings() { InvoiceManagementTopicEndpoint = "http://someendpoint", InvoiceManagementTopicKey = "SomeTopicKey" })); services.AddLogging(); return(services.BuildServiceProvider()); }