public void TestSamplingPointQueryAsync_ServerReturnsQuery_ReturnsListWithSamplingPoint()
        {
            var expectedSamplingPoint = new SamplingPoint[]
            { new SamplingPoint {
                  SamplingPointId = "SamplingPointId"
              },
              new SamplingPoint {
                  SamplingPointId = "AnotherSamplingPointId"
              } };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient
            .Setup(client => client.GetAsync(ServiceAddress + "surveys/1/samplingpoints"))
            .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedSamplingPoint))));

            var target = new NfieldSurveysService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actualSamplingPoint = target.SamplingPointsQueryAsync("1").Result;

            Assert.Equal(expectedSamplingPoint[0].SamplingPointId, actualSamplingPoint.ToArray()[0].SamplingPointId);
            Assert.Equal(expectedSamplingPoint[1].SamplingPointId, actualSamplingPoint.ToArray()[1].SamplingPointId);
            Assert.Equal(2, actualSamplingPoint.Count());
        }
        /// <summary>
        /// See <see cref="INfieldSurveysService.SamplingPointUpdateAsync"/>
        /// </summary>
        public Task <SamplingPoint> SamplingPointUpdateAsync(string surveyId, SamplingPoint samplingPoint)
        {
            if (samplingPoint == null)
            {
                throw new ArgumentNullException("samplingPoint");
            }

            var updatedSamplingPoint = new UpdateSamplingPoint
            {
                Name              = samplingPoint.Name,
                Description       = samplingPoint.Description,
                FieldworkOfficeId = samplingPoint.FieldworkOfficeId,
                GroupId           = samplingPoint.GroupId,
                Stratum           = samplingPoint.Stratum
            };

            var uri = new Uri(SurveysApi, $"{surveyId}/{SamplingPointsControllerName}/{samplingPoint.SamplingPointId}");

            return(Client.PatchAsJsonAsync(uri, updatedSamplingPoint)
                   .ContinueWith(
                       responseMessageTask => responseMessageTask.Result.Content.ReadAsStringAsync().Result)
                   .ContinueWith(
                       stringTask => JsonConvert.DeserializeObject <SamplingPoint>(stringTask.Result))
                   .FlattenExceptions());
        }
        public void t_SamplingPointMapper_Save_Insert()
        {
            loadASite();
            SamplingPoint site = new SamplingPoint()
            {
                GeoCoordinate = new Business.DataTypes.Coordinate()
                {
                    Latitude = new Business.DataTypes.Degree()
                    {
                        Value = 56.789M
                    },
                    Longitude = new Business.DataTypes.Degree()
                    {
                        Value = 67.281M
                    }
                },
                Id     = TestHelper.TestGuid1,
                Name   = "Site Name",
                SiteId = TestHelper.TestParentGuid
            };

            SamplingPointMapper.Insert(site);


            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var siteQuery = from sites in iba.SamplingPoint_ado select sites;
                Assert.IsNotNull(siteQuery, "Query result is null");
                Assert.AreEqual(1, siteQuery.Count(), "Wrong number of results in query");
                SamplingPoint_ado adoSite = siteQuery.First();
                validateObjectEquality(site, adoSite);
            }
        }
    private FiftyMeterPointSurvey getCurrentPointSurvey()
    {
        if (this.SitePointsList.Items.Count.Equals(0))
        {
            // TODO figure out the proper response???
            return(null);
        }

        if (this.UserState.SamplingPoint == null)
        {
            SamplingPoint point = this.SitePointsList.Items[0].DataItem as SamplingPoint;
            this.UserState.SamplingPoint = point;
        }

        FiftyMeterPointSurvey survey =
            this.UserState.SiteVisit.PointSurveys.Find(x => x.LocationId == this.UserState.SamplingPoint.Id);

        if (survey == null)
        {
            survey             = FiftyMeterPointSurvey.CreateNewPointSurvey(this.UserState.SamplingPoint.Id);
            survey.SiteVisitId = this.UserState.SiteVisit.Id;
            this.UserState.SiteVisit.PointSurveys.Add(survey);
        }
        this.UserState.PointSurvey = survey;

        this.ObservationsList.DataBind();

        return(survey);
    }
        public void TestSamplingPointUpdateAsync_SamplingPointExists_ReturnsSamplingPoint()
        {
            const string surveyId             = "SurveyId";
            const string samplingPointId      = "SamplingPointId";
            const string samplingPointGroupId = "MyGroupId";

            var samplingPoint = new SamplingPoint
            {
                SamplingPointId = samplingPointId,
                Name            = "Updated",
                GroupId         = samplingPointGroupId
            };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient
            .Setup(
                client =>
                client.PatchAsJsonAsync <UpdateSamplingPoint>(
                    string.Format("{0}surveys/{1}/samplingpoints/{2}", ServiceAddress, surveyId,
                                  samplingPointId), It.IsAny <UpdateSamplingPoint>()))
            .Returns(CreateTask(HttpStatusCode.OK,
                                new StringContent(JsonConvert.SerializeObject(samplingPoint))));

            var target = new NfieldSurveysService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actual = target.SamplingPointUpdateAsync(surveyId, samplingPoint).Result;

            Assert.Equal(samplingPoint.Name, actual.Name);
            Assert.Equal(samplingPoint.GroupId, actual.GroupId);
        }
 private static void validateObjectEquality(SamplingPoint site, SamplingPoint_ado adoSite)
 {
     Assert.IsNotNull(adoSite, "There is not Site with the ID to test for");
     Assert.AreEqual(site.GeoCoordinate.Latitude.Value, adoSite.Latitude, "Latitude");
     Assert.AreEqual(site.GeoCoordinate.Longitude.Value, adoSite.Longitude, "Longitude");
     Assert.AreEqual(site.Id, adoSite.LocationId, "Id");
     Assert.AreEqual(site.Name, adoSite.LocationName, "Name");
 }
        public void t_SamplingPointMapper_Save_Update()
        {
            Location_ado location = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                location                  = Location_ado.CreateLocation_ado(TestHelper.TestGuid1, "locationName", LookupConstants.LocationTypePoint);
                location.CodeName         = "abc";
                location.Latitude         = 89.3M;
                location.Longitude        = 90.10093M;
                location.ParentLocationId = TestHelper.TestParentGuid;
                iba.AddToLocation_ado(location);
            });
            List <Location_ado> extraList = DbTestHelper.LoadExtraneousLocations();

            // Setup object to be saved. Change everything except the Id.
            SamplingPoint site = new SamplingPoint()
            {
                GeoCoordinate = new Business.DataTypes.Coordinate()
                {
                    Latitude = new Business.DataTypes.Degree()
                    {
                        Value = location.Latitude.Value + 1M
                    },
                    Longitude = new Business.DataTypes.Degree()
                    {
                        Value = location.Longitude.Value + 1M
                    }
                },
                Id     = location.LocationId,
                Name   = location.LocationName + "asd",
                SiteId = TestHelper.TestParentGuid
            };

            // Execute the test
            SamplingPointMapper.Update(site);

            // Validate results
            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var siteQuery = from sites in iba.SamplingPoint_ado select sites;
                Assert.IsNotNull(siteQuery, "Query result is null");
                Assert.AreEqual(extraSamplingPoints(extraList).Count() + 1, siteQuery.Count(), "Wrong number of results in query");
                SamplingPoint_ado adoSite = siteQuery.First(x => x.LocationId == TestHelper.TestGuid1);
                validateObjectEquality(site, adoSite);

                // double check the other objects as well, must make sure they remain unchanged.
                foreach (Location_ado adoLocation in extraSamplingPoints(extraList))
                {
                    adoSite = siteQuery.First(x => x.LocationId == adoLocation.LocationId);
                    Assert.IsNotNull(adoSite, "There is no longer an object with id " + adoLocation.LocationId.ToString());
                    Assert.AreEqual(adoLocation.Latitude, adoSite.Latitude, "Extra " + adoSite.LocationId.ToString() + " Latitude mismatch");
                    Assert.AreEqual(adoLocation.Longitude, adoSite.Longitude, "Extra " + adoSite.LocationId.ToString() + " Longitude mismatch");
                    Assert.AreEqual(adoSite.LocationName, adoSite.LocationName, "Extra " + adoSite.LocationId.ToString() + " Locationname mismatch");
                }
            }
        }
        /// <summary>
        /// See <see cref="INfieldSurveysService.SamplingPointAddAsync"/>
        /// </summary>
        public Task <SamplingPoint> SamplingPointAddAsync(string surveyId, SamplingPoint samplingPoint)
        {
            var uri = new Uri(SurveysApi, $"{surveyId}/{SamplingPointsControllerName}");

            return(Client.PostAsJsonAsync(uri, samplingPoint)
                   .ContinueWith(task => task.Result.Content.ReadAsStringAsync().Result)
                   .ContinueWith(task => JsonConvert.DeserializeObject <SamplingPoint>(task.Result))
                   .FlattenExceptions());
        }
