public void Call_ComprehensiveTest() { CallModel cmodel = new CallModel(); EmployeeModel emodel = new EmployeeModel(); ProblemModel pmodel = new ProblemModel(); Calls call = new Calls(); call.DateOpened = DateTime.Now; //call.DateClosed = null; call.OpenStatus = true; call.EmployeeId = emodel.GetByLastname("Park").Id; call.TechId = emodel.GetByLastname("Burner").Id; call.ProblemId = pmodel.GetByDescription("Hard Drive Failure").Id; call.Notes = "Jimin's drive is shot, Burner to fix it"; int newCallId = cmodel.Add(call); output.WriteLine("New Call Generated - Id = " + newCallId); call = cmodel.GetById(newCallId); byte[] oldtimer = call.Timer; output.WriteLine("New Call Retrieved"); call.Notes += "\n Ordered new drive!"; if (cmodel.Update(call) == UpdateStatus.Ok) { output.WriteLine("Call was updated " + call.Notes); } else { output.WriteLine("Call was not updated!"); } call.Timer = oldtimer; call.Notes = "doesn't matter data is stale now"; if (cmodel.Update(call) == UpdateStatus.Stale) { output.WriteLine("Call was not updated due to stale data"); } cmodel = new CallModel(); call = cmodel.GetById(newCallId); if (cmodel.Delete(newCallId) == 1) { output.WriteLine("Call was deleted!"); } else { output.WriteLine("Call was noe deleted"); } Assert.Null(cmodel.GetById(newCallId)); }
public void ComprehensiveModelTestsShouldReturnTrue() { CallModel cmodel = new CallModel(); EmployeeModel emodel = new EmployeeModel(); ProblemModel pmodel = new ProblemModel(); Call call = new Call(); call.DateOpened = DateTime.Now; call.DateClosed = null; call.OpenStatus = true; call.EmployeeId = emodel.GetByLastname("Jarocki").Id; call.TechId = emodel.GetByLastname("Burner").Id; call.ProblemId = pmodel.GetByDescription("Hard Drive Failure").Id; call.Notes = "Kevin's drive is shot, Burner to fix it"; int newCallId = cmodel.Add(call); Console.WriteLine("New Call Generated - Id = " + newCallId); call = cmodel.GetById(newCallId); byte[] oldtimer = call.Timer; Console.WriteLine("New Call Retrieved"); call.Notes += "\n Ordered new RAM!"; if (cmodel.Update(call) == UpdateStatus.Ok) { Console.WriteLine("Call was updated " + call.Notes); } else { Console.WriteLine("Call was not updated!"); } call.Timer = oldtimer; if (cmodel.Update(call) == UpdateStatus.Stale) { Console.WriteLine("Call was not updated due to stale data"); } cmodel = new CallModel(); call = cmodel.GetById(newCallId); if (cmodel.Delete(newCallId) == 1) { Console.WriteLine("call was deleted!"); } else { Console.WriteLine("call was not deleted"); } Assert.IsNull(cmodel.GetById(newCallId)); }
// Update an Employee public int Update() { // UpdatesStatus is set to failed initally until we can check // for data concurrency to make sure the data is not stale UpdateStatus opStatus = UpdateStatus.Failed; try { // Create a new Call object and add the properties // from the object that has called the Add() function Call call = new Call(); call.EmployeeId = EmployeeId; call.ProblemId = ProblemId; call.TechId = TechId; call.DateOpened = DateOpened; call.OpenStatus = OpenStatus; call.DateClosed = DateClosed; call.Notes = Notes; call.Id = Id; call.Timer = Convert.FromBase64String(Timer); // This is where we check for the data concurrency to make sure that data // is not stale opStatus = _model.Update(call); } catch (Exception ex) { Console.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod().Name + " " + ex.Message); throw ex; } return(Convert.ToInt16(opStatus)); }
//Update a call by creating a new call from the traits of the view model object this method is called on. public int Update() { UpdateStatus opStatus = UpdateStatus.Failed; try { Call call = new Call(); call.Id = Id; call.EmployeeId = EmployeeId; call.ProblemId = ProblemId; call.TechId = TechId; call.DateOpened = DateOpened; call.DateClosed = DateClosed; call.OpenStatus = OpenStatus; call.Notes = Notes; call.Timer = Convert.FromBase64String(Timer); //Use the employee model's update method to send changes back to the database opStatus = _model.Update(call); } catch (Exception ex) { Console.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod().Name + " " + ex.Message); throw ex; } return(Convert.ToInt16(opStatus)); }
public int Update() { UpdateStatus operationStatus = UpdateStatus.Failed; try { Calls c = new Calls(); c.Id = Id; c.EmployeeId = EmployeeId; c.ProblemId = ProblemId; c.TechId = TechId; c.DateOpened = DateOpened; c.DateClosed = DateClosed; c.OpenStatus = OpenStatus; c.Notes = Notes; c.Timer = Convert.FromBase64String(Timer); operationStatus = _model.Update(c); } catch (Exception ex) { Console.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod().Name + " " + ex.Message); throw ex; } return(Convert.ToInt16(operationStatus)); }