コード例 #1
0
        public async Task Registrar_ocorrencia_de_ferias_com_sucesso()
        {
            // Arrange
            var mockContrato             = Substitute.For <Contrato>();
            var mockOcorrenciaRepository = Substitute.For <IOcorrenciaDeDeriasRepository>();
            var validation = new RegistrarOcorrenciaDeFeriasCommandValidation(mockOcorrenciaRepository);

            mockOcorrenciaRepository.ObtenhaOcorrenciasDoPeriodoAquisitivo(Arg.Any <Guid>(), Arg.Any <DateTime>())
            .Returns(new List <OcorrenciaDeFerias>());
            var mockColaboradorRepository = Substitute.For <IColaboradorRepository>();

            mockColaboradorRepository.BusqueColaborador(Arg.Any <Guid>())
            .Returns(new Colaborador(Guid.NewGuid(), NomePessoa.Crie("Codeizi", "Treinamento"), DateTime.Now.AddYears(-33)));
            mockColaboradorRepository.ObtenhaContrato(Arg.Any <Guid>()).Returns(mockContrato);
            var mockUOW = Substitute.For <IUnitOfWork>();

            mockUOW.Commit().ReturnsForAnyArgs(true);

            var mockMediator     = Substitute.For <IMediatorHandler>();
            var mockNotification = Substitute.For <INotificationHandler <DomainNotification>, DomainNotificationHandler>();

            var feriasCommand = new FeriasCommandHandler(mockOcorrenciaRepository,
                                                         mockColaboradorRepository,
                                                         mockUOW,
                                                         mockMediator,
                                                         mockNotification);

            var request = CenarioOcorrenciaDeFeriasCommandBuilder.Crie(validation);

            // Act
            var result = await feriasCommand.Handle(request, CancellationToken.None);

            // Assert
            Assert.True(result);
        }
コード例 #2
0
        public async Task Registrar_ocorrencia_de_ferias_com_falha_de_validacao()
        {
            // Arrange
            var mockContrato             = Substitute.For <Contrato>();
            var mockOcorrenciaRepository = Substitute.For <IOcorrenciaDeDeriasRepository>();
            var validation = new RegistrarOcorrenciaDeFeriasCommandValidation(mockOcorrenciaRepository);

            mockOcorrenciaRepository.ObtenhaOcorrenciasDoPeriodoAquisitivo(Arg.Any <Guid>(), Arg.Any <DateTime>())
            .Returns(new List <OcorrenciaDeFerias>()
            {
                new OcorrenciaDeFerias(mockContrato, new DateTime(2020, 1, 2), 30, 0),
            });
            var mockColaboradorRepository = Substitute.For <IColaboradorRepository>();

            mockColaboradorRepository.ObtenhaContrato(Arg.Any <Guid>()).Returns(mockContrato);
            var mockUOW = Substitute.For <IUnitOfWork>();

            mockUOW.Commit().ReturnsForAnyArgs(true);

            var mockMediator     = Substitute.For <IMediatorHandler>();
            var mockNotification = Substitute.For <INotificationHandler <DomainNotification>, DomainNotificationHandler>();

            var feriasCommand = new FeriasCommandHandler(mockOcorrenciaRepository,
                                                         mockColaboradorRepository,
                                                         mockUOW,
                                                         mockMediator,
                                                         mockNotification);

            var request = CenarioOcorrenciaDeFeriasCommandBuilder.Crie(validation);

            // Act
            var result = await feriasCommand.Handle(request, CancellationToken.None);

            // Assert
            Assert.False(result);
        }