public void ComprehensiveVMTests() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; cvm.DateClosed = null; cvm.OpenStatus = true; evm.Lastname = "Jarocki"; evm.GetByLastname(); cvm.EmployeeId = evm.Id; evm.Lastname = "Burner"; evm.GetByLastname(); cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Kevin has bad RAM, Burner to fix it"; cvm.Add(); Console.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; //need id for delete later cvm.GetById(); cvm.Notes += "\n Ordered new RAM!"; if (cvm.Update() == 1) { Console.WriteLine("Call was updated " + cvm.Notes); } else { Console.WriteLine("Call was not updated!"); } cvm.Notes = "Another change to comments that should not work"; if (cvm.Update() == -2) { Console.WriteLine("Call was not updated data was stale"); } cvm = new CallViewModel(); cvm.Id = id; cvm.GetById(); if (cvm.Delete() == 1) { Console.WriteLine("Call was deleted!"); } else { Console.WriteLine("Call was not deleted"); } cvm.GetById(); }
public void ComprehensiveVMTests() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; cvm.DateClosed = null; cvm.OpenStatus = true; evm.Lastname = "Pollock"; evm.GetByLastname(); cvm.EmployeeId = evm.Id; evm.Lastname = "Burner"; evm.GetByLastname(); cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Chris has bad RAM, Burner to fix it"; cvm.Add(); Console.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; // need Id for delete later cvm.GetById(); cvm.Notes += "\n Ordered new RAM!"; if (cvm.Update() == 1) { Console.WriteLine("Call was updated " + cvm.Notes); } else { Console.WriteLine("Call was NOT updated!"); } cvm.Notes = "Another change to comments that should not work."; if (cvm.Update() == -2) { Console.WriteLine("Call was NOT updated, data was stale."); } cvm = new CallViewModel(); // need to reset because of Concurrency cvm.Id = id; cvm.GetById(); if (cvm.Delete() == 1) { Console.WriteLine("Call was deleted!"); } else { Console.WriteLine("Call was NOT deleted!"); } cvm.GetById(); // should throw expected exception }
public void Call_ComprehensiveVMTest() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; cvm.DateClosed = null; cvm.OpenStatus = true; evm.Email = "*****@*****.**"; evm.GetByEmail(); cvm.EmployeeId = evm.Id; evm.Lastname = "*****@*****.**"; evm.GetByEmail(); cvm.EmployeeName = evm.Lastname; cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Sonia has bad RAM, Burner to fix it"; cvm.Add(); output.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; cvm.GetById(); cvm.Notes += "\n Ordered new RAM!"; if (cvm.Update() == 1) { output.WriteLine("Call was updated " + cvm.Notes); } else { output.WriteLine("Call was not updated!"); } cvm.Notes = "Another change to comments that should not work"; if (cvm.Update() == -2) { output.WriteLine("Call was not updated data was stale"); } cvm = new CallViewModel();// need to reset because of concureency error cvm.Id = id; cvm.GetById(); if (cvm.Delete() == 1) { output.WriteLine("Call was deleted"); } else { output.WriteLine("Call was not deleted"); } Exception ex = Assert.Throws <NullReferenceException>(() => cvm.GetById()); // should throw expected exception Assert.Equal("Object reference not set to an instance of an object.", ex.Message); }
public void ComprehensiveVMTestsShouldReturnTrue() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; cvm.DateClosed = null; cvm.OpenStatus = true; evm.Lastname = "Smartypants"; evm.GetByLastname(); cvm.EmployeeId = evm.Id; evm.Lastname = "Burner"; evm.GetByLastname(); cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByProblemDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Bigshot has bad RAM, Burner to fix it"; cvm.Version = 1; cvm.Create(); this.tstCtx.WriteLine("New Call Generated - Id = " + cvm.Id); cvm.GetById(); this.tstCtx.WriteLine("New Call Retrieved"); cvm.Notes = "\n Ordered new RAM!"; if (cvm.Update() == 1) { this.tstCtx.WriteLine("Call was updated " + cvm.Notes); } else { this.tstCtx.WriteLine("Call was not updated"); } if (cvm.Update() == -2) { this.tstCtx.WriteLine("Call was not updated data was stale"); } if (cvm.Delete() == 1) { this.tstCtx.WriteLine("Call was deleted"); } else { this.tstCtx.WriteLine("Call was not deleted"); } cvm.GetById(); // should throw expected exception }
public IHttpActionResult Put(CallViewModel callVm) { try { int retVal = callVm.Update(); switch (retVal) { case 1: return(Ok("Call " + callVm.Id + " updated!")); case -1: return(Ok("Call " + callVm.Id + " not updated!")); case -2: return(Ok("Data is stale for " + callVm.Id + ", Call not updated!")); default: return(Ok("Call " + callVm.Id + " Not updated!")); } } catch (Exception e) { return(BadRequest("Update failed - " + e.Message)); } }
public IActionResult Put([FromBody] CallViewModel viewModel) { try { int retVal = viewModel.Update(); switch (retVal) { case 1: return(Ok(new { msg = "Call " + viewModel.Id + " updated!" })); case -1: return(Ok(new { msg = "Call " + viewModel.Id + " not updated!" })); case -2: return(Ok(new { msg = "Data is stale for " + viewModel.Id + ", Call not updated!" })); default: return(Ok(new { msg = "Call " + viewModel.Id + " not updated!" })); } } catch (Exception ex) { _logger.LogError("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod().Name + " " + ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public IHttpActionResult Put(CallViewModel call) { try { //Use the EmployeeViewModel's Update method to update the employee int retVal = call.Update(); switch (retVal) { case 1: return(Ok("Call updated!")); case -1: return(Ok("Call not updated!")); case -2: return(Ok("Data is stale, call not updated!")); default: return(Ok("Call not updated!")); } } catch (Exception ex) { return(BadRequest("Update Failed - " + ex.Message)); } }
public IHttpActionResult Put(CallViewModel call) { try { int retVal = call.Update(); switch (retVal) { case 1: return(Ok("Ok! Call updated!")); case -1: return(Ok("Call not updated!")); case -2: return(Ok("Data is Stale, Call not updated")); default: return(Ok("Call not updated!")); } } catch (Exception ex) { return(BadRequest("Update Failed - Contact Tech Support")); } }
//accept an object and return a result to represent if the update is successful public IHttpActionResult Put(CallViewModel cal) { try { int retVal = cal.Update(); switch (retVal) { case 1: return(Ok("Call updated!")); case -1: return(Ok("Call not updated")); case -2: return(Ok("Call is stale! Call not updated")); default: return(Ok("Call not updated!")); } } catch (Exception ex) { return(BadRequest("Update failed - " + ex.Message)); } }
// 'PUT' method to be called when the user wants to update an employee that // is already in the database. public IHttpActionResult Put(CallViewModel call) { try { // Retrieves the update status from the EmployeeViewModel, to say whether the update // was good, didn't happen or that the user had stale data which also would not update // the employee information. Then displays a message based on the value returned, saying // whether or not the update happened. int retVal = call.Update(); switch (retVal) { case 1: return(Ok("Call " + call.Id + " updated!")); case -1: return(Ok("Call " + call.Id + " not update!")); case -2: return(Ok("Data is stale for " + call.Id + ", Call not update!")); default: return(Ok("Call " + call.Id + " not update!")); } } catch (Exception ex) { return(BadRequest("update failed - " + ex.Message)); } }
public void Call_ComprehensiveVMTest() { CallViewModel cvm = new CallViewModel(); EmployeeViewModel evm = new EmployeeViewModel(); ProblemViewModel pvm = new ProblemViewModel(); cvm.DateOpened = DateTime.Now; //cvm.DateClosed = null; cvm.OpenStatus = true; evm.Email = "*****@*****.**"; evm.GetByEmail(); cvm.EmployeeId = evm.Id; //evm.Lastname = "Park"; evm.Email = "*****@*****.**"; evm.GetByEmail(); cvm.TechId = evm.Id; pvm.Description = "Memory Upgrade"; pvm.GetByDescription(); cvm.ProblemId = pvm.Id; cvm.Notes = "Jimin has bad RAM, Burner to fix it"; cvm.Add(); output.WriteLine("New Call Generated - Id = " + cvm.Id); int id = cvm.Id; cvm.GetById(); cvm.Notes += "\n Ordered new RAM!!"; if (cvm.Update() == 1) { output.WriteLine("Call was updated " + cvm.Notes); } else { output.WriteLine("Call was not updated!"); } //cvm.Notes = "Another change to comments that should not works"; //if (cvm.Update() == -2) { // output.WriteLine("Call was not updated data was stale"); //} //cvm = new CallViewModel(); //cvm.Id = id; //cvm.GetById(); //if (cvm.Delete() == 1) //{ // output.WriteLine("Call was deleted!"); //} //else { // output.WriteLine("Call was not deleted!"); //} //Exception ex = Assert.Throws<NullReferenceException>(() => cvm.GetById()); //Assert.Equal("Object reference not set to an instance of an object.", ex.Message); }
public IHttpActionResult Put(CallViewModel call) { try { if (call.Update() == 1) { return(Ok("Call updated!")); } else if (call.Update() == -1) { return(Ok("Call not updated!")); } else { return(Ok("Data is stale, data not updated!")); } } catch (Exception ex) { return(BadRequest("Update failed - " + ex.Message)); } }
public void CallViewModelComprehensiveTestsReturnTrue() { CallViewModel vm = new CallViewModel(); vm.DateOpened = DateTime.Now; vm.OpenStatus = true; vm.EmployeeId = "56464e723dd4df30e88b8b8c"; // Bigshot vm.TechId = "56464e723dd4df30e88b8b92"; //Burner vm.ProblemId = "56464e723dd4df30e88b8b99"; vm.Notes = "Bigshot has bad RAM, Burner to fix it"; vm.Create(); this.testContextInstance.WriteLine("New Call Id == " + vm.Id); vm.GetByID(vm.Id); this.testContextInstance.WriteLine("Call retrieved"); vm.Notes = vm.Notes + "\nOrdered new Ram"; if (vm.Update() == 1) { this.testContextInstance.WriteLine("Call was updated " + vm.Notes); } else { Trace.WriteLine("Call was not updated"); } if (vm.Delete()) { this.testContextInstance.WriteLine("Call was deleted"); } else { this.testContextInstance.WriteLine("Call was not deleted"); } vm.Update(); //should throw MongoException see attribute }