コード例 #1
0
        public void Deve_Criar_Um_Novo_Cliente()
        {
            var code         = 1;
            var firstName    = "Victor";
            var lastName     = "Domingues";
            var name         = new NameVo(firstName, lastName);
            var number       = "11992535010";
            var phone        = new PhoneVo(number);
            var phone2       = new PhoneVo(number);
            var cpf          = "3333333333";
            var document     = new DocumentVo(cpf, EDocumentType.Cpf);
            var emailAddress = "*****@*****.**";
            var email        = new EmailVo(emailAddress);

            var address = new Address(Tenant.Id, "", "", "", "", "", "", "", "");

            var customer = new Customer(Tenant.Id, code, name, phone, phone2, email, document, address.Id, null);

            Assert.IsTrue(customer.Valid);
            Assert.AreEqual(customer.TenantId, Tenant.Id);
            Assert.AreEqual(customer.Name, name);
            Assert.AreEqual(customer.Phone, phone);
            Assert.AreEqual(customer.Phone2, phone2);
            Assert.AreEqual(customer.Email, email);
            Assert.AreEqual(customer.Document, document);
            Assert.AreEqual(customer.Code, code);
        }
コード例 #2
0
        public IResult Handle(ChangeCustomerCommand command)
        {
            //Criar ValueObjects
            var name  = new NameVo(command.Nome, command.Sobrenome);
            var cpf   = new CpfVo(command.Documento);
            var email = new Email(command.Email);
            //Criar
            var customer = new Customer(name, cpf, email, command.Telefone);

            //Validar
            AddNotifications(name.Notifications);
            AddNotifications(cpf.Notifications);
            AddNotifications(email.Notifications);

            if (Invalid)
            {
                return(new ApiContract(false,
                                       "Erro, corrija os seguintes problemas:",
                                       Notifications));
            }

            try
            {
                _repository.Save(customer, command.Id);
            }
            catch (Exception ex)
            {
                //TO-DO: implementar log real
                throw new Exception("Erro - Handler CustomerHandler" + ex.Message);
            }

            return(new ApiContract(true, "Customer criado com sucesso", null));
        }
コード例 #3
0
 public void Update(NameVo name, EmailVo email, PhoneVo phone)
 {
     Name  = name;
     Email = email;
     Phone = phone;
     SetUpdatedAt();
 }
コード例 #4
0
        public IResult Handle(CreateCustomerCommand command)
        {
            //transações de negócios, regras de negócio, comunicação com outros handlers
            //Criacao dos objetos
            var name     = new NameVo(command.Nome, command.Sobrenome);
            var cpf      = new CpfVo(command.Documento);
            var email    = new EmailVo(command.Email);
            var customer = new Customer(name, cpf, email, command.Telefone);

            //Validar
            AddNotifications(name.Notifications);
            AddNotifications(cpf.Notifications);
            AddNotifications(email.Notifications);

            if (Invalid)
            {
                return(new ApiContract(false,
                                       "Erro. Corrija os campos abaixo:",
                                       Notifications));
            }

            try
            {
                _repository.Save(customer, null);
            }
            catch (Exception ex)
            {
                //TO-DO: implementa log depois
                throw new Exception("Erro - Handler CustomerCommandHandler" + ex.Message);
            }

            return(new ApiContract(true, "Customer criado com sucesso!", null));
        }
コード例 #5
0
        public void NameVoTests_IsValid_ReturnTrue()
        {
            //ARRANGE
            var name = new NameVo("Ray", "Carneiro");

            //ASSERT
            Assert.AreEqual(true, name.IsValid);
        }
コード例 #6
0
        public void Deve_Criar_Um_Valor_De_Objeto_Nome()
        {
            var nome = new NameVo("Victor", "Domingues");

            Assert.AreEqual(nome.FirstName, "Victor");
            Assert.AreEqual(nome.LastName, "Domingues");
            Assert.IsTrue(nome.Valid);
        }
