Customer MaterializeCustomerFromDto(CustomerDTO customerDTO)
        {
            //create the current instance with changes from customerDTO
            var address = new Address(customerDTO.AddressCity, customerDTO.AddressZipCode, customerDTO.AddressAddressLine1, customerDTO.AddressAddressLine2);

            var current = CustomerFactory.CreateCustomer(customerDTO.FirstName,
                                                         customerDTO.LastName,
                                                         customerDTO.Telephone,
                                                         customerDTO.Company,
                                                         customerDTO.CountryId,
                                                         address);

            //set credit
            current.ChangeTheCurrentCredit(customerDTO.CreditLimit);

            //set picture
            var picture = new Picture {
                RawPhoto = customerDTO.PictureRawPhoto
            };

            picture.ChangeCurrentIdentity(current.Id);

            current.ChangePicture(picture);

            //set identity
            current.ChangeCurrentIdentity(customerDTO.Id);


            return(current);
        }
예제 #2
0
        public void CreateCustomerTest()
        {
            ProcessThreadCollection currentThreads = Process.GetCurrentProcess().Threads;

            var beforeStartingThreads = currentThreads.Count;

            CustomerFactory customerFactory = new CustomerFactory();

            customerFactory.CreateCustomer("Fred");
            customerFactory.CreateCustomer("Greg");
            customerFactory.CreateCustomer("Ted");

            var afterStartingThreads = currentThreads.Count;

            Assert.AreEqual(beforeStartingThreads, afterStartingThreads);
        }
        /// <summary>
        /// <see cref="M:Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ICustomerManagement.AddNewCustomer"/>
        /// </summary>
        /// <param name="customerDTO"><see cref="M:Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ICustomerManagement.AddNewCustomer"/></param>
        /// <returns><see cref="M:Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ICustomerManagement.AddNewCustomer"/></returns>
        public CustomerDTO AddNewCustomer(CustomerDTO customerDTO)
        {
            //check preconditions
            if (customerDTO == null || customerDTO.CountryId == Guid.Empty)
            {
                throw new ArgumentException(Messages.warning_CannotAddCustomerWithEmptyInformation);
            }

            var country = _countryRepository.Get(customerDTO.CountryId);

            if (country != null)
            {
                //Create the entity and the required associated data
                var address = new Address(customerDTO.AddressCity, customerDTO.AddressZipCode, customerDTO.AddressAddressLine1, customerDTO.AddressAddressLine2);

                var customer = CustomerFactory.CreateCustomer(customerDTO.FirstName,
                                                              customerDTO.LastName,
                                                              customerDTO.Telephone,
                                                              customerDTO.Company,
                                                              country,
                                                              address);

                //save entity
                SaveCustomer(customer);

                //return the data with id and assigned default values
                return(customer.ProjectedAs <CustomerDTO>());
            }
            else
            {
                return(null);
            }
        }
예제 #4
0
        public void FindCustomerMaterializaResultIfExist()
        {
            //Arrange
            var countryRepository = new Mock<ICountryRepository>();
            var customerRepository = new Mock<ICustomerRepository>();
            var country = new Country("spain", "es-ES");
            country.GenerateNewIdentity();

            customerRepository
                .Setup(x => x.Get(It.IsAny<Guid>()))
                .Returns((Guid guid) => {
                    return CustomerFactory.CreateCustomer("Jhon",
                                                      "El rojo",
                                                      "+3434344",
                                                      "company",
                                                      country,
                                                      new Address("city", "zipCode", "address line1", "address line2"));
                });

            Mock<ILogger<CustomerAppService>> _mockLogger = new Mock<ILogger<CustomerAppService>>();

            var customerManagementService = new CustomerAppService(countryRepository.Object, customerRepository.Object, _mockLogger.Object);

            //Act
            var result = customerManagementService.FindCustomer(Guid.NewGuid());

            //Assert
            Assert.NotNull(result);
        }
        public void AddNewOrderWithTotalGreaterCustomerCreditReturnNull()
        {
            //Arrange
            var productRepository  = new StubIProductRepository();
            var orderRepository    = new StubIOrderRepository();
            var customerRepository = new StubICustomerRepository();
            var country            = new Country("spain", "es-ES");

            country.GenerateNewIdentity();

            customerRepository.GetGuid = (guid) =>
            {
                //default credit limit is 1000
                var customer = CustomerFactory.CreateCustomer(
                    "Jhon",
                    "El rojo",
                    "+34343",
                    "company",
                    country,
                    new Address("city", "zipCode", "addressline1", "addressline2"));

                return(customer);
            };

            orderRepository.UnitOfWorkGet = () =>
            {
                var uow = new StubIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };
            orderRepository.AddOrder = (order) => { };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new OrderDto()
            {
                CustomerId      = Guid.NewGuid(),
                ShippingAddress = "Address",
                ShippingCity    = "city",
                ShippingName    = "name",
                ShippingZipCode = "zipcode",
                OrderLines      = new List <OrderLineDto>()
                {
                    new OrderLineDto()
                    {
                        ProductId = Guid.NewGuid(),
                        Amount    = 1,
                        Discount  = 0,
                        UnitPrice = 2000
                    }
                }
            };

            //act
            var result = salesManagement.AddNewOrder(dto);

            //assert
            Assert.IsNull(result);
        }
