Beispiel #1
0
        public void Can_Edit_Brand()
        {
            //---Arrange---
            Mock <IRepository> mock = new Mock <IRepository>();

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

            //---Act---
            var brand1 = ((ViewResult)controller.Edit(1)).ViewData.Model as Brands;
            var brand2 = ((ViewResult)controller.Edit(2)).ViewData.Model as Brands;
            var brand3 = ((ViewResult)controller.Edit(3)).ViewData.Model as Brands;

            //---Assert---
            Assert.AreEqual(1, brand1.BrandId);
            Assert.AreEqual(2, brand2.BrandId);
            Assert.AreEqual(3, brand3.BrandId);
        }
Beispiel #2
0
        public void Cannot_Save_Invalid_Changes()
        {
            //---Arrange
            Mock <IRepository> mock = new Mock <IRepository>();

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

            controller.ModelState.AddModelError("error", "error");

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


            //Assert
            mock.Verify(b => b.SaveBrands(It.IsAny <Brands>()), Times.Never());
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Beispiel #3
0
        public void Can_Save_Brand()
        {
            //---Arrange
            Mock <IRepository> mock       = new Mock <IRepository>();
            BrandsController   controller = new BrandsController(mock.Object);
            Brands             brand      = new Brands()
            {
                BrandName = "B2"
            };
            //---Act
            ActionResult result = controller.Edit(brand);

            //---Assert
            mock.Verify(b => b.SaveBrands(brand));
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
Beispiel #4
0
        public void Cannot_Edit_Value()
        {
            //---Arrange---
            Mock <IRepository> mock = new Mock <IRepository>();

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

            //---Act---
            var nonExistentBrand = ((ViewResult)controller.Edit(3)).ViewData.Model as Brands;

            //---Assert---
            Assert.IsNull(nonExistentBrand);
        }
Beispiel #5
0
        public void GetBrands()
        {
            // arrange
            var brands = new List <CarBrand>
            {
                new CarBrand()
                {
                    Id = 1, Name = "Audi"
                },
                new CarBrand()
                {
                    Id = 2, Name = "BMW"
                },
                new CarBrand()
                {
                    Id = 3, Name = "Opel"
                },
                new CarBrand()
                {
                    Id = 4, Name = "Mercedes-Benz"
                }
            }.AsQueryable();

            CarBrand brand = new CarBrand()
            {
                Id = 1, Name = "Test"
            };
            var brandsMock = new Mock <IBrandRepository>();

            brandsMock.Setup(m => m.Update(brand)).Returns(new OperationStatus()
            {
                Status = true
            });

            BrandsController controller = new BrandsController(brandsMock.Object);

            // act
            var result = controller.Edit(brand);

            // Assert
            brandsMock.Verify(m => m.Update(brand));
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }