Ejemplo n.º 1
0
        public async void Create_InvalidObjectPassed_ReturnsBadRequest()
        {
            // Arrange
            var           controller = new ProductController(service);
            CreateProduct addManager = new CreateProduct();
            var           productAdd = addManager.addInvalid();

            controller.ModelState.AddModelError("IdCategory", "Required");

            // Act
            var badResponse = await controller.Create(productAdd);

            // Assert
            var result = badResponse.Should().BeOfType <BadRequestObjectResult>().Subject;
            //Assert.IsType<BadRequestObjectResult>(badResponse);
        }
Ejemplo n.º 2
0
        public async void Create_WhenAdded_OkResult()
        {
            //Arrange
            var           controller = new ProductController(service);
            CreateProduct addManager = new CreateProduct();
            var           productAdd = addManager.add();
            //find it
            int idnew = 3;

            //Act
            var productAddRq = await controller.Create(productAdd);

            var productRq = await controller.GetProduct(idnew);

            var resultProductRq = productRq.Should().BeOfType <OkObjectResult>().Subject;

            //Assert
            var result = productAddRq.Should().BeOfType <OkResult>().Subject;

            Assert.Equal(idnew, resultProductRq.Value.Should().BeAssignableTo <ProductViewModel>().Subject.IdProduct);
        }
Ejemplo n.º 3
0
        public async void Create_ValidObjectPassed_ReturnedResponseHasCreatedItem()
        {
            // Arrange
            var           controller = new ProductController(service);
            CreateProduct addManager = new CreateProduct();
            var           productAdd = addManager.add();

            //context
            var context = new DbContextDrugStore(dbContextOptions);


            // Act
            var resultOk = await controller.Create(productAdd);

            var records     = db.CountRecords(context);
            var Allproducts = await controller.List();

            // Assert
            var AllresultsList = Allproducts.Should().BeAssignableTo <IEnumerable <ProductViewModel> >().Subject;

            AllresultsList.Should().HaveCount(records);
        }