Exemple #1
0
        public async void GetAllTest()
        {
            // Arrange
            var mockLogManager             = new Mock <ILogManager>();
            var mockRemunerationValidator  = new Mock <IRemunerationPayrollValidator>();
            var mockRemunerationRepository = new Mock <IRemunerationRepository>();

            // Setup mock methods/properties
            mockRemunerationRepository.Setup(x => x.GetAllAsync(It.IsAny <RemunerationRequest>()))
            .Returns(Task.FromResult(new GetResponse <IReadOnlyList <IRemunerationPayroll> > {
                Message = "Successful."
            }));

            // Act
            var sut = new RemunerationPayrollApplicationService(
                mockLogManager.Object, mockRemunerationRepository.Object, mockRemunerationValidator.Object);
            var response = await sut.GetAllAsync(It.IsAny <RemunerationRequest>());

            // 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.
            mockRemunerationRepository.Verify(x => x.GetAllAsync(It.IsAny <RemunerationRequest>()));
        }
Exemple #2
0
        public async void GetAllErrorTest()
        {
            // Arrange
            var mockLogManager             = new Mock <ILogManager>();
            var mockRemunerationValidator  = new Mock <IRemunerationPayrollValidator>();
            var mockRemunerationRepository = new Mock <IRemunerationRepository>();

            // Setup mock methods/properties
            mockRemunerationRepository.Setup(x => x.GetAllAsync(It.IsAny <RemunerationRequest>()))
            .Throws(new Exception());

            // Act
            var sut = new RemunerationPayrollApplicationService(
                mockLogManager.Object, mockRemunerationRepository.Object, mockRemunerationValidator.Object);
            var response = await sut.GetAllAsync(It.IsAny <RemunerationRequest>());

            // 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.
            mockRemunerationRepository.Verify(x => x.GetAllAsync(It.IsAny <RemunerationRequest>()));

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