public void TestCustomerToDto()
        {
            Customer customer = new Customer() {CustomerId = 1, Name = "FakeUserName", FirstName = "FakeFirstName", Version = 0};
            Address address = new Address() {AddressId = 1, AddressLine1 = "FakeStreet", PostalCode = "FakePostalCode", City = "FakeCity", Phone = "FakePhone", Email = "FakeEmail", Version = 0};
            customer.Addresses = new List<Address>() {address}.AsQueryable();
            Assert.AreEqual(true, customer.IsValid);
            Assert.AreEqual(true, address.IsValid);

            CustomerDTO dto = CustomerAdapter.CustomerToDto(customer);
            Assert.AreEqual<int>(customer.CustomerId, dto.Id);
            Assert.AreEqual<string>(customer.Name, dto.Name);
            Assert.AreEqual<string>(customer.FirstName, dto.FirstName);
            Assert.AreEqual(customer.Version, dto.Version);
            Assert.AreEqual<int>(1, dto.Addresses.Count());

            AddressDTO dtoAddress = dto.Addresses.First();
            Assert.AreEqual<int>(address.AddressId, dtoAddress.Id);
            Assert.AreEqual<String>(address.AddressLine1, dtoAddress.AddressLine1);
            Assert.AreEqual<String>(address.City, dtoAddress.City);
            Assert.AreEqual<string>(address.PostalCode, dtoAddress.PostalCode);
            Assert.AreEqual<string>(address.Phone, dtoAddress.Phone);
            Assert.AreEqual<string>(address.Email, dtoAddress.Email);
            Assert.AreEqual(address.Version, dtoAddress.Version);
            Assert.AreEqual(true, dto.IsValid);
            Assert.AreEqual(true, dtoAddress.IsValid);
        }
        public int StoreCustomer(Customer customer, IEnumerable<ChangeItem> changeItems)
        {
            int customerId = default(int);
            using (TransactionScope transaction = new TransactionScope())
            {
                customerId = rep.SaveCustomer(customer);
                foreach (ChangeItem change in changeItems)
                {
                    if (change.Object is Address)
                    {
                        Address address = (Address) change.Object;
                        switch (change.ChangeType)
                        {
                            case ChangeType.ChildInsert:
                            case ChangeType.ChildUpate:
                                rep.SaveAddress(address, customer);
                                break;
                            case ChangeType.ChildDelete:
                                rep.DeleteAddress(address.AddressId);
                                break;
                        }
                    }
                }
                transaction.Complete();
            }

            return customerId;
        }
 public static IEnumerable<ChangeItem> GetChangeItems(CustomerDTO dto, Customer customer)
 {
     IEnumerable<ChangeItem> changeItems = from c in dto.Changes
                                           select
                                               new ChangeItem(c.ChangeType,
                                                              AddressAdapter.DtoToAddress((AddressDTO) c.Object));
     return changeItems;
 }
        public void TestGetCustomerById()
        {
            CustomerBusinessComponent service = new CustomerBusinessComponent(this.context);
            Customer customer = new Customer() {CustomerId = 123};

            Expect.Once.On(context).Method("GetById").Will(Return.Value(customer));
            Customer resultCustomer = service.GetCustomerById(123);
            Assert.AreEqual<decimal>(customer.CustomerId, resultCustomer.CustomerId);
            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
 public void Validation()
 {
     customer = new Customer()
                    {
                        CustomerId = 1,
                        FirstName = "FakeName",
                        Name = "FakeName",
                        Version = 0
                    };
     Assert.IsTrue(customer.IsValid, "Should be valid");
 }
 private static int GetNumberOfOrdersOfCustomer(Customer customer, bool draftOnly)
 {
     if (customer.Orders == null)
     {
         return 0;
     }
     if (draftOnly)
     {
         return customer.Orders.Count(o => o.OrderStatus == OrderStatus.Draft);
     }
     return customer.Orders.Count();
 }
Example #7
0
 public static Customer DtoToCustomer(CustomerDTO dto)
 {
     Customer customer = new Customer()
                             {
                                 CustomerId = dto.Id,
                                 Name = dto.Name,
                                 FirstName = dto.FirstName,
                                 Version = dto.Version
                             };
     ValidationHelper.Validate(customer);
     return customer;
 }
Example #8
0
        public static CustomerDTO CustomerToDto(Customer c)
        {
            CustomerDTO dto = new CustomerDTO()
                                  {
                                      Id = c.CustomerId,
                                      Name = c.Name,
                                      FirstName = c.FirstName,
                                      Version = c.Version,
                                      Addresses = AddressAdapter.AddressToDtos(c.Addresses)
                                  };

            return dto;
        }
        public void TestGetCustomerByCriteria()
        {
            CustomerBusinessComponent service = new CustomerBusinessComponent(this.context);
            Address address = new Address {AddressId = 12345, City = "FakeCity"};
            Customer customer = new Customer {CustomerId = 456, Name = "FakeName", Addresses = new List<Address> {address}.AsQueryable()};
            IList<Customer> customers = new List<Customer>();
            customers.Add(customer);

            foreach (CustomerSearchType type in Enum.GetValues(typeof (CustomerSearchType)))
            {
                Expect.Once.On(context).Method("GetAll").Will(Return.Value(customers.AsQueryable()));
                IQueryable<Customer> resultCustomers = service.GetCustomersByCriteria(type, "FakeCity", "FakeName");
                Assert.AreEqual<decimal>(1, resultCustomers.Count());
                Assert.AreEqual<decimal>(customer.CustomerId, resultCustomers.First().CustomerId);
            }

            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
        public void TestOrdersToDtos()
        {
            Customer customer = new Customer() {CustomerId = 213, FirstName = "FakeFirstName", Name = "FakeName"};
            Order order = new Order() {OrderId = 1, OrderStatus = OrderStatus.Ordered, OrderDate = DateTime.Now, ShippedDate = null, Customer = customer, Version = 0};
            Assert.AreEqual(true, order.IsValid);

            IQueryable<Order> orders = new List<Order>() {order}.AsQueryable();
            IList<OrderListDTO> orderDtos = OrderAdapter.OrdersToListDtos(orders);
            Assert.AreEqual<int>(1, orderDtos.Count());

            OrderListDTO dto = orderDtos.First();
            Assert.AreEqual<int>(order.OrderId, dto.Id);
            Assert.AreEqual<int>((int) order.OrderStatus, (int) dto.OrderStatus);
            Assert.AreEqual<DateTime?>(order.OrderDate, dto.OrderDate);
            Assert.AreEqual<DateTime?>(order.ShippedDate, dto.ShippedDate);
            Assert.AreEqual<string>(order.Customer.ToString(), dto.CustomerName);

            Assert.AreEqual(true, dto.IsValid);
        }
        public void TestCustomersToDtos()
        {
            Customer customer = new Customer() {CustomerId = 1, Name = "FakeUserName", FirstName = "FakeFirstName", Version = 0};
            Order order1 = new Order() {OrderId = 1, OrderStatus = OrderStatus.Draft};
            Order order2 = new Order() {OrderId = 2, OrderStatus = OrderStatus.Ordered};
            customer.Orders = new List<Order>() {order1, order2}.AsQueryable();
            Assert.AreEqual(true, customer.IsValid);

            IQueryable<Customer> customers = new List<Customer>() {customer}.AsQueryable();
            IList<CustomerListDTO> customerDtos = CustomerAdapter.CustomersToDtos(customers);
            Assert.AreEqual<int>(1, customerDtos.Count());

            CustomerListDTO dto = customerDtos.First();
            Assert.AreEqual<int>(customer.CustomerId, dto.Id);
            Assert.AreEqual<string>(customer.Name, dto.Name);
            Assert.AreEqual<string>(customer.FirstName, dto.FirstName);
            Assert.AreEqual<int>(2, dto.NumberOfTotalOrders);
            Assert.AreEqual<int>(1, dto.NumberOfOpenOrders);
            Assert.AreEqual(true, dto.IsValid);
        }
        public void TestOrderToDto()
        {
            Customer customer = new Customer() {CustomerId = 1, Name = "FakeUserName", FirstName = "FakeFirstName", Version = 0};
            Order order = new Order() {OrderId = 1, OrderStatus = OrderStatus.Ordered, OrderDate = DateTime.Now, ShippedDate = null, Customer = customer, Version = 0};

            OrderDetail detail = new OrderDetail() {OrderDetailId = 1, Order = order, QuantityInUnits = 123, UnitPrice = 213.43m, Version = 0};
            Product product = new Product() {ProductId = 123, Name = "FakeProductName", Category = "FakeCategory", QuantityPerUnit = 213, ListUnitPrice = 123, Version = 0};
            detail.Product = product;
            order.OrderDetails = new List<OrderDetail>() {detail}.AsQueryable();

            Assert.AreEqual(true, order.IsValid);
            Assert.AreEqual(true, detail.IsValid);

            OrderDTO dto = OrderAdapter.OrderToDto(order);
            Assert.AreEqual<int>(order.OrderId, dto.Id);
            Assert.AreEqual<int>((int) order.OrderStatus, (int) dto.OrderStatus);
            Assert.AreEqual<DateTime?>(order.OrderDate, dto.OrderDate);
            Assert.AreEqual<DateTime?>(order.ShippedDate, dto.ShippedDate);
            Assert.AreEqual<int>(order.Customer.CustomerId, dto.CustomerId);
            Assert.AreEqual<string>(order.Customer.ToString(), dto.CustomerName);
            Assert.AreEqual(order.Version, dto.Version);

            Assert.AreEqual<int>(1, dto.Details.Count());
            OrderDetailDTO dtodetail = dto.Details.First();

            Assert.AreEqual<int>(detail.OrderDetailId, dtodetail.Id);
            Assert.AreEqual<double>(detail.QuantityInUnits, dtodetail.QuantityInUnits);
            Assert.AreEqual<decimal>(detail.UnitPrice, dtodetail.UnitPrice);
            Assert.AreEqual(detail.Version, dtodetail.Version);

            Assert.AreEqual<int>(detail.Product.ProductId, dtodetail.ProductId);
            Assert.AreEqual<string>(detail.Product.Name, dtodetail.ProductName);

            Assert.AreEqual(true, dto.IsValid);
            Assert.AreEqual(true, dtodetail.IsValid);
        }
Example #13
0
 public void SetUp()
 {
     customer = new Customer();
 }
Example #14
0
 public void ValidationFails()
 {
     customer = new Customer();
     Assert.IsFalse(customer.IsValid, "Should be invalid");
 }
Example #15
0
 public void Build()
 {
     customer = new Customer();
     Helper.AssertEmptiness(customer, "CustomerId", "Name", "FirstName", "Orders", "Addresses");
 }
Example #16
0
 public void TearDown()
 {
     customer = null;
 }
        public void TestStoreCustomer()
        {
            int customerId = 123;
            CustomerBusinessComponent service = new CustomerBusinessComponent(this.context);
            Customer customer = new Customer() {CustomerId = customerId};
            List<ChangeItem> changeItems = new List<ChangeItem>
                                               {
                                                   new ChangeItem(ChangeType.ChildInsert, new Address()),
                                                   new ChangeItem(ChangeType.ChildUpate, new Address()),
                                                   new ChangeItem(ChangeType.ChildDelete, new Address())
                                               };

            Expect.Once.On(context).Method("SaveCustomer").Will(Return.Value(customerId));
            Expect.Once.On(context).Method("SaveAddress").Will(Return.Value(1));
            Expect.Once.On(context).Method("SaveAddress").Will(Return.Value(1));
            Expect.Once.On(context).Method("DeleteAddress");
            int resultCustomerId = service.StoreCustomer(customer, changeItems);
            Assert.AreEqual<int>(customerId, resultCustomerId);

            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }