public void Backend_FactoryInventoryBackend_Update_Valid_Data_Should_Pass() { //arrange var test = FactoryInventoryBackend.Instance; var data = new FactoryInventoryModel(); var createResult = test.Create(data); data.Name = "GoodTestName"; data.Description = "Good Test Description"; data.Uri = "GoodTestUri"; data.Tokens = 100; data.Category = FactoryInventoryCategoryEnum.Food; var expect = data; //act var updateResult = test.Update(data); var result = test.Read(data.Id); //reset test.Reset(); //assert Assert.IsNotNull(result, "Updated " + TestContext.TestName); Assert.AreEqual(expect.Name, result.Name, "Name " + TestContext.TestName); Assert.AreEqual(expect.Description, result.Description, "Description " + TestContext.TestName); Assert.AreEqual(expect.Uri, result.Uri, "URI " + TestContext.TestName); Assert.AreEqual(expect.Tokens, result.Tokens, "Tokens " + TestContext.TestName); Assert.AreEqual(expect.Category, result.Category, "Category " + TestContext.TestName); }
public void Backend_GameBackend_CustomerPurchase_invalid_data_Should_Pass() { // arrange var test = GameBackend.Instance; var data = test.GetDefault(); var studentData = new StudentModel(); var student = DataSourceBackend.Instance.StudentBackend.Create(studentData); var item = new FactoryInventoryModel { Id = FactoryInventoryBackend.Instance.GetFirstFactoryInventoryId() }; // act //student.Inventory.Remove(item); student.Inventory.Clear(); DataSourceBackend.Instance.StudentBackend.Update(student); test.CustomerPurchase(student); var message = "No Inventory to Sell"; var elementNumber = student.Truck.TransactionList.Count; var result = student.Truck.TransactionList.ElementAt(0).Name.Equals(message); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.IsTrue(result, TestContext.TestName); Assert.AreEqual(1, elementNumber, TestContext.TestName); }
public void Backend_FactoryInventoryBackend__GetShopTruckItemViewModel_Invalid_Category_Empty_Should_Fail() { // Arrange var test = FactoryInventoryBackend.Instance; var student = DataSourceBackend.Instance.StudentBackend.GetDefault(); var item = DataSourceBackend.Instance.FactoryInventoryBackend.GetDefault(FactoryInventoryCategoryEnum.Truck); // Make a copy of the Item, and add it to Student Inventory and save student var studentItem = new FactoryInventoryModel(item); student.Inventory.Add(studentItem); DataSourceBackend.Instance.StudentBackend.Update(student); // Change inventory category to not match, and Save it item.Category = FactoryInventoryCategoryEnum.Unknown; DataSourceBackend.Instance.FactoryInventoryBackend.Update(item); // Act var result = test.GetShopTruckItemViewModel(student.Id, item.Id); // Reset DataSourceBackend.Instance.Reset(); // Assert Assert.IsNotNull(result, TestContext.TestName); }
public void Models_FactoryInventoryModel_Update_With_Valid_Data_Should_Pass() { // Arrange var expectUri = "uri"; var expectDescription = "Description"; var expectTokens = 1000; var expectQuantities = 2000; var expectCategory = FactoryInventoryCategoryEnum.Topper; var data = new FactoryInventoryModel(); var test = new FactoryInventoryModel { Uri = expectUri, Description = expectDescription, Tokens = expectTokens, Quantities = expectQuantities, Category = expectCategory }; // Act data.Update(test); var result = data; // Assert Assert.AreEqual(expectUri, result.Uri, "Uri " + TestContext.TestName); Assert.AreEqual(expectDescription, result.Description, "Description " + TestContext.TestName); Assert.AreEqual(expectTokens, result.Tokens, "Tokens " + TestContext.TestName); Assert.AreEqual(expectQuantities, result.Quantities, "Quantities " + TestContext.TestName); Assert.AreEqual(expectCategory, result.Category, "Category " + TestContext.TestName); }
public void Models_FactoryInventoryModel_Default_Instantiate_Should_Pass() { // Act var result = new FactoryInventoryModel(); // Assert Assert.IsNotNull(result, TestContext.TestName); }
/// <summary> /// Makes a new AvatarItem /// </summary> /// <param name="data"></param> /// <returns>AvatarItem Passed In</returns> public FactoryInventoryModel Create(FactoryInventoryModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown) { DataList.Add(data); // Add to Storage var myResult = DataSourceBackendTable.Instance.Create <FactoryInventoryModel>(tableName, partitionKey, data.Id, data, dataSourceEnum); return(data); }
/// <summary> /// Update all attributes to be what is passed in /// </summary> /// <param name="data"></param> /// <returns>Null or updated data</returns> public FactoryInventoryModel Update(FactoryInventoryModel data) { if (data == null) { return(null); } var myReturn = DataSource.Update(data); return(myReturn); }
public void Models_FactoryInventoryModel_Instantiate_Valid_Get_Catagory_Should_Pass() { // Arrange var result = new FactoryInventoryModel(); // Act var expect = result.Category; // Assert Assert.AreEqual(expect, result.Category, TestContext.TestName); }
/// <summary> /// This opens up the make a new FactoryInventory screen /// </summary> /// <returns></returns> // GET: FactoryInventory/Create public ActionResult Create() { var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext); if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser)) { return(RedirectToAction("Login", "Admin")); } var myData = new FactoryInventoryModel(); return(View(myData)); }
public void Backend_FactoryInventoryBackend_GetFactoryInventoryUri_Invalid_ID_Should_Fail() { //arrange var data = new FactoryInventoryModel(); var test = FactoryInventoryBackend.Instance; data.Id = "bogus"; //act var result = test.GetFactoryInventoryUri(data.Id); //assert Assert.IsNull(result, TestContext.TestName); }
public void Models_StudentModel_Update_Check_All_Fields_Should_Pass() { // Arrange // Set all the fields for a Student var data = new StudentModel(); var test = new StudentModel { Id = "Id", Name = "Name", Password = "******", Status = StudentStatusEnum.Hold, Tokens = 1000, ExperiencePoints = 1000, EmotionCurrent = EmotionStatusEnum.Happy, AvatarLevel = 10 }; var tempAttendance = new AttendanceModel(); test.Attendance.Add(tempAttendance); var tempInventory = new FactoryInventoryModel(); test.Inventory.Add(tempInventory); test.Truck = new ShopTruckFullModel(); // Act data.Update(test); // Assert // Id should not change... Assert.AreNotEqual(test.Id, data.Id, "Name " + TestContext.TestName); //Check each value Assert.AreEqual(test.Name, data.Name, "Name " + TestContext.TestName); Assert.AreEqual(test.Password, data.Password, "Password " + TestContext.TestName); Assert.AreEqual(test.Status, data.Status, "Status " + TestContext.TestName); Assert.AreEqual(test.Tokens, data.Tokens, "Tokens " + TestContext.TestName); Assert.AreEqual(test.ExperiencePoints, data.ExperiencePoints, "ExperiencePoints " + TestContext.TestName); Assert.AreEqual(test.EmotionCurrent, data.EmotionCurrent, "EmotionCurrent " + TestContext.TestName); Assert.AreEqual(test.AvatarLevel, data.AvatarLevel, "AvatarLevel " + TestContext.TestName); Assert.AreEqual(test.Attendance.Count, data.Attendance.Count, "Attendance " + TestContext.TestName); Assert.AreEqual(test.Inventory.Count, data.Inventory.Count, "Inventory " + TestContext.TestName); Assert.IsNotNull(data.Truck, "Inventory " + TestContext.TestName); }
public void Backend_FactoryInventoryDataSourceMock_Update_Invalid_Data_Shop_Item_Does_Not_Exist_Should_Fail() { // Arrange var backend = FactoryInventoryDataSourceMock.Instance; var expectShopModel = new FactoryInventoryModel(); // Act var result = backend.Update(expectShopModel); //reset backend.Reset(); // Assert Assert.IsNull(result, TestContext.TestName); }
public void Backend_FactoryInventoryBackend_Create_Valid_Data_Should_Pass() { //arrange var test = FactoryInventoryBackend.Instance; var data = new FactoryInventoryModel(); //act var result = test.Create(data); //reset test.Reset(); //assert Assert.IsNotNull(result, TestContext.TestName); Assert.AreEqual(data.Id, result.Id, TestContext.TestName); }
/// <summary> /// Update all attributes to be what is passed in /// </summary> /// <param name="data"></param> /// <returns>Null or updated data</returns> public FactoryInventoryModel Update(FactoryInventoryModel data) { if (data == null) { return(null); } var myReturn = DataSet.Find(n => n.Id == data.Id); if (myReturn == null) { return(null); } myReturn.Update(data); return(myReturn); }
public void Backend_FactoryInventoryBackend_Delete_Valid_Data_Should_Pass() { //arrange var test = FactoryInventoryBackend.Instance; var data = new FactoryInventoryModel(); var createResult = test.Create(data); var expect = true; //act var deleteResult = test.Delete(data.Id); //reset test.Reset(); //assert Assert.AreEqual(expect, deleteResult, TestContext.TestName); }
public void Backend_FactoryInventoryDataSourceTable_Update_Invalid_Data_Shop_Item_Does_Not_Exist_Should_Fail() { // Arrange DataSourceBackend.SetTestingMode(true); var backend = FactoryInventoryDataSourceTable.Instance; var expectShopModel = new FactoryInventoryModel(); // Act var result = backend.Update(expectShopModel); // Reset DataSourceBackend.Instance.Reset(); DataSourceBackend.SetTestingMode(false); // Assert Assert.IsNull(result, TestContext.TestName); }
public FactoryInventoryModel GetDefaultTruckFullItem(FactoryInventoryCategoryEnum category) { var data = new FactoryInventoryModel(); // Return the next item that is NOT the default var TruckSet = Index().Where(m => m.Category == category).ToList(); if (TruckSet.Any()) { var dataDefault = TruckSet.Where(m => m.IsDefault == false).ToList(); if (dataDefault.Any()) { data = dataDefault.FirstOrDefault(); } } return(data); }
public void Models_FactoryInventoryModel_Instantiate_Valid_Should_Pass() { // Arrange var uri = "uri"; var name = "name"; var description = "description"; FactoryInventoryCategoryEnum category = FactoryInventoryCategoryEnum.Food; int tokens = 10; int quantities = 10; bool isLimitSupply = true; var expect = uri; // Act var result = new FactoryInventoryModel(uri, name, description, category, tokens, quantities, isLimitSupply); // Assert Assert.AreEqual(expect, result.Uri, TestContext.TestName); }
public void Models_FactoryInventoryModel_Update_With_Invalid_Data_Null_Should_Fail() { // Arrange var expect = "test"; var data = new FactoryInventoryModel { Id = "test" }; // Act data.Update(null); var result = data.Id; // Assert Assert.AreEqual(expect, result, TestContext.TestName); }
/// <summary> /// Update all attributes to be what is passed in /// </summary> /// <param name="data"></param> /// <returns>Null or updated data</returns> public FactoryInventoryModel Update(FactoryInventoryModel data) { if (data == null) { return(null); } var myReturn = DataList.Find(n => n.Id == data.Id); if (myReturn == null) { return(null); } myReturn.Update(data); // Update Storage var myResult = DataSourceBackendTable.Instance.Create <FactoryInventoryModel>(tableName, partitionKey, data.Id, data); return(data); }
public void Controller_FactoryInventory_Delete_Post_Valid_Should_Return_IndexPage() { // Arrange FactoryInventoryController controller = new FactoryInventoryController(); FactoryInventoryModel data = new FactoryInventoryModel(); var context = CreateMoqSetupForCookie(); controller.ControllerContext = new ControllerContext(context, new RouteData(), controller); // Act var result = (RedirectToRouteResult)controller.Delete(data); var resultFactoryInventoryModel = FactoryInventoryBackend.Instance.Create(data); // Reset FactoryInventoryBackend DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual("Index", result.RouteValues["action"], TestContext.TestName); Assert.AreEqual(data.Description, resultFactoryInventoryModel.Description, TestContext.TestName); }
public void Controller_FactoryInventory_Delete_IDValid_Should_Pass() { // Arrange FactoryInventoryController controller = new FactoryInventoryController(); FactoryInventoryModel data = new FactoryInventoryModel(); string id = Backend.FactoryInventoryBackend.Instance.Create(data).Id; var context = CreateMoqSetupForCookie(); controller.ControllerContext = new ControllerContext(context, new RouteData(), controller); // Act ViewResult result = controller.Delete(id) as ViewResult; var resultFactoryInventoryModel = result.Model as FactoryInventoryModel; // Reset FactoryInventoryBackend DataSourceBackend.Instance.Reset(); // Assert Assert.IsNotNull(resultFactoryInventoryModel, TestContext.TestName); }
public ActionResult Update([Bind(Include = "Id," + "Name," + "Description," + "Uri," + "Tokens," + "Category," + "Quantities," + "IsLimitSupply," + "")] FactoryInventoryModel data) { var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext); if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser)) { return(RedirectToAction("Login", "Admin")); } if (!ModelState.IsValid) { // Send back for edit return(View(data)); } if (data == null) { // Send to error page return(RedirectToAction("Error", "Home")); } if (string.IsNullOrEmpty(data.Id)) { // Send back for Edit return(View(data)); } DataSourceBackend.Instance.FactoryInventoryBackend.Update(data); return(RedirectToAction("Index")); }
public void Controller_FactoryInventory_Delete_Post_ModelIsInvalid_Should_Pass() { // Arrange FactoryInventoryController controller = new FactoryInventoryController(); FactoryInventoryModel data = new FactoryInventoryModel(); // Make ModelState Invalid controller.ModelState.AddModelError("test", "test"); var context = CreateMoqSetupForCookie(); controller.ControllerContext = new ControllerContext(context, new RouteData(), controller); // Act ViewResult result = controller.Delete(data) as ViewResult; // Reset FactoryInventoryBackend DataSourceBackend.Instance.Reset(); // Assert Assert.IsNotNull(result, TestContext.TestName); }
public void Controller_FactoryInventory_Delete_Post_Invalid_IDIsNull_Should_Return_Model() { // Arrange FactoryInventoryController controller = new FactoryInventoryController(); FactoryInventoryModel data = new FactoryInventoryModel { Id = null }; var context = CreateMoqSetupForCookie(); controller.ControllerContext = new ControllerContext(context, new RouteData(), controller); // Act ViewResult result = controller.Delete(data) as ViewResult; var resultFactoryInventoryModel = result.Model as FactoryInventoryModel; // Reset FactoryInventoryBackend DataSourceBackend.Instance.Reset(); // Assert Assert.AreEqual(data.Description, resultFactoryInventoryModel.Description, TestContext.TestName); }
public ActionResult Factory([Bind(Include = "StudentId," + "ItemId," + "")] ShopBuyViewModel data) { if (!ModelState.IsValid) { // Send back for edit, with Error Message return(RedirectToAction("Factory", "Shop", new { id = data.StudentId })); } if (data == null) { // Send to Error Page return(RedirectToAction("Error", "Home")); } if (string.IsNullOrEmpty(data.StudentId)) { // Send back for Edit return(RedirectToAction("Factory", "Shop", new { id = data.StudentId })); } // Temp hold the Student Id for the Nav, until the Nav can call for Identity. ViewBag.StudentId = data.StudentId; if (string.IsNullOrEmpty(data.ItemId)) { // Send back for Edit return(RedirectToAction("Factory", "Shop", new { id = data.StudentId })); } // Get Student var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.StudentId); if (myStudent == null) { // Send back for Edit return(RedirectToAction("Factory", "Shop", new { id = data.StudentId })); } // Get Item var item = DataSourceBackend.Instance.FactoryInventoryBackend.Read(data.ItemId); var myItem = new FactoryInventoryModel(item); if (myItem == null) { // Send back for Edit return(RedirectToAction("Factory", "Shop", new { id = data.StudentId })); } // Check the Student Token amount, If not enough, return error if (myStudent.Tokens < myItem.Tokens) { // Not enough money... // Send back for Edit return(RedirectToAction("Factory", "Shop", new { id = data.StudentId })); } // check the quantities of item if (myItem.Quantities < 1) { // Not enough quantity... // Send back for Edit return(RedirectToAction("Factory", "Shop", new { id = data.StudentId })); } // Check the Item amount, If not enough, return error if (myItem.Tokens < 1) { // Not enough money... // Send back for Edit return(RedirectToAction("Factory", "Shop", new { id = data.StudentId })); } // Check to see if the student already has the item. If so, don't buy again, only 1 item per student var ItemAlreadyExists = myStudent.Inventory.Exists(m => m.Name == myItem.Name); if (ItemAlreadyExists) { // Already own it. return(RedirectToAction("Factory", "Shop", new { id = data.StudentId })); } // Reduce the Student Tokens by Item Price myStudent.Tokens -= myItem.Tokens; // Increase the Student Income by Item Price myStudent.Truck.Outcome += myItem.Tokens; // Time to buy ! // Check if the item is limited or not if (myItem.IsLimitSupply == true) { // Reduce the quantities of Item item.Quantities -= 1; } // Add Item to Student Inventory // TODO: Mike, add inventory to Students... myStudent.Inventory.Add(myItem); // Add info into businessList TransactionModel myTransaction = new TransactionModel { Name = "Buy " + myItem.Name + " by spending " + myItem.Tokens, Uri = null }; myStudent.Truck.BusinessList.Add(myTransaction); // Update Student DataSourceBackend.Instance.StudentBackend.Update(myStudent); return(RedirectToAction("Factory", "Shop", new { id = data.StudentId })); }
/// <summary> /// Makes a new FactoryInventory /// </summary> /// <param name="data"></param> /// <returns>FactoryInventory Passed In</returns> public FactoryInventoryModel Create(FactoryInventoryModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown) { DataSet.Add(data); return(data); }
/// <summary> /// Makes a new FactoryInventory /// </summary> /// <param name="data"></param> /// <returns>FactoryInventory Passed In</returns> public FactoryInventoryModel Create(FactoryInventoryModel data) { DataSource.Create(data); return(data); }