protected override void Context()
        {
            Username = "******";

            base.Context();

            _customerReturnedFromService = Builder<Domain.Customer>.CreateNew().Build();
            _customerReturnedFromService.MailingAddress = Builder<Address>.CreateNew().Build();
            _customerReturnedFromService.AddContact(Builder<Contact>.CreateNew().Build());

            // load customers
            for (int i = 0; i < 10; i++) { _lcs.Add(Builder<Domain.Customer>.CreateNew().Build()); }

            CustomerService.Stub(x => x.GetCustomer(Arg<string>.Is.Equal(Username),Arg<int>.Is.Equal(CustomerId)))
                .Return(_customerReturnedFromService);

            CustomerService.Stub(x => x.GetCustomers(Arg<string>.Is.Equal(Username), Arg<GetCustomersRequest>.Is.Anything))
                .Return(_lcs);

            _expectedViewModel = new UpdateCustomerViewModel
                                     {
                                         Name = _customerReturnedFromService.Name,
                                         Street = _customerReturnedFromService.MailingAddress.Street,
                                         AdditionalInfo = _customerReturnedFromService.MailingAddress.AdditionalInfo,
                                         City = _customerReturnedFromService.MailingAddress.City,
                                         State = _customerReturnedFromService.MailingAddress.State,
                                         Zipcode = _customerReturnedFromService.MailingAddress.Zipcode,
                                         ContactFirstName = _customerReturnedFromService.Contacts.First().FirstName,
                                         ContactLastName = _customerReturnedFromService.Contacts.First().LastName,
                                         ContactPhone = _customerReturnedFromService.Contacts.First().Phone,
                                         CustomerId = _customerReturnedFromService.CustomerId,
                                         Phone = _customerReturnedFromService.Phone,
                                         MailingAddressId = _customerReturnedFromService.MailingAddress.Id,
                                         ContactId = _customerReturnedFromService.Contacts.First().Id,
                                         ContactEmail = _customerReturnedFromService.Contacts.First().Email,
                                         GooglePlacesUrl = _customerReturnedFromService.GooglePlacesUrl,
                                         TwitterHandle = _customerReturnedFromService.TwitterHandle,
                                         WebsiteUrl = _customerReturnedFromService.WebsiteUrl,
                                         CustomerType = _customerReturnedFromService.CustomerType.ToString(),
                                         ParentCustomerId = _customerReturnedFromService.ParentCustomerId,
                                         ListName = _customerReturnedFromService.ListName,
                                         FacebookUrl = _customerReturnedFromService.FacebookUrl
                                     };
            _lcs.ForEach(x => _expectedViewModel.AddParentCustomer(new CustomerViewModel
                                                                                   {
                                                                                       Id = x.CustomerId,
                                                                                       Name = x.Name,
                                                                                   }));
        }
예제 #2
0
        public void AddPaymentMethodWithNhibernate()
        {
            ISession session = ServiceLocator.Factory.OpenSession();

            var method = new Domain.CreditCardPaymentMethod { RegistrationDate = DateTime.Now, Status = 2, CardHolderName = "Roman Jendrusz", CardNumber = "1234", CardType = "Visa" };
            var method2 = new Domain.DirectDebitPaymentMethod
                              {
                                  RegistrationDate = DateTime.Now,
                                  Status = 1,
                                  BankAccountNumber = "123123",
                                  HolderName = "sciemniacz"
                              };

            var customer = new Domain.Customer{Name = "Roman"};
            method.AssignedTo =  customer;
            method2.AssignedTo = customer;
            customer.UsedPaymentMethod = method2;
            var customer2 = new Domain.Customer { Name = "Marcin" };
            customer2.UsedPaymentMethod = method2;
            using(ITransaction transaction = session.BeginTransaction())
            {
                session.Save(customer);
                session.Save(method);
                session.Save(method2);
                transaction.Commit();
            }
            //IList<Domain.PaymentMethod> methods = session.CreateQuery("from PaymentMethod pm where pm.AssignedTo = :customer")
            //    .SetParameter("customer", customer)
            //    .List<Domain.PaymentMethod>();
            session = ServiceLocator.Factory.OpenSession();
            IList<Domain.PaymentMethod> methods =
                session.Linq<Domain.PaymentMethod>().Where(pm => pm.AssignedTo == customer).ToList();
            foreach (var paymentMethod in methods)
            {
                Console.WriteLine(paymentMethod.GetType().ToString());
            }
        }
        public void GetById_Should_Return_As_Expected([Frozen] Mock <ICustomerAssembler> assembler, [Frozen] Mock <ICustomerRepository> repository, Guid id, CustomerDto customerDto, Domain.Customer customer, CustomerService sut)
        {
            assembler.Setup(c => c.ToCustomerDto(customer)).Returns(customerDto);
            repository.Setup(c => c.Get(id)).Returns(customer);

            Action action = () =>
            {
                var result = sut.GetById(id);
                result.Should().BeEquivalentTo(customerDto);
            };

            action.Should().NotThrow <Exception>();
        }
        public void UpdateCustomer_Should_Success([Frozen] Mock <ICustomerAssembler> assembler, [Frozen] Mock <ICustomerRepository> repository, CustomerDto customerDto, Domain.Customer customer, CustomerService sut)
        {
            assembler.Setup(c => c.ToCustomer(customerDto)).Returns(customer);
            repository.Setup(c => c.Update(customer));

            Action action = () =>
            {
                sut.Update(customerDto);
            };

            action.Should().NotThrow <Exception>();
        }
        public void SetFields_Should_Update_Fields(string fullName, string cityCode, DateTime birthDate, Domain.Customer sut)
        {
            sut.SetFields(fullName, cityCode, birthDate);

            sut.FullName.Should().Be(fullName);
            sut.CityCode.Should().Be(cityCode);
            sut.BirthDate.Should().Be(birthDate);
        }