Пример #9
0
        /// <summary>
        /// See <see cref="INfieldSurveysService.SamplingPointAddAsync"/>
        /// </summary>
        public Task <SamplingPoint> SamplingPointAddAsync(string surveyId, SamplingPoint samplingPoint)
        {
            string uri = string.Format(@"{0}{1}/{2}", SurveysApi.AbsoluteUri, surveyId, SamplingPointsControllerName);

            return(Client.PostAsJsonAsync(uri, samplingPoint)
                   .ContinueWith(task => task.Result.Content.ReadAsStringAsync().Result)
                   .ContinueWith(task => JsonConvert.DeserializeObjectAsync <SamplingPoint>(task.Result).Result)
                   .FlattenExceptions());
        }
Пример #10
0
        private static SamplingPoint Load(IDataReader reader)
        {
            SamplingPoint site = new SamplingPoint();

            LocationBaseMapper.Load(reader, site);

            site.SiteId = reader.GetGuidFromName("ParentLocationId");

            return(site);
        }
 private static void validateResults(Location_ado location, SamplingPoint point)
 {
     Assert.IsNotNull(point, "Point object is null");
     Assert.IsNotNull(point.GeoCoordinate, "Coordinates are null");
     Assert.AreEqual(location.Latitude, point.GeoCoordinate.Latitude.Value, "Latitude");
     Assert.AreEqual(location.LocationId, point.Id, "Id");
     Assert.AreEqual(location.LocationName, point.Name, "name");
     Assert.AreEqual(location.Longitude, point.GeoCoordinate.Longitude.Value, "Longitude");
     Assert.AreEqual(location.ParentLocationId, point.SiteId, "SiteId");
 }
Пример #12
0
        public void t_SiteId()
        {
            SamplingPoint target   = new SamplingPoint();
            Guid          expected = LookupConstants.LocationTypePoint;

            Guid actual;

            target.SiteId = expected;
            actual        = target.SiteId;
            Assert.AreEqual(expected, actual);
        }
Пример #13
0
        /// <summary>
        /// See <see cref="INfieldSurveysService.SamplingPointDeleteAsync"/>
        /// </summary>
        public Task SamplingPointDeleteAsync(string surveyId, SamplingPoint samplingPoint)
        {
            if (samplingPoint == null)
            {
                throw new ArgumentNullException("samplingPoint");
            }
            var uri = new Uri(SurveysApi, $"{surveyId}/{SamplingPointsControllerName}/{samplingPoint.SamplingPointId}");

            return(Client.DeleteAsync(uri)
                   .FlattenExceptions());
        }
Пример #14
0
        /// <summary>
        /// See <see cref="INfieldSurveysService.SamplingPointDeleteAsync"/>
        /// </summary>
        public Task SamplingPointDeleteAsync(string surveyId, SamplingPoint samplingPoint)
        {
            if (samplingPoint == null)
            {
                throw new ArgumentNullException("samplingPoint");
            }
            string uri = string.Format(@"{0}{1}/{2}/{3}", SurveysApi.AbsoluteUri, surveyId, SamplingPointsControllerName, samplingPoint.SamplingPointId);

            return(Client.DeleteAsync(uri)
                   .FlattenExceptions());
        }
Пример #15
0
        public void t_CreateNewSamplingPoint()
        {
            safnet.iba.Business.Entities.Moles.MSafnetBaseEntity.AllInstances.SetNewId = (SafnetBaseEntity entity) => { return(entity.Id = LookupConstants.LocationTypeParent); };

            string name = "site name";

            SamplingPoint actual = SamplingPoint.CreateNewSamplingPoint(name);

            Assert.IsNotNull(actual, "object is null");
            Assert.AreEqual(LookupConstants.LocationTypeParent, actual.Id, "ID not assigned");
            Assert.AreEqual(name, actual.Name, "Name not assigned");
        }
Пример #16
0
        private static void saveSamplingPoint(SamplingPoint point)
        {
            List <QueryParameter> parmList = new List <QueryParameter>()
            {
                new QueryParameter("Id", point.Id),
                new QueryParameter("Longitude", point.GeoCoordinate.Longitude.Value),
                new QueryParameter("Latitude", point.GeoCoordinate.Latitude.Value),
                new QueryParameter("LocationName", point.Name),
                new QueryParameter("ParentLocationId", point.SiteId)
            };

            BaseMapper.SaveObject(point, parmList);
        }
        public void t_SamplingPointMapper_Delete()
        {
            Location_ado location = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                location = Location_ado.CreateLocation_ado(TestHelper.TestParentGuid,
                                                           "locationName", LookupConstants.LocationTypeSite);
                location.CodeName         = "abc";
                location.Latitude         = 89.3M;
                location.Longitude        = 90.10093M;
                location.ParentLocationId = null;
                iba.AddToLocation_ado(location);
            });
            Location_ado pointAdo = null;

            DbTestHelper.LoadAdoObjects((IbaUnitTestEntities iba) =>
            {
                pointAdo = Location_ado.CreateLocation_ado(TestHelper.TestGuid1,
                                                           "pointName", LookupConstants.LocationTypePoint);
                location.ParentLocationId = TestHelper.TestParentGuid;
                iba.AddToLocation_ado(pointAdo);
            });
            List <Location_ado> extraList = DbTestHelper.LoadExtraneousLocations();


            SamplingPoint point = new SamplingPoint()
            {
                Id     = TestHelper.TestGuid1,
                SiteId = TestHelper.TestParentGuid
            };

            // Exercise the system under test
            SamplingPointMapper.Delete(point);

            // Validate that the one record was deleted but none others were
            using (IbaUnitTestEntities iba = new IbaUnitTestEntities())
            {
                var pointQuery = from points in iba.Location_ado select points;
                Assert.IsNotNull(pointQuery, "Query result is null");
                Assert.AreEqual(0, pointQuery.Count(x => x.LocationId == point.Id), "Point wasn't deleted");

                // Check to see if extra points and locations are still in the database
                foreach (Location_ado extra in extraList)
                {
                    Assert.AreEqual(1, pointQuery.Count(x => x.LocationId == extra.LocationId), "Location " + extra.LocationId.ToString() + " is no longer in the database.");
                }
                Assert.AreEqual(1, pointQuery.Count(x => x.LocationId == location.LocationId), "Parent was deleted");
            }
        }
