public async void SaveTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockRuleSetRepository = new Mock <IRuleSetRepository>(); var mockRuleSetTranslator = new Mock <IRuleSetTranslator>(); var mockRuleAssemblyService = new Mock <IRuleSetAssemblyService>(); var mockRuleSet = new Mock <IRuleSet>(); // Setup mock methods/properties mockRuleSetRepository.Setup(x => x.SaveAsync(It.IsNotNull <IRuleSet>())) .Returns(Task.FromResult(new SaveResponse <IRuleSet> { Message = "Successful." })); // Act var sut = new RuleApplicationService( mockLogManager.Object, mockRuleSetRepository.Object, mockRuleSetTranslator.Object, mockRuleAssemblyService.Object); var response = await sut.SaveAsync(mockRuleSet.Object); // 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. mockRuleSetRepository.Verify(x => x.SaveAsync(It.IsAny <IRuleSet>())); }
public async void SaveErrorTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockRuleSetRepository = new Mock <IRuleSetRepository>(); var mockRuleSetTranslator = new Mock <IRuleSetTranslator>(); var mockRuleAssemblyService = new Mock <IRuleSetAssemblyService>(); var mockRuleSet = new Mock <IRuleSet>(); // Setup mock methods/properties mockRuleSetRepository.Setup(x => x.SaveAsync(It.IsNotNull <IRuleSet>())) .Throws(new Exception()); // Act var sut = new RuleApplicationService( mockLogManager.Object, mockRuleSetRepository.Object, mockRuleSetTranslator.Object, mockRuleAssemblyService.Object); var response = await sut.SaveAsync(mockRuleSet.Object); // 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. mockRuleSetRepository.Verify(x => x.SaveAsync(It.IsAny <IRuleSet>())); // Verify the application service is logging the error. mockLogManager.Verify(x => x.LogError(It.IsAny <Exception>(), It.IsAny <string>())); }