예제 #1
0
        public async void DeleteErrorTest()
        {
            // 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
            mockAudit.Setup(c => c.Id).Returns(It.IsAny <int>());
            mockAuditRepository.Setup(x => x.DeleteAsync(It.IsAny <int>()))
            .Throws(new Exception());

            // Act
            var sut = new AuditApplicationService(
                mockLogManager.Object, mockAuditRepository.Object, mockPolicyApplicationService.Object, mockClassCodeApplicationService.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.
            mockAuditRepository.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>()));
        }
예제 #2
0
        public async void DeleteTest()
        {
            // 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
            mockAudit.Setup(c => c.Id).Returns(It.IsAny <int>());
            mockAuditRepository.Setup(x => x.DeleteAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(new DeleteResponse {
                Message = "Successful."
            }));

            // Act
            var sut = new AuditApplicationService(
                mockLogManager.Object, mockAuditRepository.Object, mockPolicyApplicationService.Object, mockClassCodeApplicationService.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.
            mockAuditRepository.Verify(x => x.DeleteAsync(It.IsAny <int>()));
        }
예제 #3
0
        public async void CreateTest()
        {
            // Arrange
            var mockLogManager                  = new Mock <ILogManager>();
            var mockAuditRepository             = new Mock <IAuditRepository>();
            var mockPolicyApplicationService    = new Mock <IPolicyApplicationService>();
            var mockClassCodeApplicationService = new Mock <IClassCodeApplicationService>();

            // Act
            var sut = new AuditApplicationService(
                mockLogManager.Object, mockAuditRepository.Object, mockPolicyApplicationService.Object, mockClassCodeApplicationService.Object);
            var createResponse = await sut.CreateAsync(It.IsAny <AuditRequest>());

            // Assert
            createResponse.IsSuccessful.Should().BeTrue();
            createResponse.Content.Should().NotBeNull();
            createResponse.Content.Id.Should().NotBe(0);
        }