コード例 #1
0
        protected async Task <bool> CommitAsync()
        {
            if (_notifications.HasNotification())
            {
                return(false);
            }

            return(await _unitOfWork.CommitAsync());
        }
コード例 #2
0
        public Task <PurchaseOrder> NewPurchaseOrder(PurchaseOrder.INewPurchaseOrderBuilder newPurchaseOrderBuilder)
        {
            var entity = newPurchaseOrderBuilder.Build();

            if (!_notificationHandler.HasNotification())
            {
                _manager.List.Add(entity);
            }

            return(entity.AsTask());
        }
コード例 #3
0
        public async Task Should_Raise_Notification_When_Command_Is_Invalid()
        {
            //parameters
            var command = AddTaskCommandMock.GetInvalidDto();

            //call
            var handler = GetTasksHandler();

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

            //assert
            Assert.Null(result);
            Assert.True(_notificationHandler.HasNotification());
            Assert.Contains(command.ValidationResult.Errors, e => e.CustomState is EntityError.InvalidTaskName);
        }
コード例 #4
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());
        }
コード例 #5
0
        public Task <Product> InsertProductAsync(Product.Builder builder)
        {
            var entity = builder.Build();

            if (notificationHandler.HasNotification())
            {
                return(Task.FromResult <Product>(null));
            }

            entity.Id = Guid.NewGuid();

            list.Add(entity);

            return(entity.AsTask());
        }
コード例 #6
0
        public Customer InsertAndSaveChanges <TBuilder>(TBuilder builder)
            where TBuilder : IBuilder <Customer>
        {
            var entity = builder.Build();

            if (_notificationHandler.HasNotification())
            {
                return(null);
            }

            entity.Id = Guid.NewGuid();

            list.Add(entity);

            return(entity);
        }
コード例 #7
0
        public Guid InsertAndGetId <TBuilder>(TBuilder builder)
            where TBuilder : IBuilder <Customer>
        {
            var entity = builder.Build();

            if (notificationHandler.HasNotification())
            {
                return(Guid.Empty);
            }

            entity.Id = Guid.NewGuid();

            list.Add(entity);

            return(entity.Id);
        }
コード例 #8
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());
        }
コード例 #9
0
ファイル: UnitOfWork.cs プロジェクト: rmstreet/RedSpark.Thot
        public bool Commit()
        {
            // TODO: Verificar se podemos salvar as alterações
            if (!_notificationHandler.HasNotification())
            {
                _context.SaveChanges();
                return(true);
            }

            return(false);
        }
コード例 #10
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());
        }
コード例 #11
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;
            }
        }
コード例 #12
0
        /// <summary>
        /// Transacões aninhadas:
        /// Caso você precise trabalhar com este modelo siga o exemplo abaixo onde uma transação é aberta (Método CheckDuplicateOrder linha 50)
        /// com o paramêtro TransactionScopeOption definido para RequiresNew (isso significa que uma nova transação será criada)
        /// </summary>
        public async Task <PurchaseOrder> CreateNewPurchaseOrder(PurchaseOrder purchaseOrder)
        {
            using (var uow = unitOfWorkManager.Begin())
            {
                await CheckDuplicateOrder(purchaseOrder);

                if (notificationHandler.HasNotification())
                {
                    return(purchaseOrder);
                }

                purchaseOrder = await purchaseOrderRepository.CreateNewPurchaseOrder(purchaseOrder);

                await uow.CompleteAsync();
            }

            return(purchaseOrder);
        }
コード例 #13
0
        protected bool Commit()
        {
            if (_notification.HasNotification())
            {
                return(false);
            }

            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            _notification.Handle(new Notification("error", "Commit error!"));

            return(false);
        }
コード例 #14
0
        /// <summary>
        /// This method determines the response to the request processed by the business layer of the domain.
        /// </summary>
        /// <param name="commandResult">Result of the action returned by the business layer.</param>
        /// <returns>Response to request.</returns>
        protected CommandResponse FormatResponse(CommandResult commandResult)
        {
            CommandResponse commandResponse = new CommandResponse()
            {
                Success     = commandResult.Success,
                Message     = commandResult.Message,
                StatusCode  = commandResult.StatusCode,
                ElapsedTime = commandResult.ElapsedTime,
                Data        = commandResult.Data,
            };

            if (!commandResult.Success || _notificationHandler.HasNotification())
            {
                commandResponse.Errors = _notificationHandler.GetNotifications().Select(e => e.Notification).ToList();
            }

            return(commandResponse);
        }
コード例 #15
0
        protected void AddMessages()
        {
            if (_notifications.HasNotification())
            {
                _notifications.ListNotifications().ForEach(a =>
                {
                    switch (a.Key)
                    {
                    case ("error"):
                        TempData["errorMessage"] = a.Value;
                        break;

                    case ("info"):
                        TempData["infoMessage"] = a.Value;
                        break;

                    case ("success"):
                        TempData["successMessage"] = a.Value;
                        break;
                    }
                });
            }
        }
コード例 #16
0
 protected bool ValidOperation()
 {
     return(!_notifications.HasNotification());
 }
コード例 #17
0
ファイル: DomainService.cs プロジェクト: marcos-cruz/Holidays
 /// <summary>
 /// Determines whether there is an error.
 /// </summary>
 /// <returns><c>true</c> if there is an error, otherwise <c>false</c>.</returns>
 protected bool HasNotification()
 {
     return(_notificationHandler.HasNotification());
 }