public void Build()
 {
     orderDetail = new OrderDetail();
     Helper.AssertEmptiness(orderDetail, "QuantityInUnits", "UnitPrice");
     Assert.IsInstanceOfType(orderDetail.Product, typeof (UnknownProduct), "Should be a unknown product");
     Assert.IsInstanceOfType(orderDetail.Order, typeof (UnknownOrder), "Should be a unknown order");
 }
 public void Validation()
 {
     orderDetail = new OrderDetail()
                       {
                           OrderDetailId = 1,
                           QuantityInUnits = 100,
                           UnitPrice = 200.0m,
                           Version = 0
                       };
     Assert.IsTrue(orderDetail.IsValid, "Should be valid");
 }
        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);
        }
 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 ValidationFails()
 {
     orderDetail = new OrderDetail();
     Assert.IsFalse(orderDetail.IsValid, "Should be invalid");
 }
 public void TearDown()
 {
     orderDetail = null;
 }
 public void SetUp()
 {
     orderDetail = new OrderDetail();
 }