예제 #6
0
 public void ShouldRetrieveTheAssociatedObjectThatIsADerivedClass()
 {
     using (var scope = new TransactionScope())
     {
         ISession session = ServiceLocator.Factory.OpenSession();
         string customerName = "Test Customer";
         using (ITransaction transaction = session.BeginTransaction())
         {
             var customer = new Domain.Customer {Name = customerName};
             var paymentMethod = new Domain.CreditCardPaymentMethod
                                     {
                                         AssignedTo = customer,
                                         CardHolderName = "Joseph",
                                         CardNumber = "AAABBB!@#12",
                                         CardType = "Visa",
                                         RegistrationDate = new DateTime(2008, 10, 10),
                                         Status = 1
                                     };
             session.Save(customer);
             session.Save(paymentMethod);
             customer.UsedPaymentMethod = paymentMethod;
             transaction.Commit();
         }
         session = ServiceLocator.Factory.OpenSession();
         var previouslyAddedCustomer = session.Linq<Domain.Customer>().Where(x => x.Name == customerName).First();
         Assert.That(previouslyAddedCustomer.UsedPaymentMethod, Is.TypeOf<Domain.CreditCardPaymentMethod>());
     }
 }
예제 #7
0
 public Task UpdateCustomer(Domain.Customer customer)
 {
     HashCustomerPassword(customer);
     return(_customerRepository.UpdateCustomer(customer));
 }
예제 #8
0
        public void WhenRemovingCustomerShouldRemoveAlsoServices_withNH()
        {
            var customer = new Domain.Customer {Name = "Tester"};
            customer.Services = new HashSet<Domain.Service>();
            customer.Services.Add(new Domain.Service{MonthlyFee = 2, Name = "VOIP", BoughtBy = customer});
            ISession session = ServiceLocator.Factory.OpenSession();
            using (var transactionScope = new TransactionScope())
            {
                //Adding customer with services
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(customer);
                    transaction.Commit();
                }

                //Removing customer
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Delete(customer);
                    transaction.Commit();
                }
                Assert.That(session.Linq<Domain.Service>().Count(), Is.EqualTo(0));
            }
        }
예제 #9
0
 public void ShouldRetrieveAllCustomerRelatioinshipsWithAPerformantQuery_NH()
 {
     using (new TransactionScope())
     {
         ISession session = ServiceLocator.Factory.OpenSession();
         var customer = new Domain.Customer {Name = "Test Customer"};
         var paymentMethod = new Domain.DirectDebitPaymentMethod
                                 {
                                     AssignedTo = customer,
                                     BankAccountNumber = "1234",
                                     HolderName = "Test Customer",
                                     RegistrationDate = DateTime.Today,
                                     Status = 1
                                 };
         customer.UsedPaymentMethod = paymentMethod;
         customer.Services = new HashSet<Domain.Service>();
         customer.Services.Add(new Domain.Service {BoughtBy = customer, MonthlyFee = 20, Name = "Voip"});
         using (ITransaction transaction = session.BeginTransaction())
         {
             session.Save(customer);
             session.Save(paymentMethod);
             transaction.Commit();
         }
         session.Clear();
         IEnumerable<Domain.Customer> customers = session.CreateCriteria(typeof(Domain.Customer))
             .SetFetchMode("Services", FetchMode.Eager)
             .Add(Expression.Eq("Name", "Test Customer")).Future<Domain.Customer>();
         session.CreateCriteria(typeof(Domain.Customer))
             .SetFetchMode("UsedPaymentMethod", FetchMode.Eager)
             .Add(Expression.Eq("Name", "Test Customer")).Future<Domain.Customer>();
         customers = customers.ToList();
         Assert.That(customers, Has.Count.EqualTo(1));
         Assert.That(customer.Services, Has.Count.EqualTo(1));
         Assert.That(customer.UsedPaymentMethod, Is.Not.Null);
     }
 }
예제 #10
0
 public void UpdateCustomer(Domain.Customer c)
 {
     _repo.UpdateCustomer(c);
 }
예제 #11
0
 public void AddCustomer(Domain.Customer c)
 {
     _repo.AddCustomer(c);
 }
예제 #12
0
 public Task <Domain.Customer> Update(Domain.Customer entity)
 {
     _dbSet.Update(entity);
     return(Task.FromResult(entity));
 }