예제 #6
0
        public void FindCustomersByFilterMaterializeResults()
        {
            //Arrange
            var countryRepository  = new Mock <ICountryRepository>();
            var customerRepository = new Mock <ICustomerRepository>();
            var country            = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            customerRepository
            .Setup(x => x.AllMatching(It.IsAny <ISpecification <Customer> >()))
            .Returns((ISpecification <Customer> spec) => {
                var customers = new List <Customer>();
                customers.Add(CustomerFactory.CreateCustomer("Jhon",
                                                             "El rojo",
                                                             "+34343",
                                                             "company",
                                                             country,
                                                             new Address("city", "zipCode", "address line", "address line2")));
                return(customers);
            });

            Mock <ILogger <CustomerAppService> > _mockLogger = new Mock <ILogger <CustomerAppService> >();

            var customerManagementService = new CustomerAppService(countryRepository.Object, customerRepository.Object, _mockLogger.Object);

            //Act
            var result = customerManagementService.FindCustomers("Jhon");

            //Assert
            Assert.NotNull(result);
            Assert.True(result.Count == 1);
        }
예제 #7
0
        public void BankAccountDepositAndWithdrawSetBalance()
        {
            //Arrange
            var country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");
            var activityReason    = "reason";

            var customer = CustomerFactory.CreateCustomer(
                "Unai",
                "Zorrilla Castro",
                "+3422",
                "company",
                country,
                new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            var bankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            Assert.AreEqual(bankAccount.Balance, 0);

            bankAccount.DepositMoney(1000, activityReason);
            Assert.AreEqual(bankAccount.Balance, 1000);

            bankAccount.WithdrawMoney(250, activityReason);
            Assert.AreEqual(bankAccount.Balance, 750);
        }
예제 #8
0
        public void AddNewValidOrderReturnAddedOrder()
        {
            //Arrange

            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();
            var customerRepository = new SICustomerRepository();
            var country            = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            customerRepository.GetGuid = (guid) =>
            {
                //default credit limit is 1000
                var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", "+34343", "company", country, new Address("city", "zipCode", "addressline1", "addressline2"));

                return(customer);
            };


            orderRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };
            orderRepository.AddOrder = (order) => { };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new OrderDTO()
            {
                CustomerId      = Guid.NewGuid(),
                ShippingAddress = "Address",
                ShippingCity    = "city",
                ShippingName    = "name",
                ShippingZipCode = "zipcode",
                OrderLines      = new List <OrderLineDTO>()
                {
                    new OrderLineDTO()
                    {
                        ProductId = Guid.NewGuid(), Amount = 1, Discount = 0, UnitPrice = 20
                    }
                }
            };

            //act
            var result = salesManagement.AddNewOrder(dto);

            //assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.ShippingAddress, dto.ShippingAddress);
            Assert.AreEqual(result.ShippingCity, dto.ShippingCity);
            Assert.AreEqual(result.ShippingName, dto.ShippingName);
            Assert.AreEqual(result.ShippingZipCode, dto.ShippingZipCode);
            Assert.IsTrue(result.OrderLines.Count == 1);
            Assert.IsTrue(result.OrderLines.All(ol => ol.Id != Guid.Empty));
        }
