public void AddMeasurement(Site site, Measurement measurement) { repomeasurement_.Add(measurement); site.Measurements.Add(measurement); repomeasurement_.CommitChanges(); reposite_.CommitChanges(); }
public Site AddSite(Customer custom, string description, double longitude, double latitude) { Site site = new Site(); site.Customer = custom; site.Description = description; site.Longitude = longitude; site.Latitude = latitude; site = reposite_.Add(site); reposite_.CommitChanges(); return site; }
public Measurement GetLatestSiteState(Site site) { Validator<Site> validator = valFactory.CreateValidator<Site>(); ValidationResults valResults = validator.Validate(site); if (!valResults.IsValid) { logger_.Error("Validation Error"); throw new ValidationException(); } logger_.Info("Returned latest Site Measurement"); return site.Measurements.OrderByDescending(x => x.Time).First(); }
public void GetLatestSiteStateTest() { SiteService target = new SiteService(new RepositoryMock<Site>(), new RepositoryMock<Measurement>()); Site site = new Site() { Description = "Description", Latitude = 43.012312, Longitude = 12.12312, Serialnumber = "!§$%&/()", SiteID = 1 }; Measurement expected = new Measurement() { MeasurementID = 1, Time = DateTime.Now, Value = 100 }; site.Measurements.Add(expected); site.Measurements.Add(new Measurement() { MeasurementID = 2, Time = DateTime.Now.Subtract(TimeSpan.FromDays(1000)), Value = 100 }); site.Measurements.Add(new Measurement() { MeasurementID = 3, Time = DateTime.Now.Subtract(TimeSpan.FromHours(1)), Value = 100 }); site.Measurements.Add(new Measurement() { MeasurementID = 4, Time = DateTime.Now.Subtract(TimeSpan.FromSeconds(1)), Value = 100 }); Measurement actual; actual = target.GetLatestSiteState(site); Assert.AreEqual(expected, actual); }
public void GetCustomerStatisticsExceptionTest() { IRepository<Measurement> measurerepo = new RepositoryMock<Measurement>(); DateTime StartDate = DateTime.Now.Subtract(TimeSpan.FromDays(1000)); ; DateTime EndDate = StartDate.AddDays(100); Customer customer = new Customer() { Person = new Person() { Email = "*****@*****.**", Firstname = "PersonVorname", Lastname = "PersonNachname", Password = "******", Username = "******" } }; StatisticsService target = new StatisticsService(measurerepo); Site site = new Site() { Description = "Description", Latitude = 43.012312, Longitude = 12.12312, Serialnumber = "!§$%&/()", SiteID = 1 }; Measurement exp1 = new Measurement() { MeasurementID = 2, Time = StartDate.AddDays(11), Value = 100, Site = site }; Measurement exp2 = new Measurement() { MeasurementID = 4, Time = StartDate.AddDays(25), Value = 100, Site = site }; Measurement somemeasure1 = new Measurement() { MeasurementID = 1, Time = StartDate.Subtract(TimeSpan.FromDays(1)), Value = 100, Site = site }; site.Measurements.Add(somemeasure1); Measurement somemeasure2 = new Measurement() { MeasurementID = 3, Time = EndDate.AddDays(1), Value = 100, Site = site }; site.Measurements.Add(somemeasure2); site.Customer = customer; customer.Sites.Add(site); measurerepo.Add(somemeasure1); measurerepo.Add(somemeasure2); measurerepo.Add(exp1); measurerepo.Add(exp2); List<Measurement> expected = new List<Measurement>(){ exp1, exp2}; List<Measurement> actual; actual = target.GetCustomerStatistics(customer, StartDate, EndDate); CollectionAssert.AreEqual(actual, expected); }