public void When_adding_a_product_as_a_null_value_it_should_return_a_bad_request_code() { // Arrange var controller = new ProductsController(null, null); // Act var result = controller.Add(null); // Assert result.Should().BeOfType <BadRequestResult>(); }
public void When_adding_a_product__the_model_state_should_be_validated() { // Arrange var controller = new ProductsController(null, null); // Act controller.ModelState.AddModelError("", "Error"); var result = controller.Add(new ProductForPostDto()); // Assert result.Should().BeOfType <BadRequestObjectResult>(); }
public async void CanAddProduct() { var productDTO = new ProductDTO { Name = "Test", Count = 3, Price = 9M }; await _productController.Add(productDTO); _mock.Verify(m => m.Add(productDTO)); }
public void AddProduct_Returns_AddProductForm() { //Arrange var mockRepo = new Mock <IGenericRepository <Product> >(); var mockLogger = new Mock <ILogger <ProductsController> >(); var mockHost = new Mock <IWebHostEnvironment>(); ProductsController controller = new ProductsController(mockLogger.Object, mockHost.Object, mockRepo.Object); string expectedViewName = "Add"; //Act ViewResult result = (ViewResult)controller.Add(); string actualViewName = result.ViewName; //Assert Assert.Equal(expectedViewName, actualViewName); }
public void When_adding_a_new_valid_product_the_new_element_should_be_returned_with_valid_values() { // Arrange var controller = new ProductsController(_logger, _repository); var categoryController = new ProductCategoriesController(_categoryLogger, _productCategoryRepository); var category = ValidDataHelper.GetValidProductCategoryDto(categoryController); var product = A.New <ProductForPostDto>(); product.ProductCategoryId = category.Id; // Act var result = controller.Add(product); var retrievedElement = result.ValidateResponseAndCastTo <ProductDto, CreatedAtRouteResult> ((int)HttpStatusCodes.Created); retrievedElement.Name.Should().Be(product.Name); retrievedElement.Id.Should().NotBe(0); }
public void AddActionMethod_ReturnsAViewResult() { //arrange var unit = new Mock <IUnitOfWork>(); var products = new Mock <IGRepository <Product> >(); var customers = new Mock <IGRepository <Customer> >(); unit.Setup(r => r.ProductRepository).Returns(products.Object); unit.Setup(r => r.CustomerRepository).Returns(customers.Object); var http = new Mock <IHttpContextAccessor>(); var controller = new ProductsController(unit.Object); //act var result = controller.Add(); //assert Assert.IsType <ViewResult>(result); }
public void Add_ValidProduct_ReturnProductWithNewId() { //Arange var newProduct = ProductsFromXML[0]; //Act ProductDTO actual = null; try { var response = pcMock.Add(newProduct); actual = (ProductDTO)((OkObjectResult)response).Value; } catch (InvalidCastException) { } //Assert newProduct.IdProduct = actual.IdProduct; Assert.AreNotEqual(0, actual.IdProduct); }
static void Main(string[] args) { //test TypesController typesController = new TypesController(); typesController.Add(new Types { TypesId = 1, TypesName = "Товар" }); typesController.Add(new Types { TypesId = 2, TypesName = "Услуга" }); typesController.Add(new Types { TypesId = 3, TypesName = "Набор" }); typesController.Add(new Types { TypesId = 4, TypesName = "Комплект" }); SpeciesController speciesController = new SpeciesController(); speciesController.Add(new Species { SpeciesId = 1, SpeciesName = "Продукты", Types = typesController.Get(1) }); speciesController.Add(new Species { SpeciesId = 2, SpeciesName = "МБП", Types = typesController.Get(1) }); speciesController.Add(new Species { SpeciesId = 3, SpeciesName = "МНМА", Types = typesController.Get(1) }); speciesController.Add(new Species { SpeciesId = 4, SpeciesName = "Набор", Types = typesController.Get(1) }); speciesController.Add(new Species { SpeciesId = 5, SpeciesName = "Оборудование", Types = typesController.Get(1) }); speciesController.Add(new Species { SpeciesId = 6, SpeciesName = "Полуфабрикат", Types = typesController.Get(1) }); speciesController.Add(new Species { SpeciesId = 7, SpeciesName = "Продукция", Types = typesController.Get(1) }); speciesController.Add(new Species { SpeciesId = 8, SpeciesName = "Комплект", Types = typesController.Get(4) }); speciesController.Add(new Species { SpeciesId = 9, SpeciesName = "Услуга", Types = typesController.Get(2) }); ProductsController productsController = new ProductsController(); Product product = new Product { ProductId = 1, ProductName = "Картошка", ProductUnit = decimal.Parse("100,6"), Species = speciesController.Get(1) }; productsController.Add(product); Product product1 = new Product { ProductId = 2, ProductName = "Запчасть до авто", ProductUnit = decimal.Parse("100,69"), Species = speciesController.Get(2) }; productsController.Add(product1); Product product2 = new Product { ProductId = 3, ProductName = "Золотое кольцо", ProductUnit = decimal.Parse("100,69896"), Species = speciesController.Get(3) }; productsController.Add(product2); foreach (var prod in productsController.GetAll()) { prod.Display(); } Console.ReadKey(); }
private void PRODUCTS_ADD() { productscontroller.Add(CreateObjectProduct()); EditModeProducts = 0; MessageBox.Show("Se agrego el producto con exito."); }