/// <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;
        }
        public void CustomerFactoryWithCountryEntityCreateValidCustomer()
        {
            //Arrange
            string lastName = "El rojo";
            string firstName = "Jhon";

            Guid countryId = IdentityGenerator.NewSequentialGuid();
            Country country = new Country()
            {
                Id = countryId
            };

            //Act
            Customer customer = CustomerFactory.CreateCustomer(firstName,lastName, 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, countryId);
            Assert.AreEqual(customer.IsEnabled, true);
            Assert.AreEqual(customer.CreditLimit, 1000M);

            Assert.IsFalse(validationResults.Any());
        }
        public void CountryEnumerableToCountryDTOList()
        {
            //Arrange
            Guid idCountry = IdentityGenerator.NewSequentialGuid();

            Country country = new Country()
            {
                Id = idCountry,
                CountryName = "Spain",
                CountryISOCode = "es-ES"
            };

            IEnumerable<Country> countries = new List<Country>() { country };

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var dtos = adapter.Adapt<IEnumerable<Country>, List<CountryDTO>>(countries);

            //Assert
            Assert.IsNotNull(dtos);
            Assert.IsTrue(dtos.Any());
            Assert.IsTrue(dtos.Count == 1);

            var dto = dtos[0];

            Assert.AreEqual(idCountry, dto.Id);
            Assert.AreEqual(country.CountryName, dto.CountryName);
            Assert.AreEqual(country.CountryISOCode, dto.CountryISOCode);
        }
Exemplo n.º 4
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.IsNotNull(bankAccount);
         Assert.IsTrue(bankAccount.BankAccountNumber == bankAccountNumber);
         Assert.IsFalse(bankAccount.Locked);
         Assert.IsTrue(bankAccount.CustomerId == customer.Id);

         Assert.IsFalse(validationResults.Any());
      }
        public void CountryRepositoryAddNewItemSaveItem()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            ICountryRepository countryRepository = new CountryRepository(unitOfWork);

            var country = new Country()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                CountryName = "France",
                CountryISOCode = "fr-FR"
            };

            //Act

            countryRepository.Add(country);
            countryRepository.UnitOfWork.Commit();

            //Assert

            var result = countryRepository.Get(country.Id);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id == country.Id);
        }
      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();

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

         //Act
         var adapter = TypeAdapterFactory.CreateAdapter();
         var bankAccountDto = adapter.Adapt<BankAccount, BankAccountDto>(account);

         //Assert
         Assert.AreEqual(account.Id, bankAccountDto.Id);
         Assert.AreEqual(account.Iban, bankAccountDto.BankAccountNumber);
         Assert.AreEqual(account.Balance, bankAccountDto.Balance);
         Assert.AreEqual(account.Customer.FirstName, bankAccountDto.CustomerFirstName);
         Assert.AreEqual(account.Customer.LastName, bankAccountDto.CustomerLastName);
         Assert.AreEqual(account.Locked, bankAccountDto.Locked);
      }
Exemplo n.º 7
0
      public void CountryEnumerableToCountryDtoList()
      {
         //Arrange

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

         IEnumerable<Country> countries = new List<Country>()
         {
            country
         };

         //Act
         var adapter = TypeAdapterFactory.CreateAdapter();
         var dtos = adapter.Adapt<IEnumerable<Country>, List<CountryDto>>(countries);

         //Assert
         Assert.IsNotNull(dtos);
         Assert.IsTrue(dtos.Any());
         Assert.IsTrue(dtos.Count == 1);

         var dto = dtos[0];

         Assert.AreEqual(country.Id, dto.Id);
         Assert.AreEqual(country.CountryName, dto.CountryName);
         Assert.AreEqual(country.CountryIsoCode, dto.CountryIsoCode);
      }
Exemplo n.º 8
0
      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 CustomerCannotAssociateTransientCountry()
        {
            //Arrange
            Country country = new Country()
            {
                CountryName ="Spain"
            };

            //Act
            Customer customer = new Customer();
            customer.SetCountry(country);
        }
        public void CountryRepositoryAddNewItemSaveItem()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            var countryRepository = new CountryRepository(unitOfWork);

            var country = new Country("France", "fr-FR");
            country.GenerateNewIdentity();

            //Act
            countryRepository.Add(country);
            unitOfWork.Commit();
        }
Exemplo n.º 12
0
      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);
      }
