Пример #1
0
        public async void SaveTest()
        {
            // Arrange
            var mockLogManager                  = new Mock <ILogManager>();
            var mockAuditRepository             = new Mock <IAuditRepository>();
            var mockPolicyApplicationService    = new Mock <IPolicyApplicationService>();
            var mockClassCodeApplicationService = new Mock <IClassCodeApplicationService>();
            var mockAudit = new Mock <IAudit>();

            // Setup mock methods/properties
            mockAuditRepository.Setup(x => x.SaveAsync(It.IsNotNull <IAudit>()))
            .Returns(Task.FromResult(new SaveResponse <IAudit> {
                Message = "Successful."
            }));

            // Act
            var sut = new AuditApplicationService(
                mockLogManager.Object, mockAuditRepository.Object, mockPolicyApplicationService.Object, mockClassCodeApplicationService.Object);
            var response = await sut.SaveAsync(mockAudit.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.
            mockAuditRepository.Verify(x => x.SaveAsync(It.IsAny <IAudit>()));
        }
Пример #2
0
        public async void SaveErrorTest()
        {
            // Arrange
            var mockLogManager                  = new Mock <ILogManager>();
            var mockAuditRepository             = new Mock <IAuditRepository>();
            var mockPolicyApplicationService    = new Mock <IPolicyApplicationService>();
            var mockClassCodeApplicationService = new Mock <IClassCodeApplicationService>();
            var mockAudit = new Mock <IAudit>();

            // Setup mock methods/properties
            mockAuditRepository.Setup(x => x.SaveAsync(It.IsNotNull <IAudit>()))
            .Throws(new Exception());

            // Act
            var sut = new AuditApplicationService(
                mockLogManager.Object, mockAuditRepository.Object, mockPolicyApplicationService.Object, mockClassCodeApplicationService.Object);
            var response = await sut.SaveAsync(mockAudit.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.
            mockAuditRepository.Verify(x => x.SaveAsync(It.IsAny <IAudit>()));

            // Verify the application service is logging the error.
            mockLogManager.Verify(x => x.LogError(It.IsAny <Exception>(), It.IsAny <string>()));
        }