Example #1
0
        public async Task Receive(string queueName, Type type)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_ConnectionString);
            CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
            CloudQueue          queue          = queueClient.GetQueueReference(queueName);

            string messageText = "";

            do
            {
                var message = await ReceiveMessageAsync(queue);

                if (message == null)
                {
                    continue;
                }

                messageText = message.ToString();
                try
                {
                    CustomerCommandHandler obj = new CustomerCommandHandler(_CustomerService);

                    var CustomerCommand = Newtonsoft.Json.JsonConvert.DeserializeObject(messageText, type);

                    var context = obj.GetType();

                    var method = context.GetMethod("Handle", new Type[] { type });

                    method.Invoke(obj, new object[] { CustomerCommand });
                }
                catch (Exception ex) { Console.WriteLine(messageText); };
                System.Threading.Thread.Sleep(1000);
            } while (true);
        }
Example #2
0
        private CommandDispatcher CreateCommandDispatcher(IDomainRepository domainRepository, IEnumerable <Action <ICommand> > preExecutionPipe, IEnumerable <Action <object> > postExecutionPipe)
        {
            var commandDispatcher = new CommandDispatcher(domainRepository, preExecutionPipe, postExecutionPipe);

            var customerCommandHandler = new CustomerCommandHandler(domainRepository);

            commandDispatcher.RegisterHandler <CreateCustomer>(customerCommandHandler);
            commandDispatcher.RegisterHandler <MarkCustomerAsPreferred>(customerCommandHandler);

            var productCommandHandler = new ProductCommandHandler(domainRepository);

            commandDispatcher.RegisterHandler(productCommandHandler);

            var basketCommandHandler = new BasketCommandHandler(domainRepository);

            commandDispatcher.RegisterHandler <CreateBasket>(basketCommandHandler);
            commandDispatcher.RegisterHandler <AddItemToBasket>(basketCommandHandler);
            commandDispatcher.RegisterHandler <ProceedToCheckout>(basketCommandHandler);
            commandDispatcher.RegisterHandler <CheckoutBasket>(basketCommandHandler);
            commandDispatcher.RegisterHandler <MakePayment>(basketCommandHandler);

            var orderCommandHanler = new OrderHandler(domainRepository);

            commandDispatcher.RegisterHandler <ApproveOrder>(orderCommandHanler);
            commandDispatcher.RegisterHandler <StartShippingProcess>(orderCommandHanler);
            commandDispatcher.RegisterHandler <CancelOrder>(orderCommandHanler);
            commandDispatcher.RegisterHandler <ShipOrder>(orderCommandHanler);

            return(commandDispatcher);
        }
Example #3
0
        private static void Publish <T>(T message) where T : Message
        {
            var messageType = message.MessageType;

            if (messageType.Equals("DomainNotification"))
            {
                var obj = new DomainNotificationHandler();
                ((IDomainNotificationHandler <T>)obj).Handle(message);
            }

            if (messageType.Equals("AddCustomerCommand") ||
                messageType.Equals("UpdateCustomerCommand") ||
                messageType.Equals("DeleteCustomerCommand"))
            {
                var obj = new CustomerCommandHandler(new FakeCustomerRepository(), new FakeUow(), new FakeBus(), new DomainNotificationHandler());
                ((IHandler <T>)obj).Handle(message);
            }

            if (messageType.Equals("AddedCustomerEvent") ||
                messageType.Equals("UpdatedCustomerEvent") ||
                messageType.Equals("DeletedCustomerEvent"))
            {
                var obj = new CustomerEventHandler();
                ((IHandler <T>)obj).Handle(message);
            }
        }
 public CustomerController(
     CustomerCommandHandler commandHandler,
     CustomerQueryHandler queryHandler)
 {
     _commandHandler = commandHandler;
     _queryHandler   = queryHandler;
 }
 public CustomerController(CustomerCommandHandler customerCommandHandler, ICustomerRepository customerRepository,
                           IEmailService emailService,
                           IUow uow) : base(uow)
 {
     _customerRepository = customerRepository;
     _emailService       = emailService;
     _handler            = customerCommandHandler;
 }
Example #6
0
        public void ErrorUpdateCustomerIdCustomer()
        {
            var command       = new UpdateCustomerCommand(0, null, null, null, null, false, _appSettings);
            var commandResult = new CustomerCommandHandler(_mapper, _customerRepo.Object, _userRepo.Object)
                                .Handle(command, new CancellationToken()).Result;

            Assert.True(commandResult.HasError(1009));
        }
Example #7
0
        public void ErrorUpdateCustomerPassword(string password, int errorCode)
        {
            var command       = new UpdateCustomerCommand(0, null, null, password, null, false, _appSettings);
            var commandResult = new CustomerCommandHandler(_mapper, _customerRepo.Object, _userRepo.Object)
                                .Handle(command, new CancellationToken()).Result;

            Assert.True(commandResult.HasError(errorCode));
        }
