public void QueryWaterQualityDataListTest()
        {
            DateTime beginDate1 = new DateTime(2016, 6, 01, 10, 34, 9);

            DateTime endDate1 = new DateTime(2016, 7, 18, 18, 34, 9);

            DateTime resultDate = new DateTime(2016, 6, 15, 10, 34, 9);

            List<Hatfield.EnviroData.DataProfile.WQ.Models.Analyte> analyteList = new List<Hatfield.EnviroData.DataProfile.WQ.Models.Analyte>();

            String[] arrayNames = { "Toluene", "Ethylbenzene", "Xylenes", "Naphthenic Acid", "Toluene-d8 (BTEX)", "Benzene", "o-Terphenyl (F2-F4)", "C>10 - C16", "Phenolphthalein Alkalinity", "Alkalinity (Total as CaCO3)", "Alkalinity (Carbonate as CaCO3)", "True Colour" };

            for (int i = 0; i < 12; i++)
            {
                Analyte analyte = new Analyte
                {
                    Id = (14 + i),
                    Name = arrayNames[i],
                    Category = new AnalyteCategory
                    {
                        Id = 14,
                        Name = "Chemistry"
                    }

                };
                analyteList.Add(analyte);
            }
               

            
            List<IQueryable<LabReportSample>> queryList = new List<IQueryable<LabReportSample>>();

            var waterQualityProfile = _wqDataProfile.QueryWaterQualityData(beginDate1, endDate1, siteList, analyteList);
          
            queryList.Add(waterQualityProfile);

            var arrayWaterQualityProfile = queryList[0].ToArray();
            Assert.NotNull(waterQualityProfile);

            Assert.AreEqual(12, waterQualityProfile.Count());

            for (int i = 0; i < arrayWaterQualityProfile.Length; i++)
            {
                Assert.AreEqual((i + 1), arrayWaterQualityProfile[i].Value);
                Assert.AreEqual(resultDate, arrayWaterQualityProfile[i].DateTime);
                Assert.AreEqual(analyteList[i].Id, arrayWaterQualityProfile[i].Analyte.Id);
                Assert.AreEqual(analyteList[i].Name, arrayWaterQualityProfile[i].Analyte.Name);

                Assert.AreEqual(siteList[i].Id, arrayWaterQualityProfile[i].Site.Id);
                Assert.AreEqual(siteList[i].Name, arrayWaterQualityProfile[i].Site.Name);
                Assert.AreEqual(siteList[i].Latitude, arrayWaterQualityProfile[i].Site.Latitude);
                Assert.AreEqual(siteList[i].Longitude, arrayWaterQualityProfile[i].Site.Longitude);
                Assert.AreEqual(7, arrayWaterQualityProfile[i].UTCOffset);
            }

        }
        /// <summary>
        /// Query water quality data
        /// </summary>
        /// <param name="startDateTime">query start date</param>
        /// <param name="endDateTime">query end date</param>
        /// <param name="site">query site</param>
        /// <param name="analyte">query analyte</param>
        /// <returns></returns>
        public IQueryable<LabReportSample> QueryWaterQualityData(DateTime startDateTime, DateTime endDateTime, Site site, Analyte analyte)
        {


            var waterQualityObervationModel = from observationModel in _dbContext.Results

                                              where (observationModel.MeasurementResult.MeasurementResultValues.FirstOrDefault().ValueDateTime >= startDateTime &&
                                              observationModel.MeasurementResult.MeasurementResultValues.FirstOrDefault().ValueDateTime <= endDateTime
                                              && observationModel.FeatureAction.SamplingFeature.SamplingFeatureID == site.Id
                                              && observationModel.VariableID == analyte.Id) //use contains to see if identical value is present 
                                              select new LabReportSample
                                              {
                                                  Id = observationModel.ResultID,
                                                  DateTime = observationModel.MeasurementResult.MeasurementResultValues.FirstOrDefault().ValueDateTime,
                                                  UTCOffset = (long)observationModel.MeasurementResult.MeasurementResultValues.FirstOrDefault().ValueDateTimeUTCOffset,
                                                  Value = (int)observationModel.MeasurementResult.MeasurementResultValues.FirstOrDefault().DataValue,
                                                  Analyte = new Analyte()
                                                  {
                                                      Id = observationModel.VariableID,
                                                      Name = observationModel.Variable.VariableDefinition,

                                                      Category = new AnalyteCategory
                                                      {
                                                          Id = observationModel.VariableID,
                                                          Name = observationModel.Variable.VariableTypeCV
                                                      }
                                                  },
                                                  Site = new Site()
                                                  {
                                                      Id = observationModel.FeatureAction.SamplingFeature.Site.SamplingFeatureID,
                                                      Name = observationModel.FeatureAction.SamplingFeature.Site.SamplingFeature.SamplingFeatureName,
                                                      Latitude = observationModel.FeatureAction.SamplingFeature.Site.Latitude,
                                                      Longitude = observationModel.FeatureAction.SamplingFeature.Site.Longitude
                                                  },
                                                  Unit = new Unit
                                                  {
                                                      Id = observationModel.UnitsID,
                                                      Name = observationModel.Unit.UnitsName,
                                                      Description = observationModel.Unit.UnitsTypeCV
                                                  },
                                              };

            return waterQualityObervationModel;
                                               
        }
        public void QueryWaterQualityDataTestAnalyteAndSite()
        {
            DateTime beginDate1 = new DateTime(2016, 6, 01, 10, 34, 9);

            DateTime endDate1 = new DateTime(2016, 7, 18, 18, 34, 9);

            DateTime resultDate = new DateTime(2016, 6, 15, 10, 34, 9);

            List<Hatfield.EnviroData.DataProfile.WQ.Models.Analyte> analyteList = new List<Hatfield.EnviroData.DataProfile.WQ.Models.Analyte>();

            String[] arrayNames = { "Toluene", "Ethylbenzene", "Xylenes", "Naphthenic Acid", "Toluene-d8 (BTEX)", "Benzene", "o-Terphenyl (F2-F4)", "C>10 - C16", "Phenolphthalein Alkalinity", "Alkalinity (Total as CaCO3)", "Alkalinity (Carbonate as CaCO3)", "True Colour" };

            for (int i = 0; i < 12; i++)
            {
                Analyte analyte = new Analyte
                {
                    Id = (14 + i),
                    Name = arrayNames[i],
                    Category = new AnalyteCategory
                    {
                        Id = 14,
                        Name = "Chemistry"
                    }

                };
                analyteList.Add(analyte);
            }


            List<IQueryable<LabReportSample>> QueryList = new List<IQueryable<LabReportSample>>();
            int k = 0;

            for(int i= 0 ; i<analyteList.Count();i++)
            {
           
                 var waterQualityProfile = _wqDataProfile.QueryWaterQualityData(beginDate1, endDate1, siteList[k], analyteList[i]);
                 Assert.NotNull(waterQualityProfile);
                 QueryList.Add(waterQualityProfile);
        
                k++;
                if ((i + 1) % 4 == 0)
                {
                    k = 0;
                }

            }

            Assert.AreEqual(12, QueryList.Count()); //test for the number of values returned after the query


            for (int i = 0; i < QueryList.Count(); i++)
            {
                Assert.AreEqual(1, QueryList[i].Count()); //test for the number of values returned after the query
                Assert.AreEqual((i + 1), QueryList[i].FirstOrDefault().Value);  //values
                Assert.AreEqual(resultDate, QueryList[i].FirstOrDefault().DateTime); //date time
                Assert.AreEqual(7, QueryList[i].FirstOrDefault().UTCOffset); //offset

                Assert.AreEqual(analyteList[i].Id, QueryList[i].FirstOrDefault().Analyte.Id); //analyte id
                Assert.AreEqual(analyteList[i].Name, QueryList[i].FirstOrDefault().Analyte.Name); //analyte name

                Assert.AreEqual(siteList[k].Id, QueryList[i].FirstOrDefault().Site.Id);
                Assert.AreEqual(siteList[k].Name, QueryList[i].FirstOrDefault().Site.Name);
                Assert.AreEqual(siteList[k].Latitude, QueryList[i].FirstOrDefault().Site.Latitude);
                Assert.AreEqual(siteList[k].Longitude, QueryList[i].FirstOrDefault().Site.Longitude);
                    k++;
                    if ((i + 1) % 4 == 0)
                    {
                        k = 0;
                    }

            }
 

        }
        /// <summary>
        /// Query water quality data
        /// </summary>
        /// <param name="startDateTime">query start date</param>
        /// <param name="endDateTime">query end date</param>
        /// <param name="analyte">query analyte</param>
        /// <returns></returns>
        public IQueryable<LabReportSample> QueryWaterQualityData(DateTime startDateTime, DateTime endDateTime, Analyte analyte)
        {
            var waterQualityObervationModel = from observationModel in _dbContext.Results
                                              where (observationModel.MeasurementResult.MeasurementResultValues.FirstOrDefault().ValueDateTime >= startDateTime &&
                                             observationModel.MeasurementResult.MeasurementResultValues.FirstOrDefault().ValueDateTime <= endDateTime
                                              && observationModel.VariableID == analyte.Id)
                                              select new LabReportSample
                                              {
                                                  Id = observationModel.ResultID,
                                                  DateTime = observationModel.MeasurementResult.MeasurementResultValues.FirstOrDefault().ValueDateTime,
                                                  UTCOffset = (long)observationModel.MeasurementResult.MeasurementResultValues.FirstOrDefault().ValueDateTimeUTCOffset,

                                                  Value = (int)observationModel.MeasurementResult.MeasurementResultValues.FirstOrDefault().DataValue,    //needs to be changed
                                                  Analyte = new Analyte()
                                                  {
                                                      Id = observationModel.VariableID,
                                                      Name = observationModel.Variable.VariableDefinition,

                                                      Category = new AnalyteCategory
                                                      {
                                                          Id = observationModel.VariableID,
                                                          Name = observationModel.Variable.VariableTypeCV
                                                      }   

                                                  },
                                                  Unit = new Unit
                                                  {
                                                      Id = observationModel.UnitsID,
                                                      Name = observationModel.Unit.UnitsName,
                                                      Description = observationModel.Unit.UnitsTypeCV
                                                  },
                                              };

            return waterQualityObervationModel;


        }