예제 #1
0
        public void Models_ShopTruckInput_Instantiate_Get_Set_Should_Pass()
        {
            // Arange
            var expect = new ShopTruckInputModel
            {
                ItemId    = "item",
                Position  = FactoryInventoryCategoryEnum.Topper,
                StudentId = "student",
                TruckName = "truckName"
            };

            // Act
            var result = new ShopTruckInputModel
            {
                ItemId    = expect.ItemId,
                Position  = expect.Position,
                StudentId = expect.StudentId,
                TruckName = expect.TruckName
            };

            // Reset
            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);

            Assert.AreEqual(expect.ItemId, result.ItemId, "Item " + TestContext.TestName);
            Assert.AreEqual(expect.Position, result.Position, "Position " + TestContext.TestName);
            Assert.AreEqual(expect.StudentId, result.StudentId, "Student " + TestContext.TestName);
            Assert.AreEqual(expect.TruckName, result.TruckName, "TruckName " + TestContext.TestName);
        }
예제 #2
0
        public void Controller_Shop_Edit_Data_Valid_Position_Wheels_Should_Pass()
        {
            // Arrange
            ShopController controller = new ShopController();
            var            data       = new ShopTruckInputModel
            {
                StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id,
                ItemId    = DataSourceBackend.Instance.FactoryInventoryBackend.GetDefaultTruckFullItem(FactoryInventoryCategoryEnum.Wheels).Id,
                Position  = FactoryInventoryCategoryEnum.Wheels
            };

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

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

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

            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.AreEqual(expect, myStudent2.Truck.Wheels, TestContext.TestName);
        }
예제 #3
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);
        }
예제 #4
0
        public void Models_ShopTruckInputModel_Default_Instantiate_Should_Pass()
        {
            //arrange

            //act
            var result = new ShopTruckInputModel();

            //assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
예제 #5
0
        public void Models_ShopTruckInput_Instantiate_Should_Pass()
        {
            // Arange

            // Act
            var result = new ShopTruckInputModel();

            // Reset
            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
예제 #6
0
        public void Controller_Shop_Edit_Data_Invalid_Should_Fail()
        {
            // Arrange
            ShopController controller = new ShopController();

            ShopTruckInputModel data = new ShopTruckInputModel();

            data = null;

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

            // Assert
            Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName);
        }
예제 #7
0
        public void Controller_Shop_Edit_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.Edit(data) as ViewResult;

            // Assert
            Assert.AreEqual(controller.ModelState.IsValid, false, TestContext.TestName);
        }
예제 #8
0
        public void Controller_Shop_EditName_Data_Invalid_StudentID_Null_Should_Fail()
        {
            // Arrange
            ShopController controller = new ShopController();

            var data = new ShopTruckInputModel
            {
                StudentId = null
            };

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

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"], TestContext.TestName);
        }
예제 #9
0
        public void Controller_Shop_Edit_Data_Invalid_ItemId_Bogus_Should_Fail()
        {
            // Arrange
            ShopController controller = new ShopController();

            var data = new ShopTruckInputModel
            {
                StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id,
                ItemId    = "bogus"
            };

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

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"], TestContext.TestName);
        }
예제 #10
0
        public ActionResult EditName([Bind(Include =
                                               "StudentId," +
                                               "TruckName," +
                                               "")] ShopTruckInputModel data)
        {
            if (!ModelState.IsValid)
            {
                // Send back for edit, with Error Message
                return(RedirectToAction("Index", "Shop", new { id = data.StudentId }));
            }

            if (data == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            if (string.IsNullOrEmpty(data.StudentId))
            {
                // Send back for Edit
                return(RedirectToAction("Index", "Shop", new { id = data.StudentId }));
            }

            if (string.IsNullOrEmpty(data.TruckName))
            {
                // Send back for default
                return(RedirectToAction("Index", "Shop", new { id = data.StudentId }));
            }

            // Get Student
            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);

            if (myStudent == null)
            {
                // Send back for Edit
                return(RedirectToAction("Index", "Shop", new { id = data.StudentId }));
            }

            myStudent.Truck.TruckName = data.TruckName;

            // Update Student
            DataSourceBackend.Instance.StudentBackend.Update(myStudent);

            return(RedirectToAction("Index", "Shop", new { id = data.StudentId }));
        }
예제 #11
0
        public ActionResult Edit([Bind(Include =
                                           "StudentId," +
                                           "ItemId," +
                                           "Position," +
                                           "")] ShopTruckInputModel data)
        {
            if (!ModelState.IsValid)
            {
                // Send back for edit, with Error Message
                return(RedirectToAction("Index", "Shop", new { id = data.StudentId }));
            }

            if (data == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            if (string.IsNullOrEmpty(data.StudentId))
            {
                // Send back for Edit
                return(RedirectToAction("Index", "Shop", new { id = data.StudentId }));
            }

            if (string.IsNullOrEmpty(data.ItemId))
            {
                // Send back for Edit
                return(RedirectToAction("Index", "Shop", new { id = data.StudentId }));
            }


            // Get Student
            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);

            if (myStudent == null)
            {
                // Send back for Edit
                return(RedirectToAction("Index", "Shop", new { id = data.StudentId }));
            }

            // Get Item
            var myItem = DataSourceBackend.Instance.FactoryInventoryBackend.Read(data.ItemId);

            if (myItem == null)
            {
                // Send back for Edit
                return(RedirectToAction("Index", "Shop", new { id = data.StudentId }));
            }

            switch (data.Position)
            {
            case FactoryInventoryCategoryEnum.Truck:
                myStudent.Truck.Truck = myItem.Id;
                break;

            case FactoryInventoryCategoryEnum.Topper:
                myStudent.Truck.Topper = myItem.Id;
                break;

            case FactoryInventoryCategoryEnum.Menu:
                myStudent.Truck.Menu = myItem.Id;
                break;

            case FactoryInventoryCategoryEnum.Sign:
                myStudent.Truck.Sign = myItem.Id;
                break;

            case FactoryInventoryCategoryEnum.Wheels:
                myStudent.Truck.Wheels = myItem.Id;
                break;

            case FactoryInventoryCategoryEnum.Trailer:
                myStudent.Truck.Trailer = myItem.Id;
                break;
            }

            // Update Student
            DataSourceBackend.Instance.StudentBackend.Update(myStudent);

            return(RedirectToAction("Index", "Shop", new { id = data.StudentId }));
        }