예제 #13
0
        public async Task <Domain.Customer> Add(Domain.Customer entity)
        {
            var result = await _dbSet.AddAsync(entity);

            return(result.Entity);
        }
예제 #14
0
        public IEnumerable<Domain.Customer> QuickSearch(string searchString)
        {
            using (var context = new PRToolsEntities())
            {
                string[] searchWords = searchString.Split(' ');

                IEnumerable<IQueryable<Customer>> customerEntityLists =
                    searchWords.Select(
                        x => (from customerLists in context.Customers.Include("Contacts").Include("Addresses")
                              where customerLists.Name.Contains(x)
                              select customerLists));

                IEnumerable<Customer> customerEntities = (from customers in customerEntityLists
                                                          from customer in customers
                                                          select customer);

                var domainCustomers = new List<Domain.Customer>();
                foreach (Customer customerEntity in customerEntities)
                {
                    var customer = new Domain.Customer
                                       {
                                           CustomerId = customerEntity.CustomerId,
                                           Name = customerEntity.Name,
                                           CustomerType =
                                               (customerEntity.CustomerTypeKey != null
                                                    ? (Domain.CustomerType)
                                                      Enum.Parse(typeof (Domain.CustomerType),
                                                                 customerEntity.CustomerTypeKey)
                                                    : Domain.CustomerType.Undefined),
                                           ParentCustomerId = customerEntity.ParentCustomerId ?? 0
                                       };
                    if (customer.ParentCustomerId != 0)
                    {
                        customer.ParentName = customerEntity.Customer1.Name;
                    }
                    else
                    {
                        customer.ParentName = customer.Name;
                    }

                    Address mailingAddress = customerEntity.Addresses.FirstOrDefault(x => x.AddressType == "Mailing");
                    if (mailingAddress != null)
                    {
                        customer.MailingAddress = new Domain.Address
                                                      {
                                                          Street = mailingAddress.Street,
                                                          AdditionalInfo = mailingAddress.AdditionalInfo,
                                                          City = mailingAddress.City,
                                                          State = mailingAddress.State,
                                                          Zipcode = mailingAddress.Zipcode,
                                                      };
                    }

                    foreach (Contact contact in customerEntity.Contacts)
                    {
                        customer.AddContact(new Domain.Contact
                                                {
                                                    FirstName = contact.FirstName,
                                                    LastName = contact.LastName,
                                                    Phone = contact.Phone,
                                                });
                    }
                    domainCustomers.Add(customer);
                }
                return domainCustomers;
            }
        }
예제 #15
0
 public void DisableCustomer(Domain.Customer customer)
 {
     throw new NotImplementedException();
 }
 public Task UpdateAsync(Domain.Customer customer)
 {
     return(Task.CompletedTask);
 }
예제 #17
0
 public Domain.Customer Execute(Guid id)
 {
     Domain.Customer result = (Domain.Customer)Domain.Customer.Replay(CustomerRepository.GetCustomers(id));
     return(result);
 }
예제 #18
0
 public void DeleteCustomer(Domain.Customer c)
 {
     _repo.DeleteCustomer(c);
 }
예제 #19
0
 public void Should_Update_The_Customer_with_different_services()
 {
     using (new TransactionScope())
     {
         ISession session = ServiceLocator.Factory.OpenSession();
         var customer = new Domain.Customer {Name = "Test Customer"};
         customer.Services = new HashSet<Domain.Service>();
         customer.Services.Add(new Domain.Service {BoughtBy = customer, MonthlyFee = 20, Name = "Voip"});
         using (ITransaction transaction = session.BeginTransaction())
         {
             session.Save(customer);
             transaction.Commit();
         }
         using (ITransaction transaction = session.BeginTransaction())
         {
             customer.Services.Clear();
             customer.Services.Add(new Domain.Service { BoughtBy = customer, MonthlyFee = 23, Name = "Voip2" });
             transaction.Commit();
         }
     }
 }
예제 #20
0
 public async Task <Domain.Customer> SaveAsync(Domain.Customer customer)
 {
     return(await context.SaveAndPublishAsync(customer, context.Customers));
 }
예제 #21
0
        public void When_Dereferencing_TheService_From_The_Customer_Should_Also_Remove_The_Service_Because_It_Beomes_An_Oprhan_Object()
        {
            var customer = new Domain.Customer { Name = "Tester" };
            customer.Services = new HashSet<Domain.Service>();
            customer.Services.Add(new Domain.Service { MonthlyFee = 2, Name = "VOIP", BoughtBy = customer });
            ISession session = ServiceLocator.Factory.OpenSession();
            using (var transactionScope = new TransactionScope())
            {
                //Adding customer with services
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(customer);
                    transaction.Commit();
                }

                //Removing customer
                using (ITransaction transaction = session.BeginTransaction())
                {
                    customer.Services.Clear();
                    transaction.Commit();
                }
                Assert.That(session.Linq<Domain.Service>().Count(), Is.EqualTo(0));
            }
        }
예제 #22
0
 public Task <int> CreateCustomer(Domain.Customer customer)
 {
     HashCustomerPassword(customer);
     return(_customerRepository.CreateCustomer(customer));
 }