コード例 #1
0
        public void Add_Tasks_With_Valid_Dto_Shoud_Not_Raise_Error()
        {
            //Arrange
            var name = "nome";

            var tasks = new Tasks();

            //Act
            var result = tasks.AddTask(name, _notificationHandler);


            //Assert
            Assert.False(_notificationHandler.HasNotification());
            Assert.DoesNotContain(_notificationHandler.GetAll(), e => e.DetailedMessage == Tasks.EntityError.InvalidTaskName.ToString());
        }
コード例 #2
0
        public async Task Handle(PurchaseOrderChangedMessage message)
        {
            try
            {
                var movimentBuilder = TaxMoviment
                                      .New(_notificationHandler)
                                      .ForPurchaseOrder(
                    message.PurchaseOrderId,
                    message.PurchaseOrderBaseValue,
                    message.PurchaseOrderDiscount);

                var options = new UnitOfWorkOptions()
                {
                    IsTransactional = true,
                    Scope           = TransactionScopeOption.Required,
                    IsolationLevel  = IsolationLevel.ReadCommitted
                };

                using (var uow = _unitOfWorkManager.Begin(options))
                {
                    await _domainService.InsertAndSaveChangesAsync(movimentBuilder);

                    await uow.CompleteAsync();
                }

                if (_notificationHandler.HasNotification())
                {
                    var messages = _notificationHandler
                                   .GetAll()
                                   .Select(s => s.Message)
                                   .JoinAsString(", ");

                    _logger.LogInformation($"Tax Moviment process found error {messages}");
                    return;
                }

                var moviment = movimentBuilder.Build();

                await Handle(new TaxMovimentCalculatedMessage()
                {
                    PurchaseOrderId = moviment.PurchaseOrderId,
                    Tax             = moviment.Tax,
                    TotalValue      = moviment.PurchaseOrderTotalValue
                });

                message.DoAck();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Handle PurchaseOrderChangedMessage");
                throw;
            }
        }
コード例 #3
0
        public async Task Should__Raise_Notification_When_Employee_Not_Exists()
        {
            //parameters
            var command = AddVoteCommandMock.GetValidDto();

            Employee employee = null;

            _employeeRepository.GetEmployeeById(command.EmployeeId).ReturnsForAnyArgs(x =>
            {
                return(employee);
            });

            //call
            var handler = GetVoteHandler();

            var result = await handler.Handle(command, new System.Threading.CancellationToken());

            //assert
            Assert.Null(result);
            Assert.True(_notificationHandler.HasNotification());
            Assert.Contains(_notificationHandler.GetAll(), e => e.DetailedMessage == Employee.EntityError.InvalidEmployee.ToString());
        }
コード例 #4
0
ファイル: EmployeeTest.cs プロジェクト: igorbmaciel/Poll
        public void Add_Employee_With_Valid_Dto_Shoud_Not_Raise_Error()
        {
            //Arrange
            var name     = "nome";
            var email    = "*****@*****.**";
            var password = "******";


            var employee = new Employee();

            //Act
            var result = employee.AddEmployee(name, email, password, _notificationHandler);


            //Assert
            Assert.False(_notificationHandler.HasNotification());
            Assert.DoesNotContain(_notificationHandler.GetAll(), e => e.DetailedMessage == Employee.EntityError.InvalidEmployeeName.ToString());
            Assert.DoesNotContain(_notificationHandler.GetAll(), e => e.DetailedMessage == Employee.EntityError.InvalidEmployeeEmail.ToString());
            Assert.DoesNotContain(_notificationHandler.GetAll(), e => e.DetailedMessage == Employee.EntityError.InvalidEmployeePassword.ToString());
        }
コード例 #5
0
        public void Add_Vote_With_Valid_Dto_Shoud_Not_Raise_Error()
        {
            //Arrange
            var employeeId = Guid.NewGuid();
            var tasksId    = Guid.NewGuid();
            var comment    = "new comment";


            var vote = new Vote();

            //Act
            var result = vote.AddVote(employeeId, tasksId, comment, _notificationHandler);


            //Assert
            Assert.False(_notificationHandler.HasNotification());
            Assert.DoesNotContain(_notificationHandler.GetAll(), e => e.DetailedMessage == Vote.EntityError.InvalidEmployeeId.ToString());
            Assert.DoesNotContain(_notificationHandler.GetAll(), e => e.DetailedMessage == Vote.EntityError.InvalidTaskId.ToString());
            Assert.DoesNotContain(_notificationHandler.GetAll(), e => e.DetailedMessage == Vote.EntityError.InvalidComment.ToString());
        }