public void Build() { Order order = new Order(); Helper.AssertEmptiness(order, "OrderId", "OrderDate", "ShippedDate", "OrderDetails"); Assert.IsInstanceOfType(order.Customer, typeof (UnkownCustomer), "Customer should be of type unknown customer."); Assert.AreEqual(OrderStatus.Draft, order.OrderStatus); }
public static IEnumerable<ChangeItem> GetChangeItems(OrderDTO dto, Order order) { IEnumerable<ChangeItem> changeItems = from c in dto.Changes select new ChangeItem(c.ChangeType, DtoToDetail((OrderDetailDTO) c.Object, order)); return changeItems; }
public void TestGetOrderById() { OrderBusinessComponent service = new OrderBusinessComponent(this.context); Order order = new Order() {OrderId = 123}; Expect.Once.On(context).Method("GetById").Will(Return.Value(order)); Order resultOrder = service.GetOrderById(123); Assert.AreEqual<decimal>(order.OrderId, resultOrder.OrderId); mockBuilder.VerifyAllExpectationsHaveBeenMet(); }
public void Validation() { order = new Order() { OrderId = 1, OrderStatus = OrderStatus.Ordered, OrderDate = DateTime.Now, ShippedDate = null, Version = 0 }; Assert.IsTrue(order.IsValid, "Should be valid"); }
public static Order DtoToOrder(OrderDTO dto) { Order order = new Order() { OrderId = dto.Id, OrderStatus = dto.OrderStatus, OrderDate = dto.OrderDate, ShippedDate = dto.ShippedDate, Customer = new Customer() {CustomerId = dto.CustomerId}, Version = dto.Version }; ValidationHelper.Validate(order); return order; }
private static IList<OrderDetailDTO> OrderDetailsToDtos(Order order) { IQueryable<OrderDetailDTO> orderDetailDTO = from d in order.OrderDetails select new OrderDetailDTO() { Id = d.OrderDetailId, QuantityInUnits = d.QuantityInUnits, UnitPrice = d.UnitPrice, Version = d.Version, ProductId = d.Product.ProductId, ProductName = d.Product.Name, }; return orderDetailDTO.ToList(); }
public static OrderDTO OrderToDto(Order o) { OrderDTO dto = new OrderDTO() { Id = o.OrderId, CustomerName = o.Customer.ToString(), CustomerId = o.Customer.CustomerId, OrderStatus = o.OrderStatus, OrderDate = o.OrderDate, ShippedDate = o.ShippedDate, Version = o.Version, Details = OrderDetailsToDtos(o) }; return dto; }
public void TestGetOrderByCriteria() { OrderBusinessComponent service = new OrderBusinessComponent(this.context); Order order = new Order {OrderId = 456, Customer = new Customer {CustomerId = 1234}}; IList<Order> orders = new List<Order> {order}; foreach (OrderSearchType type in Enum.GetValues(typeof (OrderSearchType))) { Expect.Once.On(context).Method("GetAll").Will(Return.Value(orders.AsQueryable())); IQueryable<Order> resultOrders = service.GetOrdersByCriteria(type, 1234); Assert.AreEqual<decimal>(1, resultOrders.Count()); Assert.AreEqual<decimal>(order.OrderId, resultOrders.First().OrderId); } 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 TestStoreOrder() { int orderId = 123; OrderBusinessComponent service = new OrderBusinessComponent(this.context); Order order = new Order() {OrderId = orderId}; List<ChangeItem> changeItems = new List<ChangeItem> { new ChangeItem(ChangeType.ChildInsert, new OrderDetail()), new ChangeItem(ChangeType.ChildUpate, new OrderDetail()), new ChangeItem(ChangeType.ChildDelete, new OrderDetail()) }; Expect.Once.On(context).Method("SaveOrder").Will(Return.Value(orderId)); Expect.Once.On(context).Method("SaveOrderDetail").Will(Return.Value(1)); Expect.Once.On(context).Method("SaveOrderDetail").Will(Return.Value(1)); Expect.Once.On(context).Method("DeleteOrderDetail"); int resultOrderId = service.StoreOrder(order, changeItems); Assert.AreEqual<int>(orderId, resultOrderId); mockBuilder.VerifyAllExpectationsHaveBeenMet(); }
public int StoreOrder(Order order, IEnumerable<ChangeItem> changeItems) { int orderId = default(int); using (TransactionScope transaction = new TransactionScope()) { orderId = rep.SaveOrder(order); foreach (ChangeItem change in changeItems) { if (change.Object is OrderDetail) { OrderDetail detail = (OrderDetail) change.Object; switch (change.ChangeType) { case ChangeType.ChildInsert: case ChangeType.ChildUpate: rep.SaveOrderDetail(detail, order); break; case ChangeType.ChildDelete: rep.DeleteOrderDetail(detail.OrderDetailId); break; } } } if (ConfigurationHelper.UseMsmqService && order.OrderStatus == OrderStatus.Draft) { OrderToShipDTO dto = new OrderToShipDTO(); dto.Id = order.OrderId; DistributionSystemServiceClient client = new DistributionSystemServiceClient(); client.ShipOrder(dto); order = rep.GetById(order.OrderId); order.OrderStatus = OrderStatus.Ordered; rep.SaveOrder(order, false); } transaction.Complete(); } return orderId; }
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); }
public void ValidationFails() { order = new Order() { OrderId = 1, OrderStatus = OrderStatus.Draft, OrderDate = DateTime.Now, ShippedDate = DateTime.Now, Version = 0 }; Assert.IsFalse(order.IsValid, "Should be invalid"); order = new Order() { OrderId = 1, OrderStatus = OrderStatus.Ordered, OrderDate = null, ShippedDate = DateTime.Now, Version = 0 }; Assert.IsFalse(order.IsValid, "Should be invalid"); Assert.AreEqual<int>(2, order.Validate().Count); order = new Order() { OrderId = 1, OrderStatus = OrderStatus.Shipped, OrderDate = null, ShippedDate = null, Version = 0 }; Assert.IsFalse(order.IsValid, "Should be invalid"); Assert.AreEqual<int>(2, order.Validate().Count); }
private static OrderDetail DtoToDetail(OrderDetailDTO dto, Order order) { OrderDetail detail = new OrderDetail() { OrderDetailId = dto.Id, QuantityInUnits = dto.QuantityInUnits, UnitPrice = dto.UnitPrice, Product = new Product() {ProductId = dto.ProductId}, Version = dto.Version }; detail.Order = order; ValidationHelper.Validate(detail); return detail; }
public void TearDown() { order = null; }
public void SetUp() { order = new Order(); }