public void GetAgeDescription_InvalidAge() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(-1); Assert.AreEqual("unknown", description, "should be unknown"); }
public void GetAgeDescription_EarlyTwenties() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(20); Assert.AreEqual("Early twenties", description, "should be Early twenties"); description = ranger.GetAgeDescription(24); Assert.AreEqual("Early twenties", description, "should be Early twenties"); }
public void GetAgeDescription_Teenager() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(14); Assert.AreEqual("Teenager", description, "should be Teenager"); description = ranger.GetAgeDescription(19); Assert.AreEqual("Teenager", description, "should be Teenager"); }
public void GetAgeDescription_Child() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(2); Assert.AreEqual("Child", description, "should be Child"); description = ranger.GetAgeDescription(13); Assert.AreEqual("Child", description, "should be Child"); }
public void GetAgeDescription_Vampire() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(199); Assert.AreEqual("Vampire", description, "should be Vampire"); description = ranger.GetAgeDescription(4998); Assert.AreEqual("Vampire", description, "should be Vampire"); }
public void GetAgeDescription_KauriTree() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(4999); Assert.AreEqual("Kauri tree", description, "should be Kauri tree"); description = ranger.GetAgeDescription(2147483647); Assert.AreEqual("Kauri tree", description, "should be Kauri tree"); }
public void GetAgeDescription_VeryOld() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(99); Assert.AreEqual("Very old", description, "should be Very old"); description = ranger.GetAgeDescription(109); Assert.AreEqual("Very old", description, "should be Very old"); }
public void GetAgeDescription_CrazyAncient() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(110); Assert.AreEqual("Crazy ancient", description, "should be Crazy ancient"); description = ranger.GetAgeDescription(198); Assert.AreEqual("Crazy ancient", description, "should be Crazy ancient"); }
public void GetAgeDescription_KindaOld() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(50); Assert.AreEqual("Kinda old", description, "should be Kinda old"); description = ranger.GetAgeDescription(69); Assert.AreEqual("Kinda old", description, "should be Kinda old"); }
public void GetAgeDescription_Old() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(70); Assert.AreEqual("Old", description, "should be Old"); description = ranger.GetAgeDescription(98); Assert.AreEqual("Old", description, "should be Old"); }
public void GetAgeDescription_VeryAdult() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(30); Assert.AreEqual("Very adult", description, "should be Very adult"); description = ranger.GetAgeDescription(49); Assert.AreEqual("Very adult", description, "should be Very adult"); }
public void GetAgeDescription_AlmostThirty() { var ranger = new Models.AgeRanger(TheGroups); var description = ranger.GetAgeDescription(25); Assert.AreEqual("Almost thirty", description, "should be Almost thirty"); description = ranger.GetAgeDescription(29); Assert.AreEqual("Almost thirty", description, "should be Almost thirty"); }
public string Get(long id, out Models.AgeRanger ageRanger) { ageRanger = null; Exception error; DataRow dr = _DB.GetDataRow($"SELECT * FROM Person WHERE Id = {id}", out error); if (error == null) { if (dr != null) { ageRanger = new Models.AgeRanger(dr); } } else { return(error.Message); } return(null); }
public string Save(ref Models.AgeRanger record) { string result = null; try { if (record != null) { result = record.Validate(); if (string.IsNullOrEmpty(result)) { Exception error; IDbCommand cmd = _DB.GetCommand(out error); if (error == null) { int lastAge = record.Age; cmd.Parameters.Add(_DB.CreateParameter("@F1", record.FirstName)); cmd.Parameters.Add(_DB.CreateParameter("@F2", record.LastName)); cmd.Parameters.Add(_DB.CreateParameter("@F3", record.Age)); if (record.ID > 0) { cmd.CommandText = $"UPDATE Person SET FirstName = @F1, LastName = @F2, Age = @F3 WHERE ID = {record.ID}"; if (cmd.ExecuteNonQuery() <= 0) { result = "Fail to update!"; } } else { cmd.Transaction = _DB.BeginTransaction(out error); cmd.CommandText = $"INSERT INTO Person (FirstName, LastName, Age) VALUES (@F1, @F2, @F3)"; int rows = cmd.ExecuteNonQuery(); if (rows == 1) { record.ID = _DB.GetLastInsertID(); } if (record.ID > 0) { cmd.Transaction.Commit(); } else { cmd.Transaction.Rollback(); result = "Fail to insert!"; } } if (string.IsNullOrEmpty(result)) { record.AgeGroup = GetAgeGroup(record.Age); } } else { result = error.Message; } } } else { result = "Fail to save!"; } } catch (Exception ex) { result = ex.Message; } return(result); }
public ApplicationResultRecord(Models.AgeRanger record) { SetSuccess(); Record = record; }