Exemplo n.º 1
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);
      }
      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.º 3
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());
      }
Exemplo n.º 4
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);
      }
        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.º 6
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);

      }
Exemplo n.º 7
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 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);
        }
        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);

        }
        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.º 11
0
      public void AdaptEnumerableBankAccountToListBankAccountListDto()
      {
         //Arrange

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

         var customer = CustomerFactory.CreateCustomer(
            "jhon",
            "el rojo",
            "+341232",
            "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");
         var accounts = new List<BankAccount>()
         {
            account
         };

         //Act
         var adapter = TypeAdapterFactory.CreateAdapter();
         var bankAccountsDto = adapter.Adapt<IEnumerable<BankAccount>, List<BankAccountDto>>(accounts);

         //Assert
         Assert.IsNotNull(bankAccountsDto);
         Assert.IsTrue(bankAccountsDto.Count == 1);

         Assert.AreEqual(account.Id, bankAccountsDto[0].Id);
         Assert.AreEqual(account.Iban, bankAccountsDto[0].BankAccountNumber);
         Assert.AreEqual(account.Balance, bankAccountsDto[0].Balance);
         Assert.AreEqual(account.Customer.FirstName, bankAccountsDto[0].CustomerFirstName);
         Assert.AreEqual(account.Customer.LastName, bankAccountsDto[0].CustomerLastName);
      }
Exemplo n.º 12
0
      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);
      }
        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.º 14
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.º 15
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.º 16
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);
      }
Exemplo n.º 17
0
      public void AddNewCustomerThrowApplicationErrorsWhenEntityIsNotValid()
      {
         //Arrange
         var countryId = Guid.NewGuid();

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

            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() //missing lastname
         {
            CountryId = Guid.NewGuid(),
            FirstName = "Jhon"
         };

         //act
         var result = customerManagementService.AddNewCustomer(customerDto);
      }
        public void BankAccountCannotWithDrawMoneyIfBalanceIsLessThanAmountAccount()
        {
            //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.WithdrawMoney(200, "the reason..");
        }
Exemplo n.º 19
0
      private Customer GetCustomer()
      {
         var firstName = "firstName";
         var lastName = "lastName";
         var telephone = string.Empty;
         var company = string.Empty;
         var city = "city";
         var zipCode = "zipCode";
         var addressline1 = "addressline1";
         var addressline2 = "addressline2";

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

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

         var customer = CustomerFactory.CreateCustomer(firstName, lastName, telephone, company, country, address);

         return customer;
      }
Exemplo n.º 20
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());
      }
Exemplo n.º 21
0
      public void RemoveCustomerSetCustomerAsDisabled()
      {
         //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;
         };

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

         customerRepository.GetGuid = (guid) => { return customer; };

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

         //Assert
         Assert.IsFalse(customer.IsEnabled);
      }
Exemplo n.º 22
0
      public void BankAccountCannotDepositMoneyInLockedAccount()
      {
         //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);
         bankAccount.Lock();

         //Act
         bankAccount.DepositMoney(200, "the reason..");
      }
Exemplo n.º 23
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);
      }
Exemplo n.º 24
0
      public void BankAccountWithdrawMoneyAnotateActivity()
      {
         //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);

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

         //Assert
         Assert.IsTrue(bankAccount.Balance == 0);
         Assert.IsNotNull(bankAccount.BankAccountActivity);
         Assert.IsNotNull(bankAccount.BankAccountActivity.Any());
         Assert.IsTrue(bankAccount.BankAccountActivity.Last().Amount == -1000);
         Assert.IsTrue(bankAccount.BankAccountActivity.Last().ActivityDescription == activityReason);
      }
Exemplo n.º 25
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.º 26
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);
      }
Exemplo n.º 27
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.º 28
0
      public void BankAccountCannotDepositMoneyLessThanZero()
      {
         //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);

         bankAccount.DepositMoney(-100, activityReason);
      }
Exemplo n.º 29
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);
      }
        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));
        }