public void InsertTaskTest() { var request = new InsertTaskRequest { TaskProperties = new TaskEditDTO { Name = "test", Time = DateTime.Now, UserId = Guid.NewGuid() } }; var expectedResonse = new InsertTaskResponse { Exception = null }; var mockService = new Mock <ITaskService>(); mockService.Setup(x => x.InsertTask(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.InsertTask(request); Assert.IsNull(response.Exception); Assert.AreEqual(expectedResonse.Exception, response.Exception); mockService.Verify(x => x.InsertTask(request), Times.Once); }
public void DeleteTaskTest() { var testGuid = Guid.NewGuid(); var request = new DeleteTaskRequest(testGuid); var expectedResonse = new DeleteTaskResponse { Exception = null }; var mockService = new Mock <ITaskService>(); mockService.Setup(x => x.DeleteTask(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.DeleteTask(request); Assert.IsNull(response.Exception); Assert.AreEqual(expectedResonse.Exception, response.Exception); mockService.Verify(x => x.DeleteTask(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); }
public void GetTasksTest() { var mockService = new Mock <ITaskService>(); 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 request = new GetTasksRequest(); service.GetTasks(request); mockService.Verify(x => x.GetTasks(request), Times.Once); }