当前位置: 首页>>代码示例>>C#>>正文


C# Product.SetIdTo方法代码示例

本文整理汇总了C#中Product.SetIdTo方法的典型用法代码示例。如果您正苦于以下问题:C# Product.SetIdTo方法的具体用法?C# Product.SetIdTo怎么用?C# Product.SetIdTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Product的用法示例。


在下文中一共展示了Product.SetIdTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Handle_Changes_All_Product_Categories

        public void Handle_Changes_All_Product_Categories()
        {
            //Arrange
            const int catId = 3;
            var category = new Category {Name = "sharp"};
            category.SetIdTo(catId);
            var productIds = new List<int> { 2, 3, 4 };
            var product1 = new Product { Category = new Category() };
            product1.SetIdTo(2);
            var product2 = new Product { Category = new Category() };
            product2.SetIdTo(3);
            var product3 = new Product { Category = new Category() };
            product3.SetIdTo(4);
            _categoryTasks.Expect(x => x.Get(catId)).Return(category);
            _productTasks.Expect(x => x.Get(2)).Return(product1);
            _productTasks.Expect(x => x.Get(3)).Return(product2);
            _productTasks.Expect(x => x.Get(4)).Return(product3);
            _productTasks.Expect(x => x.CreateOrUpdate(Arg<Product>.Matches(y => y.Id == 2 && y.Category.Name == "sharp"))).Return(product1);
            _productTasks.Expect(x => x.CreateOrUpdate(Arg<Product>.Matches(y => y.Id == 3 && y.Category.Name == "sharp"))).Return(product2);
            _productTasks.Expect(x => x.CreateOrUpdate(Arg<Product>.Matches(y => y.Id == 4 && y.Category.Name == "sharp"))).Return(product3);

            //Act
            _handler.Handle(new MassCategoryChangeCommand(catId, productIds));

            //Assert
            _categoryTasks.VerifyAllExpectations();
            _productTasks.VerifyAllExpectations();
        }
开发者ID:nucleoid,项目名称:Template-Project,代码行数:28,代码来源:MassCategoryChangeHandlerTest.cs

示例2: CreateOrUpdate_Does_Not_Set_Created_With_Existing_And_Saves

        public void CreateOrUpdate_Does_Not_Set_Created_With_Existing_And_Saves()
        {
            //Arrange
            var product = new Product();
            product.SetIdTo(2);
            _repository.Expect(x => x.SaveOrUpdate(product));

            //Act
            var updated = _tasks.CreateOrUpdate(product);

            //Assert
            Assert.AreEqual(DateTime.MinValue, updated.Created.Date);
            _repository.VerifyAllExpectations();
        }
开发者ID:nucleoid,项目名称:Template-Project,代码行数:14,代码来源:ProductTasksTest.cs

示例3: Delete_Id_Deletes_Product

        public void Delete_Id_Deletes_Product()
        {
            //Arrange
            const int Id = 4;
            var product = new Product();
            product.SetIdTo(Id);
            _repository.Expect(x => x.Get(Id)).Return(product);
            _repository.Expect(x => x.Delete(product));

            //Act
            _tasks.Delete(Id);

            //Assert
            _repository.VerifyAllExpectations();
        }
开发者ID:nucleoid,项目名称:Template-Project,代码行数:15,代码来源:ProductTasksTest.cs

示例4: Handle_Changes_Does_Not_Change_Category_If_Same

        public void Handle_Changes_Does_Not_Change_Category_If_Same()
        {
            //Arrange
            const int catId = 3;
            var category = new Category {Name = "sharp"};
            category.SetIdTo(catId);
            var productIds = new List<int> { 2 };
            var product1 = new Product {Category = category};
            product1.SetIdTo(2);
            _categoryTasks.Expect(x => x.Get(catId)).Return(category);
            _productTasks.Expect(x => x.Get(2)).Return(product1);
            _productTasks.AssertWasNotCalled(x => x.CreateOrUpdate(Arg<Product>.Is.Anything));

            //Act
            _handler.Handle(new MassCategoryChangeCommand(catId, productIds));

            //Assert
            _categoryTasks.VerifyAllExpectations();
            _productTasks.VerifyAllExpectations();
        }