コード例 #7
0
        public void NameVoTests_State_IsInvalid()
        {
            var name = new NameVo("R", "CARNEIRO");

            name.Validate();

            Assert.AreEqual(true, name.Invalid);
        }
コード例 #8
0
 public Customer(NameVo name, CpfVo cpf, EmailVo email, string phone)
 {
     Name       = name;
     Cpf        = cpf;
     Email      = email;
     Phone      = phone;
     _addresses = new List <Address>();
 }
コード例 #9
0
        public void NameVoTests_IsInvalid_ReturnFalse()
        {
            //ARRANGE
            var name = new NameVo("R", "Carneiro");

            //ASSERT
            Assert.AreEqual(true, name.Invalid);
        }
コード例 #10
0
        public Customer Get(Guid id)
        {
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("88041300081");
            var email = new EmailVo("*****@*****.**");

            return(new Customer(name, cpf, email, "(11) 99999-9999"));
        }
コード例 #11
0
 public User(NameVo name, EmailVo email, UserRole role, PasswordVo password, PhoneVo phone, Guid tenantId)
 {
     Name     = name;
     Email    = email;
     Role     = role;
     Phone    = phone;
     Password = password;
     SetTenantId(tenantId);
     Validate();
 }
コード例 #12
0
        public Customer(NameVo name, CpfVo cpf, EmailVo email, string phone)
        {
            Id         = Guid.NewGuid();
            Name       = name;
            Cpf        = cpf;
            Email      = email;
            Phone      = phone;
            _addresses = new List <Address>();

            Validate();
        }
コード例 #13
0
 public Customer(Guid tenantId, int code, NameVo name, PhoneVo phone, PhoneVo phone2, EmailVo email, DocumentVo document, Guid addressId, string ie)
 {
     SetTenantId(tenantId);
     Code      = code;
     Name      = name;
     Phone     = phone;
     Phone2    = phone2;
     Email     = email;
     Document  = document;
     AddressId = addressId;
     Ie        = ie;
 }
コード例 #14
0
ファイル: Customer.cs プロジェクト: rcarneironet/workshop
 public Customer(
     NameVo name,
     CpfVo cpf,
     Email email,
     string telefone)
 {
     Name       = name;
     Cpf        = cpf;
     Email      = email;
     Telefone   = telefone;
     _addresses = new List <Address>();
 }
コード例 #15
0
ファイル: OrderTests.cs プロジェクト: rcarneironet/workshop
        public void Setup()
        {
            //simulando dados reais
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("88041300081");
            var email = new Email("*****@*****.**");

            _teclado = new Product("Teclado Microsoft", "Melhor teclado", "teclado.jpg", 10M, 10);
            _mouse   = new Product("Mouse Microsoft", "Melhor mouse", "mouse.jpg", 5M, 10);
            _monitor = new Product("Monitor Dell", "Melhor monitor", "dell.jpg", 50M, 10);

            _customer = new Customer(name, cpf, email, "(11) 95555-5555");
            _order    = new Order(_customer);
        }
コード例 #16
0
        public void Setup()
        {
            //Simular dados
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("15366015006");
            var email = new EmailVo("*****@*****.**");

            _teclado = new Product("Teclado Microsoft", "Melhor teclado", "teclado.jpg", 10M, 10);
            _mouse   = new Product("Mouse Microsoft", "Melhor mouse", "mouse.jpg", 5M, 10);
            _monitor = new Product("Dell", "Melhor monitor", "dell.jpg", 50M, 10);

            _customer = new Customer(name, cpf, email, "11-5555-5555");
            _order    = new Order(_customer);
        }
コード例 #17
0
        public void CreateCustomerCommandTests_CreateOrder_ShouldBeValid()
        {
            var command  = new CreateCustomerCommand();
            var name     = new NameVo("Ray", "Carneiro");
            var cpf      = new CpfVo("15366015006");
            var email    = new EmailVo("*****@*****.**");
            var customer = new Customer(name, cpf, email, command.Telefone);

            //Validar
            AddNotifications(name.Notifications);
            AddNotifications(cpf.Notifications);
            AddNotifications(email.Notifications);

            Assert.AreEqual(true, !Invalid);
        }
コード例 #18
0
        //To-DO: criar uma padrão para retorno com smart notification
        public string Execute(PlaceOrderInput order)
        {
            #region Obter dados do banco
            //Customer customer = _customerReadOnlyRepository.Get(customerId);
            //if (customer == null)
            //{
            //    AddNotification("Customer", "Customer does not exist.");
            //}
            #endregion

            //Simulando dados, não implementei acesso a dados
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("15366015006");
            var email = new EmailVo("*****@*****.**");
            _customer = new Customer(name, cpf, email, "11-5555-5555");

            if (_customer.Invalid)
            {
                AddNotification("Cliente", "Erros identificados nos dados de cliente: ");
                return(_customer.Notifications.FirstOrDefault().Message);
            }

            _order = new Order(_customer);
            var product = new Product(order.ProductItem.Title, order.ProductItem.Description, order.ProductItem.Image, order.ProductItem.Price, 10);
            _order.AddItem(product, order.ProductItem.Quantity);

            if (_order.Invalid)
            {
                AddNotification("Pedido", "Erros identificados nos dados do seu pedido: ");
                return(_order.Notifications.FirstOrDefault().Message);
            }

            string orderId;

            try
            {
                orderId = _orderWriteOnlyRepository.PlaceOrder(_customer, _order);

                _kafkaProducer.Produce(orderId);
            }
            catch (Exception ex)
            {
                //TO-DO: Implement log
                throw;
            }

            return("Número do pedido: " + orderId);
        }
コード例 #19
0
        public string Execute(PlaceOrderInput order)
        {
            //Simulação de dados e regras de negócios
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("15366015006");
            var email = new EmailVo("*****@*****.**");

            _customer = new Customer(name, cpf, email, "11-5555-5555");

            if (_customer.Invalid)
            {
                AddNotification("Cliente", "Erros identificados nos dados de cliente: ");
                return(_customer.Notifications.FirstOrDefault().Message);
            }

            _order = new Order(_customer);
            var product = new Product(order.ProductItem.Title, order.ProductItem.Description, order.ProductItem.Image, order.ProductItem.Price, 10);

            _order.AddItem(product, order.ProductItem.Quantity);

            if (_order.Invalid)
            {
                AddNotification("Pedido", "Erros identificados nos dados do seu pedido: ");
                return(_order.Notifications.FirstOrDefault().Message);
            }

            string orderId;

            try
            {
                //Salva ordem no banco de dados
                orderId = _orderWriteOnlyRepository.PlaceOrder(_customer, _order);

                //Envia mensagem para Kafka
                _kafkaAdapter.Produce(orderId);
            }
            catch
            {
                throw;
            }

            return("Número do pedido: " + orderId);
        }
コード例 #20
0
        protected DomainBaseUnitTest()
        {
            Settings.SecurityKey = "cbffeba849124af8b7b89675c223fd3d";
            Tenant = new AppTenant("Treeze", "localhost:43500", null, null);
            User   = new User(new NameVo("Victor", "Luiz"), new EmailVo("*****@*****.**"), UserRole.User, new PasswordVo("12345678", "12345678"), null, Tenant.Id);

            var code         = 1;
            var firstName    = "Victor";
            var lastName     = "Domingues";
            var name         = new NameVo(firstName, lastName);
            var number       = "11992535010";
            var phone        = new PhoneVo(number);
            var phone2       = new PhoneVo(number);
            var cpf          = "3333333333";
            var document     = new DocumentVo(cpf, EDocumentType.Cpf);
            var emailAddress = "*****@*****.**";
            var email        = new EmailVo(emailAddress);

            var address = new Address(Tenant.Id, "", "", "", "", "", "", "", "");

            Customer = new Customer(Tenant.Id, code, name, phone, phone2, email, document, address.Id, null);
        }