public void UpdateTaskTest() { var testGuid = Guid.NewGuid(); var request = new UpdateTaskRequest(testGuid) { TaskProperties = new TaskEditDTO { Name = "test", Time = DateTime.Now, UserId = Guid.NewGuid() } }; var expectedResonse = new UpdateTaskResponse { Exception = null }; var mockService = new Mock <ITaskService>(); mockService.Setup(x => x.UpdateTask(request)).Returns(expectedResonse); var mockLogger = new Mock <ILoggingService>(); var mockEmail = new Mock <IEmailService>(); var mockConfig = new Mock <IAppConfig <IServiceConfigOptions> >(); var service = new EnrichedTaskService(mockService.Object, mockLogger.Object, mockEmail.Object, mockConfig.Object); var response = service.UpdateTask(request); Assert.IsNull(response.Exception); Assert.AreEqual(expectedResonse.Exception, response.Exception); mockService.Verify(x => x.UpdateTask(request), Times.Once); }
public void UpdateTaskInvalidTest() { var testGuid = Guid.NewGuid(); var request = new UpdateTaskRequest(testGuid) { TaskProperties = new TaskEditDTO { Time = DateTime.Now, UserId = Guid.NewGuid() } }; var expectedResonse = new UpdateTaskResponse { Exception = new ValidationException("invalid") }; var mockService = new Mock <ITaskService>(); mockService.Setup(x => x.UpdateTask(request)).Returns(expectedResonse); var mockLogger = new Mock <ILoggingService>(); var mockEmail = new Mock <IEmailService>(); mockEmail.Setup(x => x.SendEmail(It.IsAny <EmailArguments>())); var mockConfigOptions = new Mock <IServiceConfigOptions>(); mockConfigOptions.Setup(x => x.AdminEmail).Returns("test"); mockConfigOptions.Setup(x => x.ErrorEmailSubject).Returns("test"); mockConfigOptions.Setup(x => x.SmtpServer).Returns("test"); mockConfigOptions.Setup(x => x.SystemEmail).Returns("test"); var mockConfig = new Mock <IAppConfig <IServiceConfigOptions> >(); mockConfig.Setup(x => x.Options).Returns(mockConfigOptions.Object); var service = new EnrichedTaskService(mockService.Object, mockLogger.Object, mockEmail.Object, mockConfig.Object); var response = service.UpdateTask(request); Assert.IsNotNull(response.Exception); mockLogger.Verify(x => x.LogError(It.IsAny <object>(), "invalid", It.IsAny <ValidationException>()), Times.Once); mockEmail.Verify(x => x.SendEmail(It.IsAny <EmailArguments>()), Times.Once); }