Пример #1
0
        public void Controller_Shop_EditName_Data_Valid_Should_Pass()
        {
            // Arrange
            DataSourceBackend.Instance.Reset();
            ShopController controller = new ShopController();
            var            data       = new ShopTruckInputModel
            {
                StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id,
                TruckName = DataSourceBackend.Instance.StudentBackend.GetDefault().Truck.TruckName
            };

            // Get the Student Record
            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);
            var expect    = myStudent.Truck.TruckName;

            // select item
            var mySelect = (RedirectToRouteResult)controller.EditName(data);

            // Act
            ViewResult result     = controller.EditName(data) as ViewResult;
            var        myStudent2 = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);

            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.AreEqual(expect, myStudent2.Truck.TruckName, TestContext.TestName);
        }
Пример #2
0
        public void Controller_Shop_EditName_Data_Invalid_Should_Fail()
        {
            // Arrange
            ShopController controller = new ShopController();

            ShopTruckInputModel data = new ShopTruckInputModel();

            data = null;

            // Act
            var result = (RedirectToRouteResult)controller.EditName(data);

            // Assert
            Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName);
        }
Пример #3
0
        public void Controller_Shop_EditName_Post_ModelIsInvalid_Should_Pass()
        {
            // Arrange
            ShopController      controller = new ShopController();
            ShopTruckInputModel data       = new ShopTruckInputModel();

            // Make ModelState Invalid
            controller.ModelState.AddModelError("test", "test");

            // Act
            ViewResult result = controller.EditName(data) as ViewResult;

            // Assert
            Assert.AreEqual(controller.ModelState.IsValid, false, TestContext.TestName);
        }
Пример #4
0
        public void Controller_Shop_EditName_Data_Invalid_TruckNameIsNull_Should_Fail()
        {
            // Arrange
            ShopController controller = new ShopController();

            var data = new ShopTruckInputModel
            {
                StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id,
                TruckName = null
            };

            // Act
            var result = (RedirectToRouteResult)controller.EditName(data);

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"], TestContext.TestName);
        }
Пример #5
0
        public void Controller_Shop_EditName_Data_Invalid_StudentId_Bogus_Should_Fail()
        {
            // Arrange
            ShopController controller = new ShopController();

            var data = new ShopTruckInputModel
            {
                StudentId = "bogus",
                TruckName = "truckName"
            };

            // Act
            var result = (RedirectToRouteResult)controller.EditName(data);

            // Reset
            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"], TestContext.TestName);
        }