protected ActionResult DisplayDetails(ProductDTO item)
        {
            var vm = GetViewModelFromTempData<ProductViewModel>() ?? new ProductViewModel();
            vm.DisplayName = Strings.ProductViewModel_DisplayName;
            vm.Model = item;

            // Finish Action
            StoreViewModelToTempData(vm);
            return View(vm);
        }
        public void TestProductViewModel()
        {
            ProductViewModel productViewModel = new ProductViewModel();
            productViewModel.Service = serviceFacade;
            ProductDTO product = new ProductDTO() {Id = 1};
            IList<ProductDTO> products = new List<ProductDTO>() {product};
            Expect.Once.On(serviceFacade).Method("GetAllProducts").Will(Return.Value(products));
            productViewModel.LoadCommand.Command.Execute(null);

            Assert.AreEqual<int>(1, productViewModel.Items.Count);
            Assert.AreEqual(product, productViewModel.SelectedItem);
            Assert.AreEqual(Strings.ProductViewModel_DisplayName, productViewModel.DisplayName);
        }
        public void TestDtoToProduct()
        {
            ProductDTO dto = new ProductDTO() { Id = 1, Name = "FakeProduct", Category = "FakeCategory", ListUnitPrice = (decimal)123.21, QuantityPerUnit = 100.2, ProductNumber = "FakeProductNumber", UnitsOnStock = 10, Version = 0 };
            Assert.AreEqual(true, dto.IsValid);

            Product product = ProductAdapter.DtoToProduct(dto);
            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);
        }
 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;
 }
        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;
        }
 // GET: Product/Create
 public ActionResult Create()
 {
     ProductDTO item = new ProductDTO();
     return DisplayDetails(item);
 }
 public void TestStoreProduct()
 {
     ProductDTO product = new ProductDTO();
     product.Id = 123;
     StoreProductResponse response = new StoreProductResponse();
     response.Id = product.Id;
     Expect.Once.On(service).Method("StoreProduct").Will(Return.Value(response));
     serviceFacade.StoreProduct(product);
 }
Beispiel #8
0
 public void StoreProduct(ProductDTO product)
 {
     try
     {
         StoreProductRequest request = new StoreProductRequest();
         request.Product = product;
         StoreProductResponse response = Service.StoreProduct(request);
         product.Id = response.Id;
     }
     catch (Exception ex)
     {
         if (ExceptionPolicy.HandleException(ex, "PL Policy")) throw;
     }
 }
        public void TestProductDetailModel()
        {
            ProductDTO dto = new ProductDTO() {Id = 1, Name = "FakeProduct", Category = "FakeCategory", ListUnitPrice = 123.21m, QuantityPerUnit = 100.2, Version = 1};

            ProductDetailViewModel productDetailViewModel = new ProductDetailViewModel(dto, false);
            productDetailViewModel.Service = serviceFacade;

            Expect.Once.On(serviceFacade).Method("StoreProduct").With(dto).Will(Return.Value(1));
            productDetailViewModel.SaveCommand.Command.Execute(null);

            Assert.AreEqual(dto, productDetailViewModel.Model);
            Assert.AreEqual(Strings.ProductDetailViewModel_DisplayName, productDetailViewModel.DisplayName);
        }