예제 #9
0
        public void BankAccountDepositMaxDecimalThrowOverflowBalance()
        {
            //Arrange
            var country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");
            var activityReason    = "reason";

            var customer = CustomerFactory.CreateCustomer(
                "Unai",
                "Zorrilla Castro",
                "+3422",
                "company",
                country,
                new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            customer.GenerateNewIdentity();

            var bankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            bankAccount.DepositMoney(1, activityReason);
            bankAccount.DepositMoney(Decimal.MaxValue, activityReason);
        }
예제 #10
0
        public void AdaptBankAccountToBankAccountDTO()
        {
            //Arrange
            var country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var customer = CustomerFactory.CreateCustomer("jhon", "el rojo", "+3441", "company", country, new Address("", "", "", ""));

            customer.GenerateNewIdentity();

            BankAccount account = new BankAccount();

            account.GenerateNewIdentity();
            account.BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02");
            account.SetCustomerOwnerOfThisBankAccount(customer);
            account.DepositMoney(1000, "reason");
            account.Lock();

            //Act
            ITypeAdapter adapter        = TypeAdapterFactory.CreateAdapter();
            var          bankAccountDTO = adapter.Adapt <BankAccount, BankAccountDTO>(account);


            //Assert
            Assert.Equal(account.Id, bankAccountDTO.Id);
            Assert.Equal(account.Iban, bankAccountDTO.BankAccountNumber);
            Assert.Equal(account.Balance, bankAccountDTO.Balance);
            Assert.Equal(account.Customer.FirstName, bankAccountDTO.CustomerFirstName);
            Assert.Equal(account.Customer.LastName, bankAccountDTO.CustomerLastName);
            Assert.Equal(account.Locked, bankAccountDTO.Locked);
        }
예제 #11
0
        private int ProcessTextInput(string inputText)
        {
            if (string.IsNullOrWhiteSpace(inputText))
            {
                return(0);
            }

            int numCashier;
            var customers = new List <Customer>();

            using (var s = new StringReader(inputText))
            {
                numCashier = int.Parse(s.ReadLine());
                string custLine;
                while ((custLine = s.ReadLine()) != null)
                {
                    var cust = CustomerFactory.CreateCustomer(custLine);
                    if (cust != null)
                    {
                        customers.Add(cust);
                    }
                }
            }

            var store = new Store(numCashier);

            return(store.EnqueueCustomers(customers));
        }
예제 #12
0
        public void BankAccountFactoryCreateValidBankAccount()
        {
            //Arrange
            var country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var customer = CustomerFactory.CreateCustomer("Unai", "Zorrilla Castro", "+3422", "company", country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));


            var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");

            BankAccount bankAccount = null;

            //Act
            bankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            var validationContext = new ValidationContext(bankAccount, null, null);
            var validationResults = customer.Validate(validationContext);

            //Assert
            Assert.NotNull(bankAccount);
            Assert.True(bankAccount.BankAccountNumber == bankAccountNumber);
            Assert.False(bankAccount.Locked);
            Assert.True(bankAccount.CustomerId == customer.Id);

            Assert.False(validationResults.Any());
        }
예제 #13
0
        public void CustomerFactoryWithCountryEntityCreateValidCustomer()
        {
            //Arrange
            var lastName  = "El rojo";
            var firstName = "Jhon";
            var telephone = "+34111111";
            var company   = "company name";

            var country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            //Act
            var customer = CustomerFactory.CreateCustomer(
                firstName,
                lastName,
                telephone,
                company,
                country,
                new Address("city", "zipcode", "AddressLine1", "AddressLine2"));
            var validationContext = new ValidationContext(customer, null, null);
            var validationResults = customer.Validate(validationContext);

            //Assert
            Assert.AreEqual(customer.LastName, lastName);
            Assert.AreEqual(customer.FirstName, firstName);
            Assert.AreEqual(customer.Country, country);
            Assert.AreEqual(customer.CountryId, country.Id);
            Assert.AreEqual(customer.IsEnabled, true);
            Assert.AreEqual(customer.Company, company);
            Assert.AreEqual(customer.Telephone, telephone);
            Assert.AreEqual(customer.CreditLimit, 1000M);

            Assert.IsFalse(validationResults.Any());
        }
