public void AddNewCustomerReturnAdaptedDTO()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            customerRepository.AddCustomer = (customer) => { };
            customerRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };

            var customerManagementService = new CustomerAppService(adapter, 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 AddNewCustomerThrowExceptionIfCustomerDtoIsNull()
      {
         //Arrange
         var countryRepository = new StubICountryRepository();
         var customerRepository = new StubICustomerRepository();

         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

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

         //Assert
         Assert.IsNull(result);
      }
      public void AddNewCustomerThrowArgumentExceptionIfCustomerCountryInformationIsEmpty()
      {
         //Arrange
         var countryRepository = new StubICountryRepository();
         var customerRepository = new StubICustomerRepository();

         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

         var customerDto = new CustomerDto()
         {
            CountryId = Guid.Empty
         };

         //act
         var result = customerManagementService.AddNewCustomer(customerDto);
      }
      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);
      }
      public void FindCustomersInPageReturnNullIfNotData()
      {
         //Arrange
         var countryRepository = new StubICountryRepository();
         var customerRepository = new StubICustomerRepository();
         customerRepository.GetEnabledInt32Int32 = (index, count) => { return new List<Customer>(); };

         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

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

         //Assert
         Assert.IsNull(result);

      }
        public void FindCountriesInPageMaterializeResults()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var countryRepository = new SICountryRepository();
            countryRepository.GetPagedInt32Int32ExpressionOfFuncOfCountryKPropertyBoolean<string>((index, count, order, ascending) =>
            {
                return new List<Country>()
                {
                    new Country(){Id = Guid.NewGuid(),CountryName ="country name",CountryISOCode="country iso"}
                };
            });

            var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository);

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

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }
      public void ConstructorThrowExceptionWhenCountryRepositoryDependencyIsNull()
      {
         //Arrange
         var customerRepository = new StubICustomerRepository();
         StubICountryRepository countryRepository = null;

         //act
         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

      }
      public void FindCountriesWithInvalidPageArgumentsReturnNull()
      {
         //Arrange
         var countryRepository = new StubICountryRepository();
         var customerRepository = new StubICustomerRepository();

         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

         //Act
         customerManagementService.FindCountries(-1, 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);
      }
예제 #10
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);
      }