Пример #18
0
        public void t_AddSamplingPoint()
        {
            Site target = new Site();

            target.Id = LookupConstants.LocationTypePoint;
            SamplingPoint point = new SamplingPoint()
            {
                Name = "a name"
            };

            target.AddSamplingPoint(point);

            Assert.IsTrue(target.SamplingPoints.Contains(point), "Does not contain point");
            Assert.AreEqual(LookupConstants.LocationTypePoint, point.SiteId, "SiteId not assigned to point");
        }
        public void t_SamplingPointMapper_Select_ByGuid()
        {
            Location_ado location = null;

            // backdoor data setup
            DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba)
            {
                location = Location_ado.CreateLocation_ado(TestHelper.TestGuid1,
                                                           "locationName", LookupConstants.LocationTypePoint);
                location.Latitude         = 89.3M;
                location.Longitude        = 90.10093M;
                location.ParentLocationId = TestHelper.TestParentGuid;
                iba.AddToLocation_ado(location);
            });
            DbTestHelper.LoadExtraneousLocations();

            // Exercise the test
            SamplingPoint site = SamplingPointMapper.Select(location.LocationId);

            validateResults(location, site);
        }
Пример #20
0
        public void TestSamplingPointRemoveAsync_ServerRemovedSamplingPoint_DoesNotThrow()
        {
            const string samplingPointId = "SamplingPointId";
            const string surveyId        = "SurveyId";
            var          samplingPoint   = new SamplingPoint
            {
                SamplingPointId = samplingPointId
            };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient
            .Setup(client => client.DeleteAsync(string.Format("{0}surveys/{1}/samplingpoints/{2}", ServiceAddress, surveyId,
                                                              samplingPointId)))
            .Returns(CreateTask(HttpStatusCode.OK));

            var target = new NfieldSurveysService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            Assert.DoesNotThrow(() => target.SamplingPointDeleteAsync(surveyId, samplingPoint).Wait());
        }
Пример #21
0
        public void TestSamplingPointAddAsync_ServerAcceptsSamplingPoint_ReturnsSamplingPoint()
        {
            const string samplingPointGroupId = "MyGroupId";
            var          office = new FieldworkOffice {
                OfficeId = "OfficeId"
            };
            var survey = new Survey(SurveyType.Basic)
            {
                SurveyId = "SurveyId"
            };
            var samplingPoint = new SamplingPoint
            {
                SamplingPointId   = "SamplingPointId",
                FieldworkOfficeId = office.OfficeId,
                GroupId           = samplingPointGroupId
            };

            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);
            var content = new StringContent(JsonConvert.SerializeObject(samplingPoint));

            mockedHttpClient
            .Setup(
                client =>
                client.PostAsJsonAsync(
                    string.Format("{0}surveys/{1}/samplingpoints", ServiceAddress, survey.SurveyId),
                    samplingPoint))
            .Returns(CreateTask(HttpStatusCode.OK, content));

            var target = new NfieldSurveysService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actual = target.SamplingPointAddAsync(survey.SurveyId, samplingPoint).Result;

            Assert.Equal(samplingPoint.SamplingPointId, actual.SamplingPointId);
            Assert.Equal(samplingPoint.FieldworkOfficeId, actual.FieldworkOfficeId);
            Assert.Equal(samplingPoint.GroupId, actual.GroupId);
        }
Пример #22
0
    private void SitePointsList_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        ListViewDataItem item  = (ListViewDataItem)e.Item;
        SamplingPoint    point = (SamplingPoint)item.DataItem;

        // Setup the hyperlinks for the list of points
        LinkButton pointName = item.FindControl("PointName") as LinkButton;

        pointName.CommandName     = "Switch";
        pointName.CommandArgument = point.Id.ToString();
        pointName.Text            = point.Name;

        if (this.UserState.SamplingPoint == null)
        {
            this.UserState.SamplingPoint = point;
        }

        // Determine which type of arrow should be displayed
        if (this.UserState.SamplingPoint.Id == point.Id)
        {
            Image arrow = item.FindControl("PointArrow") as Image;
            arrow.Visible      = true;
            pointName.CssClass = "CurrentPoint";
            pointName.Enabled  = false;

            this.CurrentPointName.Text = point.Name;
        }
        else if (!this.UserState.PointsRemaining.Count.Equals(0) && !this.UserState.PointsRemaining.Contains(point))
        {
            Image okay = item.FindControl("PointOkay") as Image;
            okay.Visible       = true;
            pointName.CssClass = "CompletedPoint";
        }
        else
        {
            Image arrow = item.FindControl("PointSilver") as Image;
            arrow.Visible = true;
        }
    }
