public async void DeleteTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockAuditTaskRepository = new Mock <IAuditTaskRepository>(); var mockAuditTask = new Mock <IAuditTask>(); // Setup mock methods/properties mockAuditTask.Setup(c => c.Id).Returns(It.IsAny <int>()); mockAuditTaskRepository.Setup(x => x.DeleteAsync(It.IsAny <int>())) .Returns(Task.FromResult(new DeleteResponse { Message = "Successful." })); // Act var sut = new AuditTaskApplicationService( mockLogManager.Object, mockAuditTaskRepository.Object); var response = await sut.DeleteAsync(It.IsAny <int>()); // Assert response.IsSuccessful.Should().BeTrue(); response.Errors.Count.Should().Be(0); response.Message.Should().NotBeNullOrEmpty(); // Verify the application service is calling the correct repository method. mockAuditTaskRepository.Verify(x => x.DeleteAsync(It.IsAny <int>())); }
public async void SaveAllTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockAuditTaskRepository = new Mock <IAuditTaskRepository>(); var mockAuditTasks = new List <IAuditTask> { new Mock <IAuditTask>().Object }; // Setup mock methods/properties mockAuditTaskRepository.Setup(x => x.SaveAllAsync(It.IsAny <IReadOnlyList <IAuditTask> >())) .Returns(Task.FromResult(new SaveResponse <IReadOnlyList <IAuditTask> > { Message = "Successful." })); // Act var sut = new AuditTaskApplicationService( mockLogManager.Object, mockAuditTaskRepository.Object); var response = await sut.SaveAllAsync(mockAuditTasks); // Assert response.IsSuccessful.Should().BeTrue(); response.Errors.Count.Should().Be(0); response.Message.Should().NotBeNullOrEmpty(); // Verify the application service is calling the correct repository method. mockAuditTaskRepository.Verify(x => x.SaveAllAsync(It.IsAny <IReadOnlyList <IAuditTask> >())); }
public async void DeleteErrorTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockAuditTaskRepository = new Mock <IAuditTaskRepository>(); var mockAuditTask = new Mock <IAuditTask>(); // Setup mock methods/properties mockAuditTask.Setup(c => c.Id).Returns(It.IsAny <int>()); mockAuditTaskRepository.Setup(x => x.DeleteAsync(It.IsAny <int>())) .Throws(new Exception()); // Act var sut = new AuditTaskApplicationService( mockLogManager.Object, mockAuditTaskRepository.Object); var response = await sut.DeleteAsync(It.IsAny <int>()); // Assert response.IsSuccessful.Should().BeFalse(); response.Errors.Count.Should().BeGreaterThan(0); response.Message.Should().NotBeNullOrEmpty(); // Verify the application service is calling the correct repository method. mockAuditTaskRepository.Verify(x => x.DeleteAsync(It.IsAny <int>())); // Verify the application service is logging the error. mockLogManager.Verify(x => x.LogError(It.IsAny <Exception>(), It.IsAny <string>())); }
public async void CreateTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockAuditTaskRepository = new Mock <IAuditTaskRepository>(); // Act var sut = new AuditTaskApplicationService( mockLogManager.Object, mockAuditTaskRepository.Object); var createResponse = await sut.CreateAsync(); // Assert createResponse.IsSuccessful.Should().BeTrue(); createResponse.Content.Should().NotBeNull(); }