public void TestTimetableRepository() { ITimetableRepository timetableRepo = new TimetableRepository(); IList <LoadTest> loadTests = timetableRepo.GetLoadTestsForTimePeriod(DateTime.UtcNow.AddDays(-10), DateTime.UtcNow.AddDays(10)); Timetable tt = new Timetable(loadTests); LoadTest newLoadtest = new LoadTest(Guid.Parse("8c928a5e-d038-44f3-a8ff-70f64a651155"), new LoadTestParameters(DateTime.UtcNow.AddDays(3), 120, 900), Guid.Parse("751ec485-437d-4bae-9ff1-1923203a87b1") , Guid.Parse("99f4dc94-718c-450d-87b6-3153bb8db622"), Guid.Parse("471119e2-2b3c-4545-97a2-5f52d1fa7954") , Guid.Parse("a868a7c5-2f4a-43f7-9a8c-a597793fdc56"), Guid.Parse("96877388-ce4d-4ea8-ae93-438a696386b9") , Guid.Parse("73e25716-7622-4af6-99a0-0638efb1c8cc")); List <LoadTest> allChanges = new List <LoadTest>() { newLoadtest }; AddOrUpdateLoadTestsValidationResult result = tt.AddOrUpdateLoadTests(allChanges); Debug.WriteLine(result.OperationResultSummary); timetableRepo.AddOrUpdateLoadTests(result); timetableRepo.DeleteById(Guid.Parse("4e880392-5497-4c9e-a3de-38f66348fe8e")); }
public void AddOrUpdateLoadTests(AddOrUpdateLoadTestsValidationResult addOrUpdateLoadTestsValidationResult) { LoadTestingContext context = new LoadTestingContext(); if (addOrUpdateLoadTestsValidationResult.ValidationComplete) { if (addOrUpdateLoadTestsValidationResult.ToBeInserted.Any()) { foreach (LoadTest toBeInserted in addOrUpdateLoadTestsValidationResult.ToBeInserted) { context.Entry <LoadTest>(toBeInserted).State = System.Data.Entity.EntityState.Added; } } if (addOrUpdateLoadTestsValidationResult.ToBeUpdated.Any()) { foreach (LoadTest toBeUpdated in addOrUpdateLoadTestsValidationResult.ToBeUpdated) { context.Entry <LoadTest>(toBeUpdated).State = System.Data.Entity.EntityState.Modified; } } } else { throw new InvalidOperationException("Validation is not complete. You have to call the AddOrUpdateLoadTests method of the Timetable class first."); } context.SaveChanges(); }
private AddOrUpdateLoadtestsResponse AddOrUpdateLoadTests(AddOrUpdateLoadtestsRequest request) { AddOrUpdateLoadtestsResponse resp = new AddOrUpdateLoadtestsResponse(); try { foreach (LoadTestViewModel vm in request.Loadtests) { if (vm.Id == null || vm.Id == default(Guid)) { vm.Id = Guid.NewGuid(); } } List <LoadTestViewModel> sortedByDate = request.Loadtests.OrderBy(l => l.StartDateUtc).ToList(); LoadTestViewModel last = sortedByDate.Last(); IList <LoadTest> loadtests = _timetableRepository.GetLoadTestsForTimePeriod(sortedByDate.First().StartDateUtc, last.StartDateUtc.AddSeconds(last.DurationSec)); Timetable timetable = new Timetable(loadtests); IList <LoadTest> loadtestsAddedOrUpdated = _timetableViewModelRepository.ConvertToDomain(request.Loadtests); AddOrUpdateLoadTestsValidationResult validationResult = timetable.AddOrUpdateLoadTests(loadtestsAddedOrUpdated); _timetableRepository.AddOrUpdateLoadTests(validationResult); resp.AddOrUpdateLoadtestsValidationResult = validationResult; } catch (Exception ex) { resp.Exception = ex; } return(resp); }
public TimetableChangedEventArgs(AddOrUpdateLoadTestsValidationResult validationResult) { if (validationResult == null) { throw new ArgumentNullException("validationResult"); } _validationResult = validationResult; }
public void Handle(EventArgs eventArgs) { TimetableChangedEventArgs e = eventArgs as TimetableChangedEventArgs; if (e != null) { AddOrUpdateLoadTestsValidationResult validationResult = e.AddOrUpdateLoadtestsValidationResult; if ((validationResult.ToBeInserted.Any() || validationResult.ToBeUpdated.Any()) && !validationResult.Failed.Any()) { EmailArguments args = new EmailArguments("Load tests added or updated", "Load tests added or updated", "My boss", "Developer1", "127.0.0.1"); _emailService.SendMail(args); } } }
public async Task <AddOrUpdateLoadtestsResponse> AddOrUpdateLoadtestsAsync(AddOrUpdateLoadtestsRequest request) { AddOrUpdateLoadtestsResponse resp = await _innerTimetableService.AddOrUpdateLoadtestsAsync(request); if (resp.Exception == null) { AddOrUpdateLoadTestsValidationResult validationResult = resp.AddOrUpdateLoadtestsValidationResult; if ((validationResult.ToBeInserted.Any() || validationResult.ToBeUpdated.Any()) && !validationResult.Failed.Any()) { EmailArguments args = new EmailArguments("Load tests added or updated", "Load tests added or updated", "My boss", "Developer1", "127.0.0.1"); _emailService.SendMail(args); } } return(resp); }