예제 #14
0
        public void CustomerFactoryWithCountryEntityCreateValidCustomer()
        {
            //Arrange
            var lastName  = "El rojo";
            var firstName = "Jhon";
            var telephone = "+34111111";
            var company   = "company name";

            var country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            //Act
            var customer = CustomerFactory.CreateCustomer(firstName, lastName, telephone, company, "*****@*****.**", country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));


            //Assert
            Assert.Equal(customer.LastName, lastName);
            Assert.Equal(customer.FirstName, firstName);
            Assert.Equal(customer.Country, country);
            Assert.Equal(customer.CountryId, country.Id);
            Assert.True(customer.IsEnabled);
            Assert.Equal(customer.Company, company);
            Assert.Equal(customer.Telephone, telephone);
        }
        protected override IEnumerable <CustomerDbObject> ExecuteSearchCommand()
        {
            command.CommandText = $"SELECT * FROM {tableName}";
            DbDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                CustomerDbObject cust       = null;
                string           typeString = reader[columnNames[5]].ToString();
                // Method 1: From value
                CustomerType cType;
                if (Enum.TryParse(typeString, out cType))
                {
                    cust = CustomerFactory.CreateCustomer(cType);
                }
                else
                {
                    throw new ArgumentNullException("Error at loading Customer table: don't know what type");
                }
                //// Method 2: From description
                //CustomerType type = EnumExtension.FromDescription<CustomerType>(typeString);
                //cust = CustomerFactory.CreateCustomer(type);

                cust.CustomerAddress = reader[columnNames[0]].ToString();
                cust.BillAmount      = Convert.ToDecimal(reader[columnNames[1]]);
                cust.BillDate        = Convert.ToDateTime(reader[columnNames[2]]);
                cust.PhoneNumber     = reader[columnNames[3]].ToString();
                cust.CustomerAddress = reader[columnNames[4]].ToString();
                yield return(cust);
            }
        }
        public void FindCustomersByFilterMaterializeResults()
        {
            //Arrange
            var countryRepository  = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            var country            = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            customerRepository.AllMatchingISpecificationOfCustomer = (spec) =>
            {
                var customers = new List <Customer>();
                customers.Add(CustomerFactory.CreateCustomer("Jhon",
                                                             "El rojo",
                                                             "+34343",
                                                             "company",
                                                             country,
                                                             new Address("city", "zipCode", "address line", "address line2")));
                return(customers);
            };


            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCustomers("Jhon");

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }
        public void FindCustomerMaterializaResultIfExist()
        {
            //Arrange
            var countryRepository  = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            var country            = new Country("spain", "es-ES");

            country.GenerateNewIdentity();

            customerRepository.GetGuid = (guid) =>
            {
                return(CustomerFactory.CreateCustomer("Jhon",
                                                      "El rojo",
                                                      "+3434344",
                                                      "company",
                                                      country,
                                                      new Address("city", "zipCode", "address line1", "address line2")));
            };

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCustomer(Guid.NewGuid());

            //Assert
            Assert.IsNotNull(result);
        }
        public void FindCustomersInPageMaterializeResults()
        {
            //Arrange
            var countryRepository  = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            var country            = new Country("spain", "es-ES");

            country.GenerateNewIdentity();

            customerRepository.GetEnabledInt32Int32 = (index, count) =>
            {
                var customers = new List <Customer>();
                customers.Add(CustomerFactory.CreateCustomer("Jhon",
                                                             "El rojo",
                                                             "+343",
                                                             "company",
                                                             country,
                                                             new Address("city", "zipCode", "address line", "address line2")));
                return(customers);
            };


            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCustomers(0, 1);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }
예제 #19
0
        public async Task <Guid> Handle(CreateCustomerCommand message, CancellationToken cancellationToken)
        {
            var country = await Uow.Repository.CountryRepository
                          .SingleOrDefaultAsync(c => c.Id == message.CountryId);

            if (country == null)
            {
                throw new NotFoundException(nameof(Country), message.CountryId);
            }

            var address = new  Address(message.AddressCity, message.AddressZipCode, message.AddressLine1, message.AddressLine2);

            var customer = CustomerFactory.CreateCustomer(message.FirstName, message.LastName, message.Telephone, message.Company, message.Email, country, address);

            await Uow.Repository.CustomerRepository.AddAsync(customer);


            if (await Uow.SaveChangesAsync())
            {
                await Bus.Publish(new CustomerCreatedEvent(customer.Id), cancellationToken);

                return(customer.Id);
            }

            return(Guid.Empty);
        }
예제 #20
0
        static void Main(string[] args)
        {
            ICustomerFactory factory  = new CustomerFactory();
            Customer         customer = factory.CreateCustomer(TypeCustomer.LoyalCustomer);

            customer.Description();
        }
