public void t_Conditions_Save_Insert() { SiteCondition Conditions = new SiteCondition() { Id = TestHelper.TestGuid1, SiteVisitId = TestHelper.TestParentGuid, Sky = 3, Temperature = new Business.DataTypes.Temperature() { Value = 54, Units = "C" }, Wind = 0 }; ConditionsMapper.Insert(Conditions); using (IbaUnitTestEntities iba = new IbaUnitTestEntities()) { var ConditionsQuery = from Conditionss in iba.SiteCondition_ado select Conditionss; Assert.IsNotNull(ConditionsQuery, "Query result is null"); Assert.AreEqual(1, ConditionsQuery.Count(), "Wrong number of results in query"); SiteCondition_ado adoConditions = ConditionsQuery.First(); validateObjectEquality(Conditions, adoConditions); } }
public void t_Conditions_Select_BySiteVisitId() { SiteCondition_ado conditionAdo = SiteCondition_ado.CreateSiteCondition_ado(TestHelper.TestGuid1, 32, "F", 2, 3, TestHelper.TestParentGuid); // backdoor data setup DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba) { iba.AddToSiteCondition_ado(conditionAdo); }); SiteCondition_ado conditionAdo2 = SiteCondition_ado.CreateSiteCondition_ado(TestHelper.TestGuid2, 32, "F", 2, 3, TestHelper.TestParentGuid); DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba) { iba.AddToSiteCondition_ado(conditionAdo2); }); // Exercise the test List <SiteCondition> conditions = ConditionsMapper.Select_BySiteVisitId(TestHelper.TestParentGuid); SiteCondition cond = conditions.First(x => x.Id == conditionAdo.ConditionId); validateResults(conditionAdo, cond); cond = conditions.First(x => x.Id == conditionAdo2.ConditionId); validateResults(conditionAdo2, cond); }
private static void validateResults(SiteCondition_ado condAdo, SiteCondition conditions) { Assert.IsNotNull(conditions, "Business object does not exist"); Assert.AreEqual(condAdo.ConditionId, conditions.Id, "ConditionId"); Assert.AreEqual(condAdo.Scale, conditions.Temperature.Units, "Units"); Assert.AreEqual(condAdo.Temperature, conditions.Temperature.Value, "Temperature"); Assert.AreEqual(condAdo.Wind, conditions.Wind, "Wind"); }
private static void validateObjectEquality(SiteCondition condition, SiteCondition_ado adoConditions) { Assert.IsNotNull(adoConditions, "There is not Conditions with the ID to test for"); Assert.AreEqual(condition.SiteVisitId, adoConditions.SiteVisitId, "SiteVisitId"); Assert.AreEqual(condition.Sky, adoConditions.Sky, "Sky"); Assert.AreEqual(condition.Temperature.Value, adoConditions.Temperature, "Temperature"); Assert.AreEqual(condition.Wind, adoConditions.Wind, "Wind"); Assert.AreEqual(condition.Temperature.Units, adoConditions.Scale, "Units/scale"); }
public void t_Conditions_Save_Update() { SiteCondition_ado conditionAdo = null; // backdoor data setup DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba) { conditionAdo = SiteCondition_ado.CreateSiteCondition_ado(TestHelper.TestGuid1, 32, "F", 2, 3, TestHelper.TestParentGuid); }); List <SiteCondition_ado> extraList = DbTestHelper.LoadExtraneousConditions(); // Setup object to be saved. Change everything except the Id. SiteCondition conditions = new SiteCondition() { Id = TestHelper.TestGuid1, SiteVisitId = TestHelper.TestGuid1, Sky = 2, Temperature = new Business.DataTypes.Temperature() { Value = 45, Units = "F" }, Wind = 2 }; // Execute the test ConditionsMapper.Update(conditions); // Validate results using (IbaUnitTestEntities iba = new IbaUnitTestEntities()) { var ConditionsQuery = from Conditionss in iba.SiteCondition_ado select Conditionss; Assert.IsNotNull(ConditionsQuery, "Query result is null"); Assert.AreEqual(extraList.Count() + 1, ConditionsQuery.Count(), "Wrong number of results in query"); SiteCondition_ado adoConditions = ConditionsQuery.First(x => x.ConditionId == TestHelper.TestGuid1); validateObjectEquality(conditions, adoConditions); // double check the other objects as well, must make sure they remain unchanged. foreach (SiteCondition_ado cond in extraList) { SiteCondition_ado posttest = ConditionsQuery.First(x => x.ConditionId == cond.ConditionId); Assert.IsNotNull(posttest, cond.ConditionId.ToString() + " is missing from results"); Assert.AreEqual(cond.Scale, posttest.Scale, cond.ConditionId.ToString() + " different scale"); Assert.AreEqual(cond.SiteVisitId, posttest.SiteVisitId, cond.ConditionId.ToString() + " different SiteVisitId"); Assert.AreEqual(cond.Sky, posttest.Sky, cond.ConditionId.ToString() + " different sky"); Assert.AreEqual(cond.Temperature, posttest.Temperature, cond.ConditionId.ToString() + " different temperature"); Assert.AreEqual(cond.Wind, posttest.Wind, cond.ConditionId.ToString() + " different wind"); } } }
public void t_Conditions_Select_ByGuid() { SiteCondition_ado conditionAdo = SiteCondition_ado.CreateSiteCondition_ado(TestHelper.TestGuid1, 32, "F", 2, 3, TestHelper.TestParentGuid); // backdoor data setup DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba) { iba.AddToSiteCondition_ado(conditionAdo); }); DbTestHelper.LoadExtraneousConditions(); // Exercise the test SiteCondition Conditions = ConditionsMapper.Select(conditionAdo.ConditionId); validateResults(conditionAdo, Conditions); }
/// <summary> /// Loads extra site conditions to improve testing /// </summary> /// <returns>List of <see cref="SiteCondition_ado"/> objects</returns> public static List <SiteCondition_ado> LoadExtraneousConditions() { List <SiteCondition_ado> conditionList = new List <SiteCondition_ado>(); SiteCondition_ado extra1 = SiteCondition_ado.CreateSiteCondition_ado(TestHelper.TestGuid2, 1, "F", 1, 1, TestHelper.TestGuid2); LoadAdoObjects((IbaUnitTestEntities iba) => { iba.AddToSiteCondition_ado(extra1); }); conditionList.Add(extra1); SiteCondition_ado extra2 = SiteCondition_ado.CreateSiteCondition_ado(TestHelper.TestGuid3, 2, "C", 2, 2, TestHelper.TestGuid2); LoadAdoObjects((IbaUnitTestEntities iba) => { iba.AddToSiteCondition_ado(extra2); }); conditionList.Add(extra2); return(conditionList); }