/// <summary> /// Create a new transient customer /// </summary> /// <param name="firstName">The customer firstName</param> /// <param name="lastName">The customer lastName</param> /// <param name="country">The associated country to this customer</param> /// <returns>A valid customer</returns> public static Customer CreateCustomer(string firstName, string lastName,Country country,Address address) { //create the customer instance var customer = new Customer() { FirstName = firstName, LastName = lastName }; //set customer address customer.Address = address; //set default picture relation with no data customer.Picture = new Picture(); //TODO: By default this is the limit for customer credit, you can set this //parameter customizable via configuration or other system customer.CreditLimit = 1000M; //Associate country customer.SetCountry(country); //by default this customer is enabled customer.Enable(); return customer; }
/// <summary> /// Create a new order /// </summary> /// <param name="customer">Associated customer</param> /// <param name="shippingName">The order shipping name</param> /// <param name="shippingCity">The order shipping city</param> /// <param name="shippingAddress">The order shipping address</param> /// <param name="shippingZipCode">The order shipping zip cocde</param> /// <returns>Associated order</returns> public static Order CreateOrder( Customer customer, string shippingName, string shippingCity, string shippingAddress, string shippingZipCode) { //create the order var order = new Order(); //create shipping var shipping = new ShippingInfo(shippingName, shippingAddress, shippingCity, shippingZipCode); //set default values order.OrderDate = DateTime.UtcNow; order.DeliveryDate = null; order.ShippingInformation = shipping; //set customer information order.SetTheCustomerForThisOrder(customer); //set identity order.GenerateNewIdentity(); return order; }
public void OrderToOrderDtoAdapter() { //Arrange var customer = new Customer(); customer.GenerateNewIdentity(); customer.FirstName = "Unai"; customer.LastName = "Zorrilla"; Product product = new Software("the product title", "the product description", "license code"); product.GenerateNewIdentity(); var order = new Order(); order.GenerateNewIdentity(); order.OrderDate = DateTime.Now; order.ShippingInformation = new ShippingInfo( "shippingName", "shippingAddress", "shippingCity", "shippingZipCode"); order.SetTheCustomerForThisOrder(customer); var orderLine = order.AddNewOrderLine(product.Id, 10, 10, 0.5M); orderLine.SetProduct(product); //Act var adapter = TypeAdapterFactory.CreateAdapter(); var orderDto = adapter.Adapt<Order, OrderDto>(order); //Assert Assert.AreEqual(orderDto.Id, order.Id); Assert.AreEqual(orderDto.OrderDate, order.OrderDate); Assert.AreEqual(orderDto.DeliveryDate, order.DeliveryDate); Assert.AreEqual(orderDto.ShippingAddress, order.ShippingInformation.ShippingAddress); Assert.AreEqual(orderDto.ShippingCity, order.ShippingInformation.ShippingCity); Assert.AreEqual(orderDto.ShippingName, order.ShippingInformation.ShippingName); Assert.AreEqual(orderDto.ShippingZipCode, order.ShippingInformation.ShippingZipCode); Assert.AreEqual(orderDto.CustomerFullName, order.Customer.FullName); Assert.AreEqual(orderDto.CustomerId, order.Customer.Id); Assert.AreEqual( orderDto.OrderNumber, string.Format("{0}/{1}-{2}", order.OrderDate.Year, order.OrderDate.Month, order.SequenceNumberOrder)); Assert.IsNotNull(orderDto.OrderLines); Assert.IsTrue(orderDto.OrderLines.Any()); Assert.AreEqual(orderDto.OrderLines[0].Id, orderLine.Id); Assert.AreEqual(orderDto.OrderLines[0].Amount, orderLine.Amount); Assert.AreEqual(orderDto.OrderLines[0].Discount, orderLine.Discount * 100); Assert.AreEqual(orderDto.OrderLines[0].UnitPrice, orderLine.UnitPrice); Assert.AreEqual(orderDto.OrderLines[0].TotalLine, orderLine.TotalLine); Assert.AreEqual(orderDto.OrderLines[0].ProductId, product.Id); Assert.AreEqual(orderDto.OrderLines[0].ProductTitle, product.Title); }
public void CustomerCannotAssociateNullCountry() { //Arrange var country = new Country("Spain", "es-ES"); //Act var customer = new Customer(); customer.SetTheCountryForThisCustomer(null); }
public void CustomerCannotAssociateTransientCountry() { //Arrange Country country = new Country("Spain", "es-ES"); //Act Customer customer = new Customer(); customer.SetTheCountryForThisCustomer(country); }
public void OrderCannotSetNullCustomer() { //Arrange var customer = new Customer(); var order = new Order(); //Act order.SetTheCustomerForThisOrder(customer); }
public void OrderCannotSetTransientCustomer() { //Arrange Customer customer = new Customer(); Order order = new Order(); //Act order.SetTheCustomerForThisOrder(customer); }
public void CustomerDisableSetIsEnabledToFalse() { //Arrange var customer = new Customer(); //Act customer.Disable(); //assert Assert.IsFalse(customer.IsEnabled); }
public void CustomerEnableSetIsEnabledToTrue() { //Arrange var customer = new Customer(); //Act customer.Enable(); //assert Assert.IsTrue(customer.IsEnabled); }
/// <summary> /// Orders by Customer specification /// </summary> /// <param name="customer">The customer</param> /// <returns>Related specification for this criterion</returns> public static ISpecification<Order> OrdersByCustomer(Customer customer) { if (customer == null || customer.IsTransient()) { throw new ArgumentNullException("customer"); } return new DirectSpecification<Order>(o => o.CustomerId == customer.Id); }
public void CustomerCannotAssociateTransientCountry() { //Arrange Country country = new Country() { CountryName ="Spain" }; //Act Customer customer = new Customer(); customer.SetCountry(country); }
public void CustomerSetCountryFixCountryId() { //Arrange var country = new Country("Spain", "es-ES"); country.GenerateNewIdentity(); //Act var customer = new Customer(); customer.SetTheCountryForThisCustomer(country); //Assert Assert.AreEqual(country.Id, customer.CountryId); }
public void BankAccountCannotSetATransientCustomer() { //Arrange var customer = new Customer() { FirstName = "Unai", LastName = "Zorrilla", }; var bankAccount = new BankAccount(); //Act bankAccount.SetCustomerOwnerOfThisBankAccount(customer); }
/// <summary> /// Create a new instance of bankaccount /// </summary> /// <param name="customer">The customer associated with this bank account</param> /// <param name="bankAccountNumber">The bank account number</param> /// <returns>A valid bank account</returns> public static BankAccount CreateBankAccount(Customer customer, BankAccountNumber bankAccountNumber) { var bankAccount = new BankAccount(); //set the bank account number bankAccount.BankAccountNumber = bankAccountNumber; //set default bank account as unlocked bankAccount.UnLock(); //set the customer for this bank account bankAccount.SetCustomer(customer); return bankAccount; }
public void CustomerEnumerableToCustomerListDTOListAdapt() { //Arrange Guid idCustomer = IdentityGenerator.NewSequentialGuid(); Guid idCountry = IdentityGenerator.NewSequentialGuid(); Customer customer = new Customer() { Id = idCustomer, FirstName = "Unai", LastName = "Zorrilla", CreditLimit = 1000M, Telephone = "617404929", Company = "Spirtis", Address = new Address("Monforte", "27400", "AddressLine1", "AddressLine2"), Picture = new Picture() { Id = idCustomer, RawPhoto = new byte[0] { } } }; customer.SetCountry(new Country() { Id = idCountry, CountryName = "Spain", CountryISOCode = "es-ES" }); IEnumerable<Customer> customers = new List<Customer>() { customer }; //Act ITypeAdapter adapter = PrepareTypeAdapter(); var dtos = adapter.Adapt<IEnumerable<Customer>, List<CustomerListDTO>>(customers); //Assert Assert.IsNotNull(dtos); Assert.IsTrue(dtos.Any()); Assert.IsTrue(dtos.Count == 1); CustomerListDTO dto = dtos[0]; Assert.AreEqual(idCustomer, dto.Id); Assert.AreEqual(customer.FirstName, dto.FirstName); Assert.AreEqual(customer.LastName, dto.LastName); Assert.AreEqual(customer.Company, dto.Company); Assert.AreEqual(customer.Telephone, dto.Telephone); Assert.AreEqual(customer.CreditLimit, dto.CreditLimit); Assert.AreEqual(customer.Address.City, dto.AddressCity); Assert.AreEqual(customer.Address.ZipCode, dto.AddressZipCode); Assert.AreEqual(customer.Address.AddressLine1, dto.AddressAddressLine1); Assert.AreEqual(customer.Address.AddressLine2, dto.AddressAddressLine2); }
/// <summary> /// Create a new instance of bankaccount /// </summary> /// <param name="customer">The customer associated with this bank account</param> /// <param name="bankAccountNumber">The bank account number</param> /// <returns>A valid bank account</returns> public static BankAccount CreateBankAccount(Customer customer, BankAccountNumber bankAccountNumber) { var bankAccount = new BankAccount(); //set the identity bankAccount.GenerateNewIdentity(); //set the bank account number bankAccount.BankAccountNumber = bankAccountNumber; //set default bank account as unlocked bankAccount.UnLock(); //set the customer for this bank account bankAccount.SetCustomerOwnerOfThisBankAccount(customer); return bankAccount; }
public void EnumerableOrderToOrderListDTOAdapter() { //Arrange Customer customer = new Customer(); customer.Id = IdentityGenerator.NewSequentialGuid(); customer.FirstName = "Unai"; customer.LastName = "Zorrilla"; Product product = new Software(); product.Id = IdentityGenerator.NewSequentialGuid(); product.Title = "the product title"; product.Description = "the product description"; Order order = new Order(); order.Id = IdentityGenerator.NewSequentialGuid(); order.OrderDate = DateTime.Now; order.ShippingInformation = new ShippingInfo("shippingName", "shippingAddress", "shippingCity", "shippingZipCode"); order.SetCustomer(customer); var line = order.CreateOrderLine(product.Id, 1, 200, 0); order.AddOrderLine(line); var orders = new List<Order>() { order }; //Act ITypeAdapter adapter = PrepareTypeAdapter(); var orderListDTO = adapter.Adapt<IEnumerable<Order>, List<OrderListDTO>>(orders); //Assert Assert.AreEqual(orderListDTO[0].Id, order.Id); Assert.AreEqual(orderListDTO[0].OrderDate, order.OrderDate); Assert.AreEqual(orderListDTO[0].DeliveryDate, order.DeliveryDate); Assert.AreEqual(orderListDTO[0].TotalOrder, order.GetOrderTotal()); Assert.AreEqual(orderListDTO[0].ShippingAddress, order.ShippingInformation.ShippingAddress); Assert.AreEqual(orderListDTO[0].ShippingCity, order.ShippingInformation.ShippingCity); Assert.AreEqual(orderListDTO[0].ShippingName, order.ShippingInformation.ShippingName); Assert.AreEqual(orderListDTO[0].ShippingZipCode, order.ShippingInformation.ShippingZipCode); Assert.AreEqual(orderListDTO[0].CustomerFullName, order.Customer.FullName); Assert.AreEqual(orderListDTO[0].CustomerId, order.Customer.Id); }
public void OrderAddNewOrderLineFixOrderId() { //Arrange var shippingName = "shippingName"; var shippingCity = "shippingCity"; var shippingZipCode = "shippingZipCode"; var shippingAddress = "shippingAddress"; var customer = new Customer(); customer.GenerateNewIdentity(); var order = OrderFactory.CreateOrder(customer, shippingName, shippingCity, shippingAddress, shippingZipCode); order.GenerateNewIdentity(); var line = order.AddNewOrderLine(Guid.NewGuid(), 1, 1, 0); //Assert Assert.AreEqual(order.Id, line.OrderId); }
/// <summary> /// Create a new transient customer /// </summary> /// <param name="firstName">The customer firstName</param> /// <param name="lastName">The customer lastName</param> /// <param name="country">The associated country to this customer</param> /// <returns>A valid customer</returns> public static Customer CreateCustomer( string firstName, string lastName, string telephone, string company, Country country, Address address) { //create new instance and set identity var customer = new Customer(); customer.GenerateNewIdentity(); //set data customer.FirstName = firstName; customer.LastName = lastName; customer.Company = company; customer.Telephone = telephone; //set address customer.Address = address; //customer is enabled by default customer.Enable(); //TODO: By default this is the limit for customer credit, you can set this //parameter customizable via configuration or other system customer.ChangeTheCurrentCredit(1000M); //set default picture var picture = new Picture(); picture.ChangeCurrentIdentity(customer.Id); customer.ChangePicture(picture); //set the country for this customer customer.SetTheCountryForThisCustomer(country); return customer; }
/// <summary> /// Create a new transient customer /// </summary> /// <param name="firstName">The customer firstName</param> /// <param name="lastName">The customer lastName</param> /// <param name="country">The associated country to this customer</param> /// <returns>A valid customer</returns> public static Customer CreateCustomer(string firstName, string lastName, Guid countryId,Address address) { //create the customer instance var customer = new Customer() { FirstName = firstName, LastName = lastName }; //set address customer.Address = address; //TODO: By default this is the limit for customer credit, you can set this //parameter customizable via configuration or other system customer.CreditLimit = 1000M; //set country identifier customer.CountryId = countryId; customer.Enable(); return customer; }
public void PerformBankTransfer() { //Arrange //--> source bank account data var sourceId = new Guid("3481009C-A037-49DB-AE05-44FF6DB67DEC"); var bankAccountNumberSource = new BankAccountNumber("4444", "5555", "3333333333", "02"); var sourceCustomer = new Customer(); sourceCustomer.GenerateNewIdentity(); var source = BankAccountFactory.CreateBankAccount(sourceCustomer, bankAccountNumberSource); source.ChangeCurrentIdentity(sourceId); source.DepositMoney(1000, "initial"); var sourceBankAccountDto = new BankAccountDto() { Id = sourceId, BankAccountNumber = source.Iban }; //--> target bank account data var targetCustomer = new Customer(); targetCustomer.GenerateNewIdentity(); var targetId = new Guid("8A091975-F783-4730-9E03-831E9A9435C1"); var bankAccountNumberTarget = new BankAccountNumber("1111", "2222", "3333333333", "01"); var target = BankAccountFactory.CreateBankAccount(targetCustomer, bankAccountNumberTarget); target.ChangeCurrentIdentity(targetId); var targetBankAccountDto = new BankAccountDto() { Id = targetId, BankAccountNumber = target.Iban }; var accounts = new List<BankAccount>() { source, target }; var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetGuid = (guid) => { return accounts.Where(ba => ba.Id == guid).SingleOrDefault(); }; bankAccountRepository.UnitOfWorkGet = () => { var unitOfWork = new StubIUnitOfWork(); unitOfWork.Commit = () => { }; return unitOfWork; }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act bankingService.PerformBankTransfer(sourceBankAccountDto, targetBankAccountDto, 100M); //Assert Assert.AreEqual(source.Balance, 900); Assert.AreEqual(target.Balance, 100); }
public void FindBankAccountsReturnAllItems() { var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetAll = () => { var customer = new Customer(); customer.GenerateNewIdentity(); var bankAccount = new BankAccount() { BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02"), }; bankAccount.SetCustomerOwnerOfThisBankAccount(customer); bankAccount.GenerateNewIdentity(); var accounts = new List<BankAccount>() { bankAccount }; return accounts; }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.FindBankAccounts(); Assert.IsNotNull(result); Assert.IsTrue(result.Count == 1); }
public void AddBankAccountReturnDtoWhenSaveSucceed() { //Arrange IBankTransferService transferService = new BankTransferService(); var customerRepository = new StubICustomerRepository(); customerRepository.GetGuid = (guid) => { var customer = new Customer() { FirstName = "Jhon", LastName = "El rojo" }; customer.ChangeCurrentIdentity(guid); return customer; }; var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.AddBankAccount = (ba) => { }; bankAccountRepository.UnitOfWorkGet = () => { var uow = new StubIUnitOfWork(); uow.Commit = () => { }; return uow; }; var dto = new BankAccountDto() { CustomerId = Guid.NewGuid(), BankAccountNumber = "BA" }; IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.AddBankAccount(dto); //Assert Assert.IsNotNull(result); }
Order CreateNewOrder(OrderDTO dto, Customer associatedCustomer) { //Create a new order entity from factory Order newOrder = OrderFactory.CreateOrder(associatedCustomer, dto.ShippingName, dto.ShippingCity, dto.ShippingAddress, dto.ShippingZipCode); //if have lines..add if (dto.OrderLines != null) { foreach (var line in dto.OrderLines) //add order lines newOrder.AddNewOrderLine(line.ProductId, line.Amount, line.UnitPrice, line.Discount / 100); } return newOrder; }
/// <summary> /// Link a customer to this order line /// </summary> /// <param name="customer">The customer to relate</param> public void SetTheCustomerForThisOrder(Customer customer) { if (customer == null || customer.IsTransient()) { throw new ArgumentException(Messages.exception_CannotAssociateTransientOrNullCustomer); } this.Customer = customer; this.CustomerId = customer.Id; }
Order CreateNewOrder(OrderDTO dto, Customer associatedCustomer) { //Create a new order entity from factory Order newOrder = OrderFactory.CreateOrder(associatedCustomer, dto.ShippingName, dto.ShippingCity, dto.ShippingAddress, dto.ShippingZipCode); //set the poid newOrder.Id = IdentityGenerator.NewSequentialGuid(); //if have lines..add if (dto.OrderLines != null) { foreach (var line in dto.OrderLines) { var orderLine = newOrder.CreateOrderLine(line.ProductId, line.Amount, line.UnitPrice, line.Discount); newOrder.AddOrderLine(orderLine); } } return newOrder; }
public void EnumerableOrderToOrderListDtoAdapter() { //Arrange var customer = new Customer(); customer.GenerateNewIdentity(); customer.FirstName = "Unai"; customer.LastName = "Zorrilla"; Product product = new Software("the product title", "the product description", "license code"); product.GenerateNewIdentity(); var order = new Order(); order.GenerateNewIdentity(); order.OrderDate = DateTime.Now; order.ShippingInformation = new ShippingInfo( "shippingName", "shippingAddress", "shippingCity", "shippingZipCode"); order.SetTheCustomerForThisOrder(customer); var line = order.AddNewOrderLine(product.Id, 1, 200, 0); var orders = new List<Order>() { order }; //Act var adapter = TypeAdapterFactory.CreateAdapter(); var orderListDto = adapter.Adapt<IEnumerable<Order>, List<OrderListDto>>(orders); //Assert Assert.AreEqual(orderListDto[0].Id, order.Id); Assert.AreEqual(orderListDto[0].OrderDate, order.OrderDate); Assert.AreEqual(orderListDto[0].DeliveryDate, order.DeliveryDate); Assert.AreEqual(orderListDto[0].TotalOrder, order.GetOrderTotal()); Assert.AreEqual(orderListDto[0].ShippingAddress, order.ShippingInformation.ShippingAddress); Assert.AreEqual(orderListDto[0].ShippingCity, order.ShippingInformation.ShippingCity); Assert.AreEqual(orderListDto[0].ShippingName, order.ShippingInformation.ShippingName); Assert.AreEqual(orderListDto[0].ShippingZipCode, order.ShippingInformation.ShippingZipCode); Assert.AreEqual(orderListDto[0].CustomerFullName, order.Customer.FullName); Assert.AreEqual(orderListDto[0].CustomerId, order.Customer.Id); }
public void LockBankAccountReturnTrueIfBankAccountIsLocked() { //Arrange var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.UnitOfWorkGet = () => { var uow = new StubIUnitOfWork(); uow.Commit = () => { }; return uow; }; bankAccountRepository.GetGuid = (guid) => { var customer = new Customer(); customer.GenerateNewIdentity(); var bankAccount = new BankAccount(); bankAccount.GenerateNewIdentity(); bankAccount.SetCustomerOwnerOfThisBankAccount(customer); return bankAccount; }; IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.LockBankAccount(Guid.NewGuid()); //Assert Assert.IsTrue(result); }
void SaveCustomer(Customer customer) { //recover validator var validator = EntityValidatorFactory.CreateValidator(); if (validator.IsValid(customer)) //if customer is valid { //add the customer into the repository _customerRepository.Add(customer); //commit the unit of work _customerRepository.UnitOfWork.Commit(); } else //customer is not valid, throw validation errors throw new ApplicationValidationErrorsException(validator.GetInvalidMessages<Customer>(customer)); }
public void OrderAddOrderLineFixOrderId() { //Arrange string shippingName= "shippingName"; string shippingCity = "shippingCity"; string shippingZipCode = "shippingZipCode"; string shippingAddress = "shippingAddress"; Customer customer = new Customer(); customer.Id = IdentityGenerator.NewSequentialGuid(); Order order = OrderFactory.CreateOrder(customer, shippingName, shippingCity, shippingAddress, shippingZipCode); order.Id = IdentityGenerator.NewSequentialGuid(); var line = order.CreateOrderLine(IdentityGenerator.NewSequentialGuid(), 1, 1, 0); //Act order.AddOrderLine(line); //Assert Assert.AreEqual(order.Id, line.OrderId); }