Exemplo n.º 13
0
      public void CustomerEnumerableToCustomerListDtoListAdapt()
      {
         //Arrange

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

         var address = new Address("Monforte", "27400", "AddressLine1", "AddressLine2");

         var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", "617404929", "Spirtis", country, address);
         var picture = new Picture
         {
            RawPhoto = new byte[0]
            {
            }
         };

         customer.ChangeTheCurrentCredit(1000M);
         customer.ChangePicture(picture);
         customer.SetTheCountryForThisCustomer(country);

         IEnumerable<Customer> customers = new List<Customer>()
         {
            customer
         };

         //Act
         var adapter = TypeAdapterFactory.CreateAdapter();

         var dtos = adapter.Adapt<IEnumerable<Customer>, List<CustomerListDto>>(customers);

         //Assert

         Assert.IsNotNull(dtos);
         Assert.IsTrue(dtos.Any());
         Assert.IsTrue(dtos.Count == 1);

         var dto = dtos[0];

         Assert.AreEqual(customer.Id, 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);

      }
        public void BankAccountSetCustomerFixCustomerId()
        {
            //Arrange
            Country country = new Country("Spain", "es-ES");
            country.GenerateNewIdentity();

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

            //Assert
            Assert.AreEqual(customer.Id, bankAccount.CustomerId);
        }
Exemplo n.º 15
0
      public void CountryToCountryDtoAdapter()
      {
         //Arrange
         var country = new Country("Spain", "es-ES");
         country.GenerateNewIdentity();

         //Act
         var adapter = TypeAdapterFactory.CreateAdapter();
         var dto = adapter.Adapt<Country, CountryDto>(country);

         //Assert
         Assert.AreEqual(country.Id, dto.Id);
         Assert.AreEqual(country.CountryName, dto.CountryName);
         Assert.AreEqual(country.CountryIsoCode, dto.CountryIsoCode);
      }
        public void CountryWithNullNameProduceValidationError()
        {
            //Arrange
            Country country = new Country();
            country.CountryName = null;

            ValidationContext validationContext = new ValidationContext(country, null, null);

            //Act
            var validationResults = country.Validate(validationContext);

            //assert
            Assert.IsNotNull(validationResults);
            Assert.IsTrue(validationResults.Any());
            Assert.IsTrue(validationResults.First().MemberNames.Contains("CountryName"));
        }
        public void CountryWithEmptyIsoCodeProduceValidationError()
        {
            //Arrange
            Country country = new Country();
            country.CountryName = "Spain";
            country.CountryISOCode = string.Empty;

            ValidationContext validationContext = new ValidationContext(country, null, null);

            //Act
            var validationResults = country.Validate(validationContext);

            //assert
            Assert.IsNotNull(validationResults);
            Assert.IsTrue(validationResults.Any());
            Assert.IsTrue(validationResults.First().MemberNames.Contains("CountryISOCode"));
        }
Exemplo n.º 18
0
      /// <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;
      }
        public void BankAccountLockSetLocked()
        {
            //Arrange
            Country 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);

        }
Exemplo n.º 20
0
      public void AddNewCustomerReturnAdaptedDto()
      {
         //Arrange

         var countryRepository = new StubICountryRepository();
         countryRepository.GetGuid = (guid) =>
         {
            var country = new Country("Spain", "es-ES");
            ;
            country.ChangeCurrentIdentity(guid);

            return country;
         };
         var customerRepository = new StubICustomerRepository();
         customerRepository.AddCustomer = (customer) => { };
         customerRepository.UnitOfWorkGet = () =>
         {
            var uow = new StubIUnitOfWork();
            uow.Commit = () => { };

            return uow;
         };

         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

         var customerDto = new CustomerDto()
         {
            CountryId = Guid.NewGuid(),
            FirstName = "Jhon",
            LastName = "El rojo"
         };

         //act
         var result = customerManagementService.AddNewCustomer(customerDto);

         //Assert
         Assert.IsNotNull(result);
         Assert.IsTrue(result.Id != Guid.Empty);
         Assert.AreEqual(result.FirstName, customerDto.FirstName);
         Assert.AreEqual(result.LastName, customerDto.LastName);
      }
        public void CountryToCountryDTOAdapter()
        {
            //Arrange
            Guid idCountry = IdentityGenerator.NewSequentialGuid();

            Country country = new Country()
            {
                Id = idCountry,
                CountryName = "Spain",
                CountryISOCode = "es-ES"
            };

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var dto = adapter.Adapt<Country,CountryDTO>(country);

            //Assert
            Assert.AreEqual(idCountry, dto.Id);
            Assert.AreEqual(country.CountryName, dto.CountryName);
            Assert.AreEqual(country.CountryISOCode, dto.CountryISOCode);
        }
        public void CustomerToCustomerDTOAdapt()
        {
            //Arrange

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

            var address = new Address("Monforte", "27400", "AddressLine1", "AddressLine2");

            var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", "617404929", "Spirtis", country, address);
            var picture = new Picture { RawPhoto = new byte[0] { } };

            customer.ChangeTheCurrentCredit(1000M);
            customer.ChangePicture(picture);
            customer.SetTheCountryForThisCustomer(country);

            //Act

            ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter();
            var dto = adapter.Adapt<Customer, CustomerDTO>(customer);

            //Assert

            Assert.AreEqual(customer.Id, 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.Country.CountryName, dto.CountryCountryName);
            Assert.AreEqual(country.Id, dto.CountryId);


            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);
        }