开发者ID:nucleoid,项目名称:Template-Project,代码行数:20,代码来源:MassCategoryChangeHandlerTest.cs

示例5: Edit_Validates_Bad_Model_And_Forwards_To_Edit

        public void Edit_Validates_Bad_Model_And_Forwards_To_Edit()
        {
            //Arrange
            var routeData = new RouteData();
            var httpContext = MockRepository.GenerateStub<HttpContextBase>();
            var controllerContext = MockRepository.GenerateStub<ControllerContext>(httpContext, routeData, _controller);
            _controller.ControllerContext = controllerContext;
            _controller.ValueProvider = new FormCollection().ToValueProvider();
            var product = new Product {Category = new Category()};
            product.SetIdTo(2);
            _categoryTasks.Expect(x => x.GetAll()).Return(new List<Category> { new Category() });
            _captchaTasks.Expect(x => x.Validate(ConfigurationManager.AppSettings["ReCaptchaPrivate"])).Return(true);

            //Act
            var result = _controller.Edit(product) as ViewResult;

            //Assert
            Assert.AreEqual(string.Empty, result.ViewName);
            Assert.IsInstanceOfType<ProductEditViewModel>(result.Model);
            Assert.AreEqual(2, (result.Model as ProductEditViewModel).Product.Id);
            Assert.AreEqual(1, (result.Model as ProductEditViewModel).Categories.Count);
            _categoryTasks.VerifyAllExpectations();
            _captchaTasks.VerifyAllExpectations();
        }
开发者ID:nucleoid,项目名称:Template-Project,代码行数:24,代码来源:ProductsControllerTest.cs

示例6: Edit_Forwards_To_View_With_Product

        public void Edit_Forwards_To_View_With_Product()
        {
            //Arrange
            var product = new Product {Category = new Category()};
            product.SetIdTo(3);
            _productTasks.Expect(x => x.Get(3)).Return(product);
            _categoryTasks.Expect(x => x.GetAll()).Return(new List<Category> {new Category()});

            //Act
            var result = _controller.Edit(3) as ViewResult;

            //Assert
            Assert.AreEqual(string.Empty, result.ViewName);
            Assert.IsInstanceOfType<ProductEditViewModel>(result.Model);
            Assert.AreEqual(3, (result.Model as ProductEditViewModel).Product.Id);
            Assert.AreEqual(1, (result.Model as ProductEditViewModel).Categories.Count);
            _productTasks.VerifyAllExpectations();
        }
开发者ID:nucleoid,项目名称:Template-Project,代码行数:18,代码来源:ProductsControllerTest.cs

示例7: Delete_Deletes_Product_And_Redirects_To_Index

        public void Delete_Deletes_Product_And_Redirects_To_Index()
        {
            //Arrange
            var product = new Product();
            product.SetIdTo(3);
            _productTasks.Expect(x => x.Delete(3));

            //Act
            var result = _controller.Delete(3) as RedirectToRouteResult;

            //Assert
            Assert.AreEqual("Index", result.RouteValues["Action"]);
            _productTasks.VerifyAllExpectations();
        }
开发者ID:nucleoid,项目名称:Template-Project,代码行数:14,代码来源:ProductsControllerTest.cs

示例8: Get_Returns_Product_With_Correct_Id

        public void Get_Returns_Product_With_Correct_Id()
        {
            //Arrange
            const int Id = 4;
            var product = new Product();
            product.SetIdTo(Id);
            _repository.Expect(x => x.Get(Id)).Return(product);

            //Act
            var gotten = _tasks.Get(Id);

            //Assert
            Assert.AreEqual(Id, gotten.Id);
            _repository.VerifyAllExpectations();
        }
开发者ID:nucleoid,项目名称:Template-Project,代码行数:15,代码来源:ProductTasksTest.cs


注:本文中的Product.SetIdTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。