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);
        }
        public void SaveSiteConditions(SiteVisit visit)
        {
            if (visit == null)
            {
                throw new ArgumentNullException("visit");
            }

            SiteVisitMapper.Insert(visit);
            ConditionsMapper.Insert(visit.StartConditions);
            ConditionsMapper.Insert(visit.EndConditions);
        }
        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");
                }
            }
        }
Ejemplo n.º 5
0
    protected void RetrieveIncomplete_Click(object sender, EventArgs e)
    {
        if (this.SiteVisitedInput.SelectedIndex > -1 && !string.IsNullOrEmpty(this.VisitDateInput.Text))
        {
            List <SiteVisit> visitList = SiteVisitMapper.SelectAllForSite(Guid.Parse(this.SiteVisitedInput.SelectedValue));
            SiteVisit        theVisit  = visitList.Find(x => !x.IsDataEntryComplete
                                                        &&
                                                        x.StartTimeStamp.Value.ToShortDateString()
                                                        .Equals(
                                                            DateTime.Parse(this.VisitDateInput.Text).ToShortDateString()));
            if (theVisit != null)
            {
                resetSession();

                this.UserState.SiteVisit = theVisit;
                this.UserState.SiteVisit.SupplementalObservations.AddRange(
                    SupplementalObservationMapper.SelectAllForEvent(theVisit.Id));
                this.UserState.SiteVisit.PointSurveys.AddRange(PointSurveyMapper.SelectAllForSiteVisit(theVisit.Id));
                this.UserState.SiteVisit.PointSurveys.ForEach(x =>
                {
                    x.Observations.AddRange(ObservationMapper.SelectAllForEvent <PointCountBeyond50>(x.Id));
                    x.Observations.AddRange(ObservationMapper.SelectAllForEvent <PointCountWithin50>(x.Id));
                });
                List <SiteCondition> conditions = ConditionsMapper.Select_BySiteVisitId(theVisit.Id);
                if (conditions != null && conditions.Count.Equals(2))
                {
                    this.UserState.SiteVisit.StartConditions =
                        conditions.Single(x => x.Id.Equals(this.UserState.SiteVisit.StartConditions.Id));
                    this.UserState.SiteVisit.EndConditions =
                        conditions.Single(x => x.Id.Equals(this.UserState.SiteVisit.EndConditions.Id));
                }

                loadCurrentSiteVisit();
            }
            else
            {
                Master.SetErrorMessage(
                    "<p>No <i>incomplete</i> site visit entry has been started for this site and date.</p>");
            }
        }
        else
        {
            Master.SetErrorMessage(
                "<p>Both site and date must be filled in to retrieve an incomplete site visit.</p>");
        }
    }
        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);
        }