Exemplo n.º 23
0
      public void CustomerRepositoryAddNewItemSaveItem()
      {
         //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 customer = CustomerFactory.CreateCustomer(
            "Felix",
            "Trend",
            "+3434",
            "company",
            country,
            new Address("city", "zipCode", "addressLine1", "addressLine2"));
         customer.SetTheCountryReference(country.Id);

         //Act
         customerRepository.Add(customer);
         unitOfWork.Commit();
      }
Exemplo n.º 24
0
      public void UpdateCustomerMergePersistentAndCurrent()
      {
         //Arrange
         var country = new Country("spain", "es-ES");
         country.GenerateNewIdentity();

         var customerId = Guid.NewGuid();

         var countryRepository = new StubICountryRepository();
         var customerRepository = new StubICustomerRepository();

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

            return uow;
         };

         customerRepository.GetGuid = (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.MergeCustomerCustomer = (persistent, current) =>
         {
            Assert.AreEqual(persistent, current);
            Assert.IsTrue(persistent != null);
            Assert.IsTrue(current != null);
         };

         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

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

         //act
         customerManagementService.UpdateCustomer(customerDto);
      }
        public void CountryRepositoryRemoveItemDeleteIt()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            var countryRepository = new CountryRepository(unitOfWork);

            var country = new Country("England", "en-EN");
            country.GenerateNewIdentity();
            
            countryRepository.Add(country);
            countryRepository.UnitOfWork.Commit();

            //Act
            countryRepository.Remove(country);
            unitOfWork.Commit();
        }
Exemplo n.º 26
0
      public void FindCountriesByFilterMaterializeResults()
      {
         //Arrange
         var customerRepository = new StubICustomerRepository();
         var countryRepository = new StubICountryRepository();
         countryRepository.AllMatchingISpecificationOfCountry = (spec) =>
         {

            var country = new Country("country name", "country iso");
            country.GenerateNewIdentity();

            return new List<Country>()
            {
               country
            };
         };

         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

         //Act
         var result = customerManagementService.FindCountries("filter");

         //Assert
         Assert.IsNotNull(result);
         Assert.IsTrue(result.Count == 1);
      }
Exemplo n.º 27
0
      public void FindCountriesInPageMaterializeResults()
      {
         //Arrange
         var customerRepository = new StubICustomerRepository();
         var countryRepository = new StubICountryRepository();
/*         countryRepository.GetPagedInt32Int32ExpressionOfFuncOfCountryKPropertyBoolean<string>(
            (index, count, order, ascending) =>
            {
               var country = new Country("country name", "country iso");
               country.GenerateNewIdentity();

               return new List<Country>()
               {
                  country
               };
            });*/
         countryRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfCountryM0Boolean<string>(
            (index, count, order, ascending) =>
            {
               var country = new Country("country name", " country iso");
               country.GenerateNewIdentity();
               return new List<Country>()
               {
                  country
               };
            });

         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

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

         //Assert
         Assert.IsNotNull(result);
         Assert.IsTrue(result.Count == 1);
      }
Exemplo n.º 28
0
      public void FindCustomerMaterializaResultIfExist()
      {
         //Arrange
         var countryRepository = new StubICountryRepository();
         var customerRepository = new StubICustomerRepository();
         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);
      }
Exemplo n.º 29
0
      public void FindCustomersByFilterMaterializeResults()
      {
         //Arrange
         var countryRepository = new StubICountryRepository();
         var customerRepository = new StubICustomerRepository();
         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);
      }
Exemplo n.º 30
0
      public void FindCustomersInPageMaterializeResults()
      {
         //Arrange
         var countryRepository = new StubICountryRepository();
         var customerRepository = new StubICustomerRepository();
         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);
      }