public void Constructor_Sets_Properties() { //Arrange const int catId = 4; var productIds = new List<int> {2, 3, 4}; //Act var command = new MassCategoryChangeCommand(catId, productIds); //Assert Assert.AreEqual(4, command.CategoryId); Assert.AreEqual(3, command.ProductIds.Count()); }
public ActionResult ChangeCategory(FormCollection collection) { var catId = Int32.Parse(collection["category"]); var productIds = new List<int>(); foreach (var key in collection.AllKeys) { int productId; if(Int32.TryParse(key, out productId) && collection[key] != bool.FalseString.ToLowerInvariant()) productIds.Add(productId); } var command = new MassCategoryChangeCommand(catId, productIds); var results = _commandProcessor.Process(command); if (results.Success) return new ContentResult { Content = "Categories successfully changed! Refresh to see the changes.", ContentType = "text/html" }; return new ContentResult { Content = "One or more categories failed to change!", ContentType = "text/html" }; }
public void Handle_Does_Not_Find_A_Product() { //Arrange const int catId = 3; var productIds = new List<int> {2, 3, 4}; _categoryTasks.Expect(x => x.Get(catId)).Return(new Category()); _productTasks.Expect(x => x.Get(Arg<int>.Is.Anything)).Repeat.Once().Return(null); var command = new MassCategoryChangeCommand(catId, productIds); //Act var result = _handler.Handle(command); //Assert Assert.IsFalse(result.Success); _categoryTasks.VerifyAllExpectations(); _productTasks.VerifyAllExpectations(); }