public void Controller_AvatarSelectShop_Edit_Data_Valid_Position_Pants_Should_Pass() { // Arrange var controller = new AvatarSelectController(); var data = new AvatarItemInputModel { StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id, ItemId = DataSourceBackend.Instance.AvatarItemBackend.GetDefaultAvatarItemFullItem(AvatarItemCategoryEnum.Pants).Id, Position = AvatarItemCategoryEnum.Pants }; // Get the Student Record var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId); var expect = myStudent.AvatarComposite.PantsId; // Act ViewResult result = controller.Edit(data) as ViewResult; var myStudent2 = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual(expect, myStudent2.AvatarComposite.PantsId, TestContext.TestName); }
public void Models_AvatarItemInput_Instantiate_Get_Set_Should_Pass() { // Arange var expect = new AvatarItemInputModel { ItemId = "item", Position = AvatarItemCategoryEnum.Accessory, StudentId = "student" }; // Act var result = new AvatarItemInputModel { ItemId = expect.ItemId, Position = expect.Position, StudentId = expect.StudentId }; // 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); }
public void Models_AvatarItemInput_Instantiate_Should_Pass() { // Arange // Act var result = new AvatarItemInputModel(); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.IsNotNull(result, TestContext.TestName); }
public void Controller_AvatarSelectShop_Edit_Data_Invalid_Should_Fail() { // Arrange var controller = new AvatarSelectController(); AvatarItemInputModel data = new AvatarItemInputModel(); data = null; // Act var result = (RedirectToRouteResult)controller.Edit(data); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName); }
public void Controller_AvatarSelectShop_Edit_Post_ModelIsInvalid_Should_Pass() { // Arrange var controller = new AvatarSelectController(); AvatarItemInputModel data = new AvatarItemInputModel(); // Make ModelState Invalid controller.ModelState.AddModelError("test", "test"); // Act ViewResult result = controller.Edit(data) as ViewResult; // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual(controller.ModelState.IsValid, false, TestContext.TestName); }
public void Controller_AvatarSelectShop_Edit_Data_Invalid_ItemId_Bogus_Should_Fail() { // Arrange var controller = new AvatarSelectController(); var data = new AvatarItemInputModel { StudentId = DataSourceBackend.Instance.StudentBackend.GetDefault().Id, ItemId = "bogus" }; // Act var result = (RedirectToRouteResult)controller.Edit(data); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual("Index", result.RouteValues["action"], TestContext.TestName); }
public ActionResult Edit([Bind(Include = "StudentId," + "ItemId," + "Position," + "")] AvatarItemInputModel data) { if (!ModelState.IsValid) { // Send back for edit, with Error Message return(RedirectToAction("Index", "AvatarSelect", new { id = data.StudentId })); } if (data == null) { return(RedirectToAction("Error", "Home")); } if (string.IsNullOrEmpty(data.StudentId)) { // Send back for Edit return(RedirectToAction("Index", "AvatarSelect", new { id = data.StudentId })); } if (string.IsNullOrEmpty(data.ItemId)) { // Send back for Edit return(RedirectToAction("Index", "AvatarSelect", new { id = data.StudentId })); } // Get Student var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId); if (myStudent == null) { // Send back for Edit return(RedirectToAction("Index", "AvatarSelect", new { id = data.StudentId })); } // Get Item var myItem = DataSourceBackend.Instance.AvatarItemBackend.Read(data.ItemId); if (myItem == null) { // Send back for Edit return(RedirectToAction("Index", "AvatarSelect", new { id = data.StudentId })); } var AvatarBase = "/Content/Avatar/"; switch (data.Position) { case AvatarItemCategoryEnum.Accessory: myStudent.AvatarComposite.AccessoryId = myItem.Id; myStudent.AvatarComposite.AccessoryUri = myItem.Uri; myStudent.AvatarComposite.AvatarAccessoryUri = AvatarBase + myItem.Uri; break; case AvatarItemCategoryEnum.Cheeks: myStudent.AvatarComposite.CheeksId = myItem.Id; myStudent.AvatarComposite.CheeksUri = myItem.Uri; myStudent.AvatarComposite.AvatarCheeksUri = AvatarBase + myItem.Uri; break; case AvatarItemCategoryEnum.Expression: myStudent.AvatarComposite.ExpressionId = myItem.Id; myStudent.AvatarComposite.ExpressionUri = myItem.Uri; myStudent.AvatarComposite.AvatarExpressionUri = AvatarBase + myItem.Uri; break; case AvatarItemCategoryEnum.HairBack: myStudent.AvatarComposite.HairBackId = myItem.Id; myStudent.AvatarComposite.HairBackUri = myItem.Uri; myStudent.AvatarComposite.AvatarHairBackUri = AvatarBase + myItem.Uri; break; case AvatarItemCategoryEnum.HairFront: myStudent.AvatarComposite.HairFrontId = myItem.Id; myStudent.AvatarComposite.HairFrontUri = myItem.Uri; myStudent.AvatarComposite.AvatarHairFrontUri = AvatarBase + myItem.Uri; break; case AvatarItemCategoryEnum.Head: myStudent.AvatarComposite.HeadId = myItem.Id; myStudent.AvatarComposite.HeadUri = myItem.Uri; myStudent.AvatarComposite.AvatarHeadUri = AvatarBase + myItem.Uri; break; case AvatarItemCategoryEnum.Pants: myStudent.AvatarComposite.PantsId = myItem.Id; myStudent.AvatarComposite.PantsUri = myItem.Uri; myStudent.AvatarComposite.AvatarPantsUri = AvatarBase + myItem.Uri; break; case AvatarItemCategoryEnum.ShirtFull: myStudent.AvatarComposite.ShirtFullId = myItem.Id; myStudent.AvatarComposite.ShirtFullUri = myItem.Uri + ".png"; myStudent.AvatarComposite.AvatarShirtFullUri = AvatarBase + myItem.Uri; myStudent.AvatarComposite.ShirtShortId = myItem.Id; var temp = myItem.Uri.Split('.'); myStudent.AvatarComposite.ShirtShortUri = temp[0] + "_short.png";; myStudent.AvatarComposite.AvatarShirtShortUri = AvatarBase + myStudent.AvatarComposite.ShirtShortUri; break; } // Update Student DataSourceBackend.Instance.StudentBackend.Update(myStudent); return(RedirectToAction("Index", "AvatarSelect", new { id = data.StudentId })); }