public void TestGetProductById()
        {
            ProductBusinessComponent service = new ProductBusinessComponent(this.context);
            Product product = new Product() {ProductId = 123};

            Expect.Once.On(context).Method("GetById").Will(Return.Value(product));
            Product resultProduct = service.GetProductById(123);
            Assert.AreEqual<decimal>(product.ProductId, resultProduct.ProductId);
            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
        public int StoreProduct(Product product)
        {
            int productId = default(int);
            using (TransactionScope transaction = new TransactionScope())
            {
                productId = rep.SaveProduct(product);
                transaction.Complete();
            }

            return productId;
        }
        public void TestStoreProduct()
        {
            int productId = 123;
            ProductBusinessComponent service = new ProductBusinessComponent(this.context);
            Product product = new Product() {ProductId = 456, Name = "FakeProduct", Category = "FakeCategory"};

            Expect.Once.On(context).Method("SaveProduct").Will(Return.Value(productId));
            int resultProductId = service.StoreProduct(product);
            Assert.AreEqual<int>(productId, resultProductId);

            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
        public void TestProductToDto()
        {
            Product product = new Product() { ProductId = 1, Name = "FakeProduct", Category = "FakeCategory", ListUnitPrice = (decimal)123.21, QuantityPerUnit = 100.2, ProductNumber = "FakeProductNumber", UnitsOnStock = 10, Version = 0 };
            Assert.AreEqual(true, product.IsValid);

            ProductDTO dto = ProductAdapter.ProductToDto(product);
            Assert.AreEqual<int>(product.ProductId, dto.Id);
            Assert.AreEqual<string>(product.Name, dto.Name);
            Assert.AreEqual<string>(product.Category, dto.Category);
            Assert.AreEqual(product.Version, dto.Version);
            Assert.AreEqual<double>(product.QuantityPerUnit, dto.QuantityPerUnit);
            Assert.AreEqual<decimal>(product.ListUnitPrice, dto.ListUnitPrice);
            Assert.AreEqual(true, dto.IsValid);
        }
예제 #5
0
 public void Validation()
 {
     product = new Product()
                   {
                       ProductId = 1,
                       Category = "FakeCategory",
                       QuantityPerUnit = 100.2,
                       Name = "FakeProductName",
                       ListUnitPrice = 200.45m,
                       ProductNumber = "FakeProductNumber",
                       UnitsOnStock = 100,
                       Version = 0
                   };
     Assert.IsTrue(product.IsValid, "Should be valid");
 }
예제 #6
0
 public static Product DtoToProduct(ProductDTO dto)
 {
     Product product = new Product()
                           {
                               ProductId = dto.Id,
                               ProductNumber = dto.ProductNumber,
                               Name = dto.Name,
                               Category = dto.Category,
                               QuantityPerUnit = dto.QuantityPerUnit,
                               ListUnitPrice = dto.ListUnitPrice,
                               UnitsOnStock = dto.UnitsOnStock,
                               Version = dto.Version
                           };
     ValidationHelper.Validate(product);
     return product;
 }
예제 #7
0
        public static ProductDTO ProductToDto(Product p)
        {
            ProductDTO dto = new ProductDTO()
                                 {
                                     Id = p.ProductId,
                                     ProductNumber = p.ProductNumber,
                                     Name = p.Name,
                                     Category = p.Category,
                                     QuantityPerUnit = p.QuantityPerUnit,
                                     ListUnitPrice = p.ListUnitPrice,
                                     UnitsOnStock = p.UnitsOnStock,
                                     Version = p.Version
                                 };

            return dto;
        }
        public void TestProductsToDtos()
        {
            Product product = new Product() {ProductId = 1, Name = "FakeProduct", Category = "FakeCategory", ListUnitPrice = (decimal) 123.21, QuantityPerUnit = 100.2, ProductNumber = "FakeProductNumber", UnitsOnStock = 10, Version = 0};
            Assert.AreEqual(true, product.IsValid);

            IQueryable<Product> products = new List<Product>() {product}.AsQueryable();
            IList<ProductDTO> productDtos = ProductAdapter.ProductsToDtos(products);
            Assert.AreEqual<int>(1, productDtos.Count());

            ProductDTO dto = productDtos.First();
            Assert.AreEqual<int>(product.ProductId, dto.Id);
            Assert.AreEqual<string>(product.Name, dto.Name);
            Assert.AreEqual<string>(product.Category, dto.Category);
            Assert.AreEqual<double>(product.QuantityPerUnit, dto.QuantityPerUnit);
            Assert.AreEqual<decimal>(product.ListUnitPrice, dto.ListUnitPrice);
            Assert.AreEqual(true, dto.IsValid);
        }
        public void TestGetProductByCriteria()
        {
            ProductBusinessComponent service = new ProductBusinessComponent(this.context);
            Product product = new Product() {ProductId = 456, Name = "FakeProduct", Category = "FakeCategory"};
            IList<Product> products = new List<Product>();
            products.Add(product);

            foreach (ProductSearchType type in Enum.GetValues(typeof (ProductSearchType)))
            {
                Expect.Once.On(context).Method("GetAll").Will(Return.Value(products.AsQueryable()));
                IQueryable<Product> resultProducts = service.GetProductsByCriteria(type, "FakeCategory", "FakeProduct");
                Assert.AreEqual<decimal>(1, resultProducts.Count());
                Assert.AreEqual<decimal>(product.ProductId, resultProducts.First().ProductId);
            }

            mockBuilder.VerifyAllExpectationsHaveBeenMet();
        }
예제 #10
0
        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);
        }
예제 #11
0
 public void ValidationFails()
 {
     product = new Product();
     Assert.IsFalse(product.IsValid, "Should be invalid");
 }
예제 #12
0
 public void Build()
 {
     product = new Product();
     Helper.AssertEmptiness(product, "ProductId", "Name", "Category", "ListUnitPrice", "QuantityPerUnit");
 }
예제 #13
0
 public void TearDown()
 {
     product = null;
 }
예제 #14
0
 public void SetUp()
 {
     product = new Product();
 }