コード例 #1
0
ファイル: BrandTests.cs プロジェクト: Alba-Sula/DokoMobile
        public void Can_Delete_Brand()
        {
            //---Arrange
            Brands brand = new Brands()
            {
                BrandId = 2, BrandName = "B2"
            };
            Mock <IRepository> mock = new Mock <IRepository>();

            mock.Setup(b => b.Brands).Returns(new Brands[]
            {
                new Brands()
                {
                    BrandId = 1, BrandName = "B1"
                },
                brand
            });
            BrandsController controller = new BrandsController(mock.Object);

            //---Act
            ActionResult result = controller.Delete(brand.BrandId);

            //---Assert
            mock.Verify(b => b.DeleteBrand(brand.BrandId));
        }
コード例 #2
0
        public void Delete_ShouldReturnOk()
        {
            //Arrange
            var mock       = new Mock <IBrandService>();
            var controller = new BrandsController(mock.Object);

            //Act
            mock.Setup(p => p.Delete(1));
            var result = controller.Delete(1) as OkResult;

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkResult));
            Assert.AreEqual(200, result.StatusCode);
        }
コード例 #3
0
        public async Task DeleteShouldReturnsNotFoundWhenDbReturnsNull()
        {
            // Arrange
            var brandId            = 1;
            var adminBrandsService = new Mock <IAdminBrandsService>();

            adminBrandsService
            .Setup(s => s.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(() => null);

            var controller = new BrandsController(adminBrandsService.Object, null);

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

            // Assert
            result.Should().NotBeNull();
            result.As <NotFoundResult>().StatusCode.Should().Be(WebConstants.StatusCodeNotFound);
        }
コード例 #4
0
        protected void grvUser_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            Id = int.Parse(e.CommandArgument.ToString());
            switch (e.CommandName)
            {
            case "Edit":
                DataTable dt = BrandsController.GetByColumn("Id", Id.ToString());
                txtName.Text = dt.Rows[0]["Name"].ToString();
                txtLogo.Text = dt.Rows[0]["Logo"].ToString();
                txtOrd.Text  = dt.Rows[0]["Ord"].ToString();
                txtLang.Text = dt.Rows[0]["Lang"].ToString();

                break;

            case "Delete":
                tbBrandInfo obj = new tbBrandInfo();
                obj.Id = Id;
                BrandsController.Delete(obj);
                _LoadBrand();
                break;
            }
        }
コード例 #5
0
        public async void DeleteBrand_ReturnBrandDeleted(int id)
        {
            // Arrange
            var mockRepo = new Mock <IVehicleCatalogRepository>();

            mockRepo.Setup(repo => repo.GetBrand(id))
            .Returns(Task.FromResult <Brand>(new Brand()
            {
                Id = id, Name = "Brand 1"
            }));
            mockRepo.Setup(repo => repo.SaveAll())
            .Returns(Task.FromResult <bool>(true));
            var mapper     = _dependencyFixture.ServiceProvider.GetService <IMapper>();
            var logger     = Mock.Of <ILogger <BrandsController> >();
            var controller = new BrandsController(mockRepo.Object, mapper, logger);

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

            // Assert
            Assert.IsType <NoContentResult>(result);
        }
コード例 #6
0
        public async Task BrandsController_Delete_Success()
        {
            var createRequest = new BrandCreateRequest {
                Name = "Test brand6"
            };

            var controller   = new BrandsController(_fixture.BrandService);
            var createResult = await controller.Post(createRequest);

            var createResponse = GetResponse <BrandCreateResponse>(createResult);

            Assert.Equal("Test brand6", createResponse.Name);

            var deleteResult = await controller.Delete(createResponse.Id);

            Assert.IsType <OkResult>(deleteResult);

            var getResult = await controller.Get(createResponse.Id);

            var getOkResult = Assert.IsType <OkObjectResult>(getResult);

            Assert.Null(getOkResult.Value);
        }
コード例 #7
0
        public async Task DeleteReturnRedirectWithValidId()
        {
            // Arrange
            string successMessage     = null;
            var    resultBrand        = new Brand();
            var    brandDb            = DataHelper.GetBrand();
            var    adminBrandsService = new Mock <IAdminBrandsService>();

            adminBrandsService
            .Setup(s => s.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(brandDb);

            adminBrandsService
            .Setup(s => s.DeleteAsync(It.IsAny <Brand>()))
            .Callback((Brand model) => { resultBrand = model; })
            .Returns(Task.CompletedTask);

            var tempData = new Mock <ITempDataDictionary>();

            tempData
            .SetupSet(t => t[WebConstants.TempDataSuccessMessageKey] = It.IsAny <string>())
            .Callback((string key, object message) => successMessage = message as string);

            var controller = new BrandsController(adminBrandsService.Object, null);

            controller.TempData = tempData.Object;

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

            // Assert
            successMessage.Should().Be($"Brand {brandDb.Name} successfully deleted.");

            result.Should().BeOfType <RedirectToActionResult>();

            result.As <RedirectToActionResult>().ActionName.Should().Be("Index");
        }
コード例 #8
0
        public void Delete_ReturnsNoContentType_WhenBrandExists()
        {
            var result = brandController.Delete(existedBrandId);

            Assert.IsInstanceOf(typeof(NoContentResult), result);
        }