Example #8
0
        public void ErrorCreateCustomerAddress(string address, int errorCode)
        {
            var command       = new CreateCustomerCommand(null, null, null, address, _appSettings);
            var commandResult = new CustomerCommandHandler(_mapper, _customerRepo.Object, _userRepo.Object)
                                .Handle(command, new CancellationToken()).Result;

            Assert.True(commandResult.HasError(errorCode));
        }
Example #9
0
        public EditCustomerViewModel(int id)
        {
            this.context = new BankAppDataContext();
            this.customerCommandHandler = new CustomerCommandHandler(context);
            this.customerQueriesHandler = new CustomerQueriesHandler(context);

            Customer = customerQueriesHandler.GetCustomer(id);
            Birthday = (DateTime)Customer.Birthday;
        }
        public void ShouldNotCreatePaymentMethod_When_CommandIsInvalid()
        {
            var command = new CreatePaymentMethodCommand("", "", "", Guid.NewGuid());
            var handler = new CustomerCommandHandler(new CustomerRepositoryMock(), null);

            var result = handler.Handle(command);

            Assert.False(result.IsValid);
        }
        public void ShouldCreatePaymentMethod_When_CommandIsValid()
        {
            var command = new CreatePaymentMethodCommand("James B", "1234 1234 1234 1234", "1234", Guid.NewGuid());
            var handler = new CustomerCommandHandler(new CustomerRepositoryMock(), null);

            var result = handler.Handle(command);

            Assert.True(result.IsValid);
        }
        public void ShouldCreateCustomer_When_CommandIsValid()
        {
            var command = new CreateCustomerCommand("James Bond", "*****@*****.**", "+44 1111 1111");
            var handler = new CustomerCommandHandler(new CustomerRepositoryMock(), null);

            var result = handler.Handle(command);

            Assert.True(result.IsValid);
        }
Example #13
0
        public void ErrorUpdateCustomerIdCustomerNotExists()
        {
            _customerRepo.Setup(s => s.IdCustomerExists(It.IsAny <int>())).Returns(Task.FromResult(false));

            var command       = new UpdateCustomerCommand(1, "Luciano Pereira", "[email protected]", "abc123", "New York", true, _appSettings);
            var commandResult = new CustomerCommandHandler(_mapper, _customerRepo.Object, _userRepo.Object)
                                .Handle(command, new CancellationToken()).Result;

            Assert.True(commandResult.HasError(2005));
        }
Example #14
0
 public CustomerTicketController(CustomerCommandHandler customerCommandHandler,
                                 CustomerQueryHandler customerQueryHandler,
                                 TicketCommandHandler ticketCommandHandler,
                                 TicketQueryHandler ticketQueryHandler)
 {
     _customerCommandHandler = customerCommandHandler;
     _customerQueryHandler   = customerQueryHandler;
     _ticketCommandHandler   = ticketCommandHandler;
     _ticketQueryHandler     = ticketQueryHandler;
 }
Example #15
0
        public void ErrorCreateCustomerEmailExists()
        {
            _userRepo.Setup((s) => s.EmailExists(It.IsAny <string>())).Returns(Task.FromResult(true));

            var command       = new CreateCustomerCommand("Luciano Pereira", "[email protected]", "abc123", "New York", _appSettings);
            var commandResult = new CustomerCommandHandler(_mapper, _customerRepo.Object, _userRepo.Object)
                                .Handle(command, new CancellationToken()).Result;

            Assert.True(commandResult.HasError(2002));
        }
Example #16
0
        public void Setup()
        {
            options = new DbContextOptionsBuilder <BankAppDataContext>()
                      .UseInMemoryDatabase(databaseName: "TestingDb")
                      .Options;

            systemClock               = Substitute.For <ISystemClock>();
            context                   = new BankAppDataContext(options);
            accountQueriesHandler     = new AccountQueriesHandler(context);
            accountCommandHandler     = new AccountCommandHandler(context);
            customerCommandHandler    = new CustomerCommandHandler(context);
            customerQueriesHandler    = new CustomerQueriesHandler(context);
            dispositionQueriesHandler = new DispositionQueriesHandler(context);
        }
        public void CustomerHandlerTests_CreateCustomer_Should_Be_Valid()
        {
            var command = new CreateCustomerCommand();

            command.Nome      = "Ray";
            command.Sobrenome = "Carneiro";
            command.Documento = "72092578022";
            command.Email     = "*****@*****.**";
            command.Telefone  = "";

            var handler = new CustomerCommandHandler(new FakeCustomerRepositoryTests());

            Assert.AreEqual(true, handler.IsValid);
        }
