Ejemplo n.º 1
0
        public void Test5(int id)
        {
            IActionResult result = null;

            Assert.Throws <NullReferenceException>(() =>
            {
                result = controller.Delete(id);
                Assert.NotNull(result);
            });
        }
Ejemplo n.º 2
0
        public async void Task_DeleteBrand_Retun_BadRequestResult()
        {
            var controller = new BrandController(context);
            int?id         = null;
            var data       = await controller.Delete(id);

            Assert.IsType <BadRequestResult>(data);
        }
Ejemplo n.º 3
0
        public async void Task_DeleteBrand_Return_NotFoundResult()
        {
            var controller = new BrandController(context);
            var id         = 10;
            var data       = await controller.Delete(id);

            Assert.IsType <NotFoundResult>(data);
        }
Ejemplo n.º 4
0
        public async void Task_DeleteBrand_Retun_OkResult()
        {
            var controller = new BrandController(context);
            int id         = 6;
            var data       = await controller.Delete(id);

            Assert.IsType <OkObjectResult>(data);
        }
Ejemplo n.º 5
0
        public void Delete([Values(1000961)] int id)
        {
            _controller.Request.Method = HttpMethod.Delete;

            var actual = _controller.Delete(id, 0) as OkNegotiatedContentResult <string>;

            Assert.IsNotNull(actual);
        }
Ejemplo n.º 6
0
        public async Task Delete_ReturnPartialViewAndBrandName_ByPassingBrandId()
        {
            // Arrange
            var brandId = 1;
            var brand   = GetListOfBrands().First(x => x.Id == brandId);

            mockBrandRepo.Setup(x => x.GetByIdAsync(It.IsAny <int?>())).ReturnsAsync(brand);

            mockUOW.Setup(x => x.Repository <Brand>()).Returns(mockBrandRepo.Object);

            var controller = new BrandController(mockUOW.Object);

            // Act
            var result = await controller.Delete(brandId);

            // Assert
            var viewResult = Assert.IsType <PartialViewResult>(result);
            var model      = Assert.IsAssignableFrom <string>(viewResult.ViewData.Model);

            Assert.Equal(brand.Name, model);
        }
Ejemplo n.º 7
0
        public async void CanDeleteBrandById()
        {
            DbContextOptions <NoodleContext> options =
                new DbContextOptionsBuilder <NoodleContext>()
                .UseInMemoryDatabase("CanDeleteBrandById")
                .Options;

            using (NoodleContext context = new NoodleContext(options))
            {
                //arrange
                Brand brand1 = new Brand();
                brand1.Id   = 1;
                brand1.Name = "Number111";

                Brand brand2 = new Brand();
                brand2.Id   = 2;
                brand2.Name = "Number222";

                Brand brand3 = new Brand();
                brand3.Id   = 3;
                brand3.Name = "Number333";

                BrandController bc = new BrandController(context);

                //act
                await context.Brands.AddAsync(brand1);

                await context.Brands.AddAsync(brand2);

                await context.Brands.AddAsync(brand3);

                var findBrand    = context.Brands.Find(1);
                var deletedBrand = bc.Delete(findBrand.Id);

                //assert
                Assert.Equal(2, context.Brands.Count());
            }
        }
Ejemplo n.º 8
0
        public async Task DeletePost_RedirectAndDeleteBrand_ByPassingBrandId()
        {
            // Arrange
            var brandId = 1;
            var brand   = GetListOfBrands().First(x => x.Id == brandId);

            mockBrandRepo.Setup(x => x.GetByIdAsync(It.IsAny <int?>())).ReturnsAsync(brand);
            mockBrandRepo.Setup(x => x.DeleteAsync(It.IsAny <Brand>())).Returns(Task.FromResult(It.IsAny <int>())).Verifiable();

            mockUOW.Setup(x => x.Repository <Brand>()).Returns(mockBrandRepo.Object);

            var controller = new BrandController(mockUOW.Object);

            // Act
            var result = await controller.Delete(brandId, It.IsAny <IFormCollection>());

            // Assert
            var redirectResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectResult.ControllerName);
            Assert.Equal("Index", redirectResult.ActionName);
            mockBrandRepo.Verify();
        }
Ejemplo n.º 9
0
        public void DeleteTestReturn200()
        {
            var result = brandController.Delete(2);

            Assert.IsInstanceOf <NoContentResult>(result);
        }