/// <summary> /// Setups the base. /// </summary> public void SetupBase() { var serviceScope = new Mock <IServiceScope>(); var serviceScopeFactory = new Mock <IServiceScopeFactory>(); this.notificationsChannelMock = new Mock <INotificationsChannel>(); this.notificationsCarrierMock = new Mock <IWebNotificationsCarrier>(); this.serviceProviderMock = new Mock <IServiceProvider>(); _ = serviceScopeFactory.Setup(x => x.CreateScope()).Returns(serviceScope.Object); _ = serviceScope.Setup(x => x.ServiceProvider).Returns(this.serviceProviderMock.Object); _ = this.serviceProviderMock.Setup(sp => sp.GetService(typeof(INotificationsChannel))).Returns(this.notificationsChannelMock.Object); _ = this.serviceProviderMock.Setup(sp => sp.GetService(typeof(IWebNotificationsCarrier))).Returns(this.notificationsCarrierMock.Object); _ = this.serviceProviderMock.Setup(sp => sp.GetService(typeof(IServiceScopeFactory))).Returns(serviceScopeFactory.Object); this.notificationsCarrierService = new NotificationsCarrierService(this.serviceProviderMock.Object, NullLogger <NotificationsCarrierService> .Instance); }
public async Task ExceptionInExceuteAsync() { this.SetupBase(); _ = this.notificationsChannelMock.Setup(ncm => ncm.ReadAllNotificationsAsync(It.IsAny <CancellationToken>())).Throws(new Exception("Test exception.")); using var service = new NotificationsCarrierService(this.serviceProviderMock.Object, NullLogger <NotificationsCarrierService> .Instance); await service.StartAsync(default);
public void Ctor_ValidInput() { this.SetupBase(); using var service = new NotificationsCarrierService(this.serviceProviderMock.Object, NullLogger <NotificationsCarrierService> .Instance); Assert.IsTrue(service.GetType().FullName.Equals(typeof(NotificationsCarrierService).FullName)); }