예제 #21
0
        public void BankAccountLockSetLocked()
        {
            //Arrange
            var country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var customer = CustomerFactory.CreateCustomer(
                "Unai",
                "Zorrilla Castro",
                "+3422",
                "company",
                country,
                new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");

            var bankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            //Act
            bankAccount.Lock();

            //Assert
            Assert.IsTrue(bankAccount.Locked);
        }
예제 #22
0
        public void FindCustomersInPageMaterializeResults()
        {
            //Arrange
            var countryRepository = new Mock<ICountryRepository>();
            var customerRepository = new Mock<ICustomerRepository>();
            var country = new Country("spain", "es-ES");
            country.GenerateNewIdentity();

            customerRepository
                .Setup(x => x.GetEnabled(It.IsAny<Int32>(), It.IsAny<Int32>()))
                .Returns((Int32 index, Int32 count) => {
                    var customers = new List<Customer>();
                    customers.Add(CustomerFactory.CreateCustomer("Jhon",
                                                                "El rojo",
                                                                "+343",
                                                                "company",
                                                                 country,
                                                                 new Address("city", "zipCode", "address line", "address line2")));
                    return customers;
                });

            Mock<ILogger<CustomerAppService>> _mockLogger = new Mock<ILogger<CustomerAppService>>();

            var customerManagementService = new CustomerAppService(countryRepository.Object, customerRepository.Object, _mockLogger.Object);

            //Act
            var result = customerManagementService.FindCustomers(0, 1);

            //Assert
            Assert.NotNull(result);
            Assert.True(result.Count == 1);
        }
예제 #23
0
        public void BankAccountWithdrawMoneyAnotateActivity()
        {
            //Arrange
            Country country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var    bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");
            string activityReason    = "reason";

            var customer = CustomerFactory.CreateCustomer("Unai", "Zorrilla Castro", "+3422", "company", country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            var bankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            //Act
            bankAccount.DepositMoney(1000, activityReason);
            bankAccount.WithdrawMoney(1000, activityReason);

            //Assert
            Assert.True(bankAccount.Balance == 0);
            Assert.NotNull(bankAccount.BankAccountActivity);
            Assert.True(bankAccount.BankAccountActivity.Any());
            Assert.True(bankAccount.BankAccountActivity.Last().Amount == -1000);
            Assert.True(bankAccount.BankAccountActivity.Last().ActivityDescription == activityReason);
        }
예제 #24
0
        public void CustomerRepositoryRemoveItemDeleteIt()
        {
            //Arrange
            var unitOfWork         = new MainBcUnitOfWork();
            var customerRepository = new CustomerRepository(unitOfWork);

            var country = new Country("Spain", "es-ES");

            country.ChangeCurrentIdentity(new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"));

            var address = new Address("city", "zipCode", "addressline1", "addressline2");

            var customer = CustomerFactory.CreateCustomer("Frank", "Frank", "+3444", "company", country, address);

            customer.SetTheCountryReference(country.Id);

            customerRepository.Add(customer);
            unitOfWork.Commit();

            //Act
            customerRepository.Remove(customer);
            unitOfWork.Commit();

            var result = customerRepository.Get(customer.Id);

            //Assert
            Assert.IsNull(result);
        }
예제 #25
0
        public void IsCreditValidForOrderReturnFalseIfTotalOrderIsGreaterThanCustomerCredit()
        {
            //Arrange
            string shippingName    = "shippingName";
            string shippingCity    = "shippingCity";
            string shippingZipCode = "shippingZipCode";
            string shippingAddress = "shippingAddress";

            var country = new Country("spain", "es-ES");

            country.GenerateNewIdentity();

            var customer = CustomerFactory.CreateCustomer("jhon", "el rojo", "+3422", "company", country, new Address("city", "zipCode", "address line1", "addres line2"));

            //Act
            Order order = OrderFactory.CreateOrder(customer, shippingName, shippingCity, shippingAddress, shippingZipCode);

            order.AddNewOrderLine(Guid.NewGuid(), 100, 240, 0); // this is greater that 1000 ( default customer credit )

            //assert
            var result = order.IsCreditValidForOrder();

            //Assert
            Assert.IsFalse(result);
        }
        public ITransactionContext CreateTransactionContext(IProcessExecutionContext executionContext, IRecordPointer <Guid> transactionContextId, bool useCache = true)
        {
            useCache = useCache && executionContext.Cache != null;

            string cacheKey = null;

            if (useCache)
            {
                cacheKey = CACHE_KEY + transactionContextId.Id.ToString();

                if (executionContext.Cache.Exists(cacheKey))
                {
                    return(executionContext.Cache.Get <ITransactionContext>(cacheKey));
                }
            }


            var record = DataConnector.GetTransactionContextRecord(executionContext.DataService, transactionContextId);

            var customer = CustomerFactory.CreateCustomer(executionContext, record.CustomerId, useCache);

            var transactionContext = new TransactionContext(record, customer);

            if (useCache)
            {
                var settings     = SettingsFactory.CreateSettings(executionContext.Settings);
                var cacheTimeout = settings.TransactionContextCacheTimeout;

                executionContext.Cache.Add <ITransactionContext>(cacheKey, transactionContext, cacheTimeout.Value);
            }

            return(transactionContext);
        }
예제 #27
0
        public void RemoveCustomerSetCustomerAsDisabled()
        {
            //Arrange
            var country = new Country("spain", "es-ES");
            country.GenerateNewIdentity();

            Guid customerId = Guid.NewGuid();
            
            var countryRepository = new Mock<ICountryRepository>();
            var customerRepository = new Mock<ICustomerRepository>();
            Mock<MainBCUnitOfWork> _mockContext = new Mock<MainBCUnitOfWork>();
            _mockContext.Setup(c => c.Commit());
            customerRepository
                .Setup(x => x.UnitOfWork).Returns(_mockContext.Object);

            var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo","+3434","company",country, new Address("city", "zipCode", "address line", "address line"));
            customer.ChangeCurrentIdentity(customerId);

            customerRepository
            .Setup(x => x.Get(It.IsAny<Guid>()))
            .Returns((Guid guid) => {
                return customer;
            });

            Mock<ILogger<CustomerAppService>> _mockLogger = new Mock<ILogger<CustomerAppService>>();

            //Act
            var customerManagementService = new CustomerAppService(countryRepository.Object, customerRepository.Object, _mockLogger.Object);
            customerManagementService.RemoveCustomer(customerId);

            //Assert
            Assert.False(customer.IsEnabled);
        }
예제 #28
0
        public void LocalCustomerForOrdersGreatherThan100()
        {
            var customer = CustomerFactory.CreateCustomer(102);

            var loyalCustomer = Assert.IsType <LoyalCustomer>(customer);

            Assert.Equal(10, loyalCustomer.Discount);
        }
예제 #29
0
파일: Program.cs 프로젝트: Korfu/VetClinic
      public static void CreateAppointment()
      {
          var customer    = _customerFactory.CreateCustomer();
          var animal      = _animalFactory.CreateAnimal();
          var appointment = _appointmentFactory.CreateAppointment(animal, customer);

          Console.WriteLine(" ");
          //appointment.Display();
      }
예제 #30
0
        public void UpdateCustomerMergePersistentAndCurrent()
        {
            //Arrange
            var country = new Country("spain", "es-ES");

            country.GenerateNewIdentity();

            Guid customerId = Guid.NewGuid();

            var countryRepository  = new Mock <ICountryRepository>();
            var customerRepository = new Mock <ICustomerRepository>();
            Mock <MainBCUnitOfWork> _mockContext = new Mock <MainBCUnitOfWork>();

            _mockContext.Setup(c => c.Commit());
            customerRepository
            .Setup(x => x.UnitOfWork).Returns(_mockContext.Object);

            customerRepository
            .Setup(x => x.Get(It.IsAny <Guid>()))
            .Returns((Guid guid) => {
                var customer = CustomerFactory.CreateCustomer("Jhon",
                                                              "El rojo",
                                                              "+3434",
                                                              "company",
                                                              country,
                                                              new Address("city", "zipCode", "address line", "address line"));
                customer.ChangeCurrentIdentity(customerId);

                return(customer);
            });

            customerRepository
            .Setup(x => x.Merge(It.IsAny <Customer>(), It.IsAny <Customer>()))
            .Callback <Customer, Customer>((persistent, current) =>
            {
                Assert.Equal(persistent, current);
                Assert.True(persistent != null);
                Assert.True(current != null);
            }
                                           );

            Mock <ILogger <CustomerAppService> > _mockLogger = new Mock <ILogger <CustomerAppService> >();

            var customerManagementService = new CustomerAppService(countryRepository.Object, customerRepository.Object, _mockLogger.Object);

            var customerDTO = new CustomerDTO() //missing lastname
            {
                Id        = customerId,
                CountryId = country.Id,
                FirstName = "Jhon",
                LastName  = "El rojo",
            };

            //act
            customerManagementService.UpdateCustomer(customerDTO);
        }