Example #18
0
        public void ErrorUpdateCustomerEmailExistsDifferentUser()
        {
            _customerRepo.Setup(s => s.IdCustomerExists(It.IsAny <int>())).Returns(Task.FromResult(true));
            var customer = new Servico.Entities.Customer(1, 1, "MY NAME", "MY ADDRESS");

            _customerRepo.Setup(s => s.GetCustomer(It.IsAny <int>())).Returns(Task.FromResult(customer));
            _userRepo.Setup((s) => s.EmailExistsDifferentUser(It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(true));

            var command       = new UpdateCustomerCommand(1, "Cassio Guilhermy", "[email protected]", "cass123", "Gyn", true, _appSettings);
            var commandResult = new CustomerCommandHandler(_mapper, _customerRepo.Object, _userRepo.Object)
                                .Handle(command, new CancellationToken()).Result;

            Assert.True(commandResult.HasError(2003));
        }
Example #19
0
        public void ErrorUpdateCustomerIdUserNotExists()
        {
            _customerRepo.Setup(s => s.IdCustomerExists(It.IsAny <int>())).Returns(Task.FromResult(true));
            var customer = new Domain.Entities.Customer(1, 1, "MY NAME", "MY ADDRESS");

            _customerRepo.Setup(s => s.GetCustomer(It.IsAny <int>())).Returns(Task.FromResult(customer));
            _userRepo.Setup((s) => s.IdUserExists(It.IsAny <int>())).Returns(Task.FromResult(false));

            var command       = new UpdateCustomerCommand(1, "Luciano Pereira", "[email protected]", "abc123", "New York", true, _appSettings);
            var commandResult = new CustomerCommandHandler(_mapper, _customerRepo.Object, _userRepo.Object)
                                .Handle(command, new CancellationToken()).Result;

            Assert.True(commandResult.HasError(2000));
        }
        public void CustomerHandlerTests_CreateCustomer_Should_Create_Successfully()
        {
            var command = new CreateCustomerCommand();

            command.Nome      = "Ray";
            command.Sobrenome = "Carneiro";
            command.Documento = "72092578022";
            command.Email     = "*****@*****.**";
            command.Telefone  = "";

            var handler = new CustomerCommandHandler(new FakeCustomerRepositoryTests());
            var result  = handler.Handle(command);

            Assert.AreNotEqual(null, result);
        }
        public void ShouldRegisterCustomerWhenCommandIsValid()
        {
            var command = new RegisterCustomerCommand()
            {
                FirstName = "Alipio",
                LastName  = "Ferro",
                Document  = "53702077049",
                Email     = "*****@*****.**"
            };


            var handler = new CustomerCommandHandler(new FakeCustomerRepository());
            var result  = handler.Handle(command);

            Assert.AreNotEqual(null, result);
        }
Example #22
0
        public UnitTest2()
        {
            CommandResultReposiotry commandResultReposiotry = new CommandResultReposiotry();
            CustomerRepository customerRepository = new CustomerRepository();
            CustomerCommandHandler customerCommandHandler = new CustomerCommandHandler(customerRepository, commandResultReposiotry);
            CommandResultQueryaHandler commandResultQueryaHandler = new CommandResultQueryaHandler(commandResultReposiotry);

            CommandBus commandBus = new CommandBus();
            commandBus.Registerd<CustomerCreateCommand>(customerCommandHandler);

            QueryBus queryBus = new QueryBus();
            queryBus.Registerd<CommandResultQuery>(commandResultQueryaHandler);

            _commandBus = commandBus;
            _queryBus = queryBus;
        }
Example #23
0
        private CommandDispatcher CreateCommandDispatcher(IDomainRepository domainRepository, IEnumerable <Action <ICommand> > preExecutionPipe, IEnumerable <Action <object> > postExecutionPipe)
        {
            var commandDispatcher = new CommandDispatcher(domainRepository, preExecutionPipe, postExecutionPipe);

            var customerCommandHandler = new CustomerCommandHandler(domainRepository);

            commandDispatcher.RegisterHandler(customerCommandHandler);

            var productCommandHandler = new ProductCommandHandler(domainRepository);

            commandDispatcher.RegisterHandler(productCommandHandler);

            var orderCommandHandler = new OrderCommandHandler(domainRepository);

            commandDispatcher.RegisterHandler(orderCommandHandler);

            return(commandDispatcher);
        }
Example #24
0
 public EditCustomerViewModel()
 {
     this.context = new BankAppDataContext();
     this.customerCommandHandler = new CustomerCommandHandler(context);
     this.customerQueriesHandler = new CustomerQueriesHandler(context);
 }
 public CustumerController(CustomerCommandHandler handler, IUow uow) : base(uow)
 {
     _handler = handler;
 }
Example #26
0
 public CustomerController(IUow uow, CustomerCommandHandler handler)
     : base(uow)
 {
     _handler = handler;
 }
 public CustomerController(CustomerCommandHandler handler)
 {
     _handler = handler;
 }
Example #28
0
 public CustomerController(ICustomerRepository repository, CustomerCommandHandler handler)
 {
     _repository = repository;
     _handler    = handler;
 }
Example #29
0
 public CustomerController(IUow uow, CustomerCommandHandler commandHandler) :
     base(uow)
 {
     _uow            = uow;
     _commandHandler = commandHandler;
 }
 public CustomerController(CustomerCommandHandler customerCommandHandler,
                           CustomerQueryHandler customerQueryHandler)
 {
     _customerCommandHandler = customerCommandHandler;
     _customerQueryHandler   = customerQueryHandler;
 }
Example #31
0
 public CustomerController(CustomerCommandHandler handler, ICustomerRepository customerRepository)
 {
     _handler            = handler;
     _customerRepository = customerRepository;
 }