예제 #11
0
      public void FindCustomerReturnNullIfCustomerIdIsEmpty()
      {
         //Arrange
         var countryRepository = new StubICountryRepository();
         var customerRepository = new StubICustomerRepository();
         customerRepository.GetGuid = (guid) =>
         {
            if (guid == Guid.Empty) {
               return null;
            }
            else
            {
               return new Customer();
            }
         };
         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

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

         //Assert
         Assert.IsNull(result);

      }
        public void FindCustomersWithInvalidPageArgumentsReturnNull()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();

            var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository);

            //Act
            var resultInvalidPageIndex = customerManagementService.FindCustomers(-1, 0);
            var resultInvalidPageCount = customerManagementService.FindCustomers(1, 0);

            //Assert
            Assert.IsNull(resultInvalidPageIndex);
            Assert.IsNull(resultInvalidPageCount);
        }
        public void RemoveCustomerSetCustomerAsDisabled()
        {
            //Arrange
            Guid countryGuid = Guid.NewGuid();
            Guid customerId = Guid.NewGuid();
            var adapter = PrepareTypeAdapter();
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();

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

                return uow;
            };

            var customer = CustomerFactory.CreateCustomer("Jhon","El rojo",countryGuid,new Address("city", "zipCode", "address line", "address line"));
            customer.Id = customerId;

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

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

            //Assert
            Assert.IsFalse(customer.IsEnabled);
        }
        public void FindCustomersInPageMaterializeResults()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            customerRepository.GetEnabledInt32Int32 = (index, count) =>
            {
                var customers = new List<Customer>();
                customers.Add(CustomerFactory.CreateCustomer("Jhon",
                                                            "El rojo",
                                                             Guid.NewGuid(),
                                                             new Address("city","zipCode","address line","address line2")));
                return customers;
            };

            var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository);

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

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }
        public void FindCustomersByFilterReturnNullIfNotData()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            customerRepository.AllMatchingISpecificationOfCustomer = (spec) =>
            {
                return new List<Customer>();
            };

            var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository);

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

            //Assert
            Assert.IsNull(result);
        }
        public void FindCustomersByFilterMaterializeResults()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            customerRepository.AllMatchingISpecificationOfCustomer = (spec) =>
            {
                var customers = new List<Customer>();
                customers.Add(CustomerFactory.CreateCustomer("Jhon",
                                                            "El rojo",
                                                             Guid.NewGuid(),
                                                             new Address("city", "zipCode", "address line", "address line2")));
                return customers;
            };

            var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository);

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

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }
        public void FindCustomerReturnNullIfCustomerIdIsEmpty()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();

            var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository);

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

            //Assert
            Assert.IsNull(result);
        }
        public void FindCustomerMaterializaResultIfExist()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            customerRepository.GetGuid = (guid) =>
            {
                return CustomerFactory.CreateCustomer("Jhon",
                                                      "El rojo",
                                                      Guid.NewGuid(),
                                                      new Address("city", "zipCode", "address line1", "address line2"));

            };

            var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository);

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

            //Assert
            Assert.IsNotNull(result);
        }
        public void UpdateCustomerMergePersistentAndCurrent()
        {
            //Arrange
            Guid countryGuid = Guid.NewGuid();
            Guid customerId = Guid.NewGuid();
            var adapter = PrepareTypeAdapter();
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();

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

                return uow;
            };

            customerRepository.GetGuid = (guid) =>
            {
                var customer = CustomerFactory.CreateCustomer("Jhon",
                                                               "El rojo",
                                                               countryGuid,
                                                               new Address("city", "zipCode", "address line", "address line"));
                customer.Id = customerId;

                return customer;
            };

            customerRepository.MergeCustomerCustomer = (persistent, current) =>
            {
                Assert.AreEqual(persistent, current);
                Assert.IsTrue(persistent != null);
                Assert.IsTrue(current != null);
            };

            var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository);

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

            //act
            customerManagementService.UpdateCustomer(customerDTO);
        }
        public void AddNewCustomerReturnNullIfCustomerCountryInformationIsEmpty()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();

            var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository);

            var customerDTO = new CustomerDTO()
            {
                CountryId = Guid.Empty
            };

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

            //Assert
            Assert.IsNull(result);
        }
예제 #21
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);
      }
예제 #22
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);
      }
예제 #23
0
      public void FindCountriesInPageReturnNullIfNotData()
      {
         //Arrange
         var customerRepository = new StubICustomerRepository();
         var countryRepository = new StubICountryRepository();
         //countryRepository.GetPagedInt32Int32ExpressionOfFuncOfCountryKPropertyBoolean<string>(
         //   (index, count, order, ascending) => { return new List<Country>(); });

         countryRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfCountryM0Boolean<string>(
            (index, count, order, ascending) => new List<Country>());

         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

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

         //Assert
         Assert.IsNull(result);
      }
예제 #24
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);
      }
예제 #25
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);
      }
예제 #26
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);
      }
예제 #27
0
      public void FindCountriesByFilterReturnNullIfNotData()
      {
         //Arrange
         var customerRepository = new StubICustomerRepository();
         var countryRepository = new StubICountryRepository();
         countryRepository.AllMatchingISpecificationOfCountry = (spec) => { return new List<Country>(); };

         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

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

         //Assert
         Assert.IsNull(result);
      }
예제 #28
0
      public void FindCustomersWithInvalidPageArgumentsThrowArgumentException()
      {
         //Arrange
         var countryRepository = new StubICountryRepository();
         var customerRepository = new StubICustomerRepository();

         var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

         //Act
         customerManagementService.FindCustomers(-1, 0);

      }
예제 #29
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 FindCountriesByFilterMaterializeResults()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var countryRepository = new SICountryRepository();
            countryRepository.AllMatchingISpecificationOfCountry = (spec)=>
            {
                return new List<Country>()
                {
                    new Country(){Id = Guid.NewGuid(),CountryName ="country name",CountryISOCode="country iso"}
                };
            };

            var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository);

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

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }