예제 #1
0
        public void Controller_Shop_Factory_Data_InValid_Item_Already_Exists_Should_Fail()
        {
            // Arrange
            ShopController controller = new ShopController();

            var data = new ShopBuyViewModel
            {
                StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id,
                ItemId    = DataSourceBackend.Instance.FactoryInventoryBackend.GetFirstFactoryInventoryId()
            };

            // Get the Student Record and Add some Tokens to it.
            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);

            myStudent.Tokens = 1000;
            DataSourceBackend.Instance.StudentBackend.Update(myStudent);

            // Get the Item Record and Set the Token Value
            var myInventory = DataSourceBackend.Instance.FactoryInventoryBackend.Read(data.ItemId);

            myInventory.Tokens = 10;
            DataSourceBackend.Instance.FactoryInventoryBackend.Update(myInventory);

            // Buy it one time, this puts the item in the student inventory
            var myPurchase1 = (RedirectToRouteResult)controller.Factory(data);

            // No Purchase, so tokens stay the same
            var expect      = myStudent.Tokens;
            var expectCount = myStudent.Inventory.Count();

            // Act

            // Trying to buy the second time will fail
            var result = (RedirectToRouteResult)controller.Factory(data);

            var myStudent2 = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);

            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.AreEqual("Factory", result.RouteValues["action"], TestContext.TestName);
            Assert.AreEqual(expect, myStudent2.Tokens, TestContext.TestName);
            Assert.AreEqual(expectCount, myStudent2.Inventory.Count(), TestContext.TestName);
        }
예제 #2
0
        public void Controller_Shop_Factory_Default_Should_Pass()
        {
            // Arrange
            ShopController controller = new ShopController();
            string         id         = DataSourceBackend.Instance.StudentBackend.GetDefault().Id;

            // Act
            ViewResult result = controller.Factory(id) as ViewResult;

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

            ShopBuyViewModel data;

            data = null;

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

            // Assert
            Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName);
        }
예제 #4
0
        public void Controller_Shop_Factory_Post_ModelIsInvalid_Should_Pass()
        {
            // Arrange
            ShopController   controller = new ShopController();
            ShopBuyViewModel data       = new ShopBuyViewModel();

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

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

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

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

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

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

            var data = new ShopBuyViewModel
            {
                StudentId = "studentID",
                ItemId    = null
            };

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

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

            string id = DataSourceBackend.Instance.StudentBackend.GetDefault().Id;

            // Reset DataSourceBackend
            DataSourceBackend.Instance.Reset();

            // Act
            var result = (RedirectToRouteResult)controller.Factory(id);

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

            var data = new ShopBuyViewModel
            {
                StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id
            };
            var ItemList = DataSourceBackend.Instance.FactoryInventoryBackend.Index();

            data.ItemId = ItemList.Find(n => n.IsLimitSupply == true).Id;

            // Get the Item which is limited

            // Get the Student Record and Add some Tokens to it.
            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);

            myStudent.Tokens = 1000;
            DataSourceBackend.Instance.StudentBackend.Update(myStudent);

            // Get the Item Record and Set the Token Value
            var myInventory = DataSourceBackend.Instance.FactoryInventoryBackend.Read(data.ItemId);

            myInventory.Tokens     = 10;
            myInventory.Quantities = 10;
            DataSourceBackend.Instance.FactoryInventoryBackend.Update(myInventory);

            var expect           = myStudent.Tokens - myInventory.Tokens;
            var expectOutcome    = myStudent.Truck.Outcome + myInventory.Tokens;
            var expectQuantities = myInventory.Quantities - 1;

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

            var myStudent2 = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);

            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.AreEqual(expect, myStudent2.Tokens, TestContext.TestName);
            Assert.AreEqual(expectOutcome, myStudent2.Truck.Outcome, TestContext.TestName);
            Assert.AreEqual(expectQuantities, myInventory.Quantities, TestContext.TestName);
            Assert.IsNotNull(myStudent2.Truck.BusinessList, TestContext.TestName);
        }
예제 #9
0
        public void Controller_Shop_Factory_Data_InValid_Tokens_Less_Than_One_Should_Fail()
        {
            // Arrange
            ShopController controller = new ShopController();

            var data = new ShopBuyViewModel
            {
                StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id,
                ItemId    = DataSourceBackend.Instance.FactoryInventoryBackend.GetFirstFactoryInventoryId()
            };

            // Get the Student Record and Add some Tokens to it.
            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);

            myStudent.Tokens = 0;
            DataSourceBackend.Instance.StudentBackend.Update(myStudent);

            // Get the Item Record and Set the Token Value
            var myInventory = DataSourceBackend.Instance.FactoryInventoryBackend.Read(data.ItemId);

            myInventory.Tokens = 0;
            DataSourceBackend.Instance.FactoryInventoryBackend.Update(myInventory);

            // No Purchase, so tokens stay the same
            var expect      = myStudent.Tokens;
            var expectCount = myStudent.Inventory.Count();

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

            var myStudent2 = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);

            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.AreEqual("Factory", result.RouteValues["action"], TestContext.TestName);
            Assert.AreEqual(expect, myStudent2.Tokens, TestContext.TestName);
            Assert.AreEqual(expectCount, myStudent2.Inventory.Count(), TestContext.TestName);
        }
예제 #10
0
        public void Controller_Shop_Factory_Data_Valid_Item_Quantity_Is_Not_Limited_Should_Pass()
        {
            // Arrange
            ShopController controller = new ShopController();

            var data = new ShopBuyViewModel
            {
                StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id,
                ItemId    = DataSourceBackend.Instance.FactoryInventoryBackend.GetFirstFactoryInventoryId()
            };

            // Get the Student Record and Add some Tokens to it.
            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);

            myStudent.Tokens = 1000;
            myStudent.Inventory.Clear();    //Clear inventory
            DataSourceBackend.Instance.StudentBackend.Update(myStudent);

            // Get the Item Record and Set the Token Value
            var myInventory = DataSourceBackend.Instance.FactoryInventoryBackend.Read(data.ItemId);

            myInventory.Tokens = 10;
            DataSourceBackend.Instance.FactoryInventoryBackend.Update(myInventory);

            var expect        = myStudent.Tokens - myInventory.Tokens;
            var expectOutcome = myStudent.Truck.Outcome + myInventory.Tokens;

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

            var myStudent2 = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId);

            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.AreEqual(expect, myStudent2.Tokens, TestContext.TestName);
            Assert.AreEqual(expectOutcome, myStudent2.Truck.Outcome, TestContext.TestName);
            Assert.IsNotNull(myStudent2.Truck.BusinessList, TestContext.TestName);
        }