Example #1
0
        public async void GetAllTest()
        {
            // Arrange
            var mockLogManager                = new Mock <ILogManager>();
            var mockClientRepository          = new Mock <IClientRepository>();
            var mockClientValidator           = new Mock <IClientValidator>();
            var mockAddressApplicationService = new Mock <IAddressApplicationService>();
            var mockContactApplicationService = new Mock <IContactApplicationService>();

            // Setup mock methods/ properties
            mockClientRepository.Setup(x => x.GetAllAsync())
            .Returns(Task.FromResult(new GetResponse <IReadOnlyList <IClient> > {
                Message = "Successful."
            }));

            // Act
            var sut = new ClientApplicationService(
                mockLogManager.Object, mockClientRepository.Object, mockClientValidator.Object, mockAddressApplicationService.Object, mockContactApplicationService.Object);
            var response = await sut.GetAllAsync();

            // 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.
            mockClientRepository.Verify(x => x.GetAllAsync());
        }
Example #2
0
        public async void GetAllErrorTest()
        {
            // Arrange
            var mockLogManager                = new Mock <ILogManager>();
            var mockClientRepository          = new Mock <IClientRepository>();
            var mockClientValidator           = new Mock <IClientValidator>();
            var mockAddressApplicationService = new Mock <IAddressApplicationService>();
            var mockContactApplicationService = new Mock <IContactApplicationService>();

            // Setup mock methods/ properties
            mockClientRepository.Setup(x => x.GetAllAsync())
            .Throws(new Exception());

            // Act
            var sut = new ClientApplicationService(
                mockLogManager.Object, mockClientRepository.Object, mockClientValidator.Object, mockAddressApplicationService.Object, mockContactApplicationService.Object);
            var response = await sut.GetAllAsync();


            // 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.
            mockClientRepository.Verify(x => x.GetAllAsync());

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