Пример #23
0
        public void TestSamplingPointRemoveAsync_ServerRemovedSamplingPoint_DoesNotThrow()
        {
            const string samplingPointId = "SamplingPointId";
            const string surveyId        = "SurveyId";
            var          samplingPoint   = new SamplingPoint
            {
                SamplingPointId = samplingPointId
            };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient
            .Setup(client => client.DeleteAsync(new Uri(ServiceAddress, $"Surveys/{surveyId}/SamplingPoints/{samplingPointId}")))
            .Returns(CreateTask(HttpStatusCode.OK));

            var target = new NfieldSurveysService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            // assert: no throw
            target.SamplingPointDeleteAsync(surveyId, samplingPoint).Wait();
        }
Пример #24
0
    private void PointSurveyList_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        ListViewDataItem      item   = (ListViewDataItem)e.Item;
        FiftyMeterPointSurvey survey = (FiftyMeterPointSurvey)item.DataItem;


        // find the SamplingPoint in order to get the right text for the PointName label
        SamplingPoint point =
            this.UserState.PointsRemaining.Union(this.UserState.PointsCompleted)
            .SingleOrDefault(x => x.Id.Equals(survey.SamplingPointId));

        if (point == null)
        {
            Master.SetErrorMessage(
                "<p>Apologies for the inconvenience, but there seems to have been an unexpected problem. Please close this browser window and start your data entry session over.</p>");
            return;
        }
        Label pointName = item.FindControl("SurveyPointName") as Label;

        pointName.Text = point.Name;

        Label startTime = item.FindControl("SurveyStartTime") as Label;
        Label noise     = item.FindControl("SurveyNoise") as Label;
        Label count     = item.FindControl("SurveyCountSpecies") as Label;


        if (survey.StartTimeStamp.HasValue)
        {
            startTime.Text = survey.StartTimeStamp.Value.ToString("yyyy-MM-dd HH:mm");
            noise.Text     = survey.NoiseCode + " - " + survey.NoiseCodeText;
            count.Text     = survey.Observations.GroupBy(x => x.SpeciesCode).Count().ToString();
        }
        else
        {
            startTime.Text = noise.Text = count.Text = "n/a";
        }
    }
 /// <summary>
 /// Updates an existing <see cref="SamplingPoint"/> with a synchronous operation.
 /// </summary>
 public void UpdateSamplingPoint(string surveyId, SamplingPoint samplingPoint)
 {
     _surveysService.SamplingPointUpdate(surveyId, samplingPoint);
 }
 /// <summary>
 /// Adds a sampling point with a synchronous operation.
 /// </summary>
 /// <param name="surveyId"></param>
 /// <param name="samplingPoint"></param>
 public void AddSamplingPoint(string surveyId, SamplingPoint samplingPoint)
 {
     _surveysService.SamplingPointAdd(surveyId, samplingPoint);
 }
 /// <summary>
 /// A synchronous version of <see cref="INfieldSurveysService.SamplingPointUpdateAsync"/>
 /// </summary>
 public static void SamplingPointUpdate(this INfieldSurveysService surveysService, string surveyId, SamplingPoint samplingPoint)
 {
     surveysService.SamplingPointUpdateAsync(surveyId, samplingPoint).Wait();
 }
Пример #28
0
 public static void Update(SamplingPoint point)
 {
     saveSamplingPoint(point);
 }
Пример #29
0
 public static void Insert(SamplingPoint point)
 {
     saveSamplingPoint(point);
 }
Пример #30
0
 public static void Delete(SamplingPoint point)
 {
     BaseMapper.DeleteObject(point);
 }