public void Controller_AvatarSelectShop_Select_Data_Invalid_AvatarComposite_Null_Should_Fail() { // Arrange var controller = new AvatarSelectController(); var data = new ShopBuyViewModel { StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id, ItemId = DataSourceBackend.Instance.AvatarItemBackend.GetDefault(AvatarItemCategoryEnum.Accessory).Id }; // Get the Student Record and Add some Tokens to it. var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId); myStudent.AvatarComposite = null; DataSourceBackend.Instance.StudentBackend.Update(myStudent); // Act var result = (RedirectToRouteResult)controller.Select(data); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual("Select", result.RouteValues["action"], TestContext.TestName); }
public void Controller_AvatarSelectShop_Select_Data_InValid_Item_Already_Exists_Should_Fail() { // Arrange var controller = new AvatarSelectController(); var data = new ShopBuyViewModel { StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id, ItemId = DataSourceBackend.Instance.AvatarItemBackend.GetFirstAvatarItemId() }; // 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.AvatarItemBackend.Read(data.ItemId); myInventory.Tokens = 10; DataSourceBackend.Instance.AvatarItemBackend.Update(myInventory); // Buy it one time, this puts the item in the student inventory var myPurchase1 = (RedirectToRouteResult)controller.Select(data); // No Purchase, so tokens stay the same var expect = myStudent.Tokens; var expectCount = myStudent.AvatarInventory.Count(); // Act // Trying to buy the second time will fail var result = (RedirectToRouteResult)controller.Select(data); var myStudent2 = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual("Select", result.RouteValues["action"], TestContext.TestName); Assert.AreEqual(expect, myStudent2.Tokens, TestContext.TestName); Assert.AreEqual(expectCount, myStudent2.AvatarInventory.Count(), TestContext.TestName); }
public void Controller_AvatarSelectShop_Select_Default_Should_Pass() { // Arrange var controller = new AvatarSelectController(); var id = DataSourceBackend.Instance.StudentBackend.GetDefault().Id; // Act ViewResult result = controller.Select(id) as ViewResult; // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.IsNotNull(result, TestContext.TestName); }
public void Controller_AvatarSelectShop_Select_Data_Invalid_Null_Should_Fail() { // Arrange var controller = new AvatarSelectController(); ShopBuyViewModel data; data = null; // Act var result = (RedirectToRouteResult)controller.Select(data); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName); }
public void Controller_AvatarSelectShop_Select_Post_ModelIsInvalid_Should_Pass() { // Arrange var controller = new AvatarSelectController(); var data = new ShopBuyViewModel(); // Make ModelState Invalid controller.ModelState.AddModelError("test", "test"); // Act ViewResult result = controller.Select(data) as ViewResult; // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual(controller.ModelState.IsValid, false, TestContext.TestName); }
public void Controller_AvatarSelectShop_Select_Data_Invalid_ItemId_Bogus_Should_Fail() { // Arrange var controller = new AvatarSelectController(); var data = new ShopBuyViewModel { StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id, ItemId = "bogus" }; // Act var result = (RedirectToRouteResult)controller.Select(data); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual("Select", result.RouteValues["action"], TestContext.TestName); }
public void Controller_AvatarSelectShop_Select_Get_myDataIsNull_ShouldReturnErrorPage() { // Arrange var controller = new AvatarSelectController(); var id = DataSourceBackend.Instance.StudentBackend.GetDefault().Id; // Reset DataSourceBackend DataSourceBackend.Instance.Reset(); DataSourceBackend.SetTestingMode(true); // Act var result = (RedirectToRouteResult)controller.Select(id); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName); Assert.AreEqual("Home", result.RouteValues["controller"], TestContext.TestName); }
public void Controller_AvatarSelectShop_Select_Data_Valid_Limited_Should_Pass() { // Arrange var controller = new AvatarSelectController(); var data = new ShopBuyViewModel { StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id, ItemId = DataSourceBackend.Instance.AvatarItemBackend.GetFirstAvatarItemId() }; // Get the Student Record and Add some Tokens to it. var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId); myStudent.Tokens = 1000; // Clear the Student AvatarInventory, so one can be purchanged. myStudent.AvatarInventory.Clear(); DataSourceBackend.Instance.StudentBackend.Update(myStudent); // Get the Item Record and Set the Token Value var myInventory = DataSourceBackend.Instance.AvatarItemBackend.Read(data.ItemId); myInventory.Tokens = 10; myInventory.IsLimitSupply = true; DataSourceBackend.Instance.AvatarItemBackend.Update(myInventory); var expect = myStudent.Tokens - myInventory.Tokens; // Act ViewResult result = controller.Select(data) as ViewResult; var myStudent2 = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual(expect, myStudent2.Tokens, TestContext.TestName); }
public void Controller_AvatarSelectShop_Select_Data_InValid_Tokens_Less_Than_One_Should_Fail() { // Arrange var controller = new AvatarSelectController(); var data = new ShopBuyViewModel { StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id, ItemId = DataSourceBackend.Instance.AvatarItemBackend.GetFirstAvatarItemId() }; // 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.AvatarItemBackend.Read(data.ItemId); myInventory.Tokens = 0; DataSourceBackend.Instance.AvatarItemBackend.Update(myInventory); // No Purchase, so tokens stay the same var expect = myStudent.Tokens; var expectCount = myStudent.AvatarInventory.Count(); // Act var result = (RedirectToRouteResult)controller.Select(data); var myStudent2 = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual("Select", result.RouteValues["action"], TestContext.TestName); Assert.AreEqual(expect, myStudent2.Tokens, TestContext.TestName); Assert.AreEqual(expectCount, myStudent2.AvatarInventory.Count(), TestContext.TestName); }