public async Task EPSPetroAuditControllerTest_FailAuditByVersion() { IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); MockEPSPetroAuditRepository fakeRepo = new MockEPSPetroAuditRepository(); IDistributedCache _cache = FakeCache(); var localizer = new MockStringLocalizer <EPSPetroAuditController>(); localizer[0] = new LocalizedString("DatesErrorMsg", "Start and end dates are mandatory"); IEPSPetroAuditApi epsPetroAuditAPI = new EPSPetroAuditApi(appSettings, fakeRepo); EPSPetroAuditController controller = FakeController(_cache, epsPetroAuditAPI, localizer); var epsPetroAudits = await controller.Get(901, null, null); var actualResult = ((Microsoft.AspNetCore.Mvc.ObjectResult)epsPetroAudits); Assert.Equal(actualResult.StatusCode, (int)System.Net.HttpStatusCode.BadRequest); Assert.Equal((actualResult.Value), "Start and end dates are mandatory"); }
public async Task EPSPetroAuditControllerTest_FailOnDateRangeAuditByVersion() { IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); MockEPSPetroAuditRepository fakeRepo = new MockEPSPetroAuditRepository(); IDistributedCache _cache = FakeCache(); var localizer = new MockStringLocalizer <EPSPetroAuditController>(); localizer[0] = new LocalizedString("DateRangeError", "Date range should not be greater than 30 days"); IEPSPetroAuditApi epsPetroAuditAPI = new EPSPetroAuditApi(appSettings, fakeRepo); EPSPetroAuditController controller = FakeController(_cache, epsPetroAuditAPI, localizer); var epsPetroAudits = await controller.Get(901, "2017-09-01 13:53:28.710", "2017-10-10 13:53:28.710"); var actualResult = ((Microsoft.AspNetCore.Mvc.ObjectResult)epsPetroAudits); Assert.Equal(actualResult.StatusCode, (int)System.Net.HttpStatusCode.BadRequest); Assert.Equal((actualResult.Value), "Date range should not be greater than 30 days"); }
public async Task EPSPetroAuditControllerTest_SuccessAuditByVersion() { int versionId = 901; string start = "2017-09-10 13:53:28.710"; string end = "2017-10-10 13:53:28.710"; IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); MockEPSPetroAuditRepository fakeRepo = new MockEPSPetroAuditRepository(); IDistributedCache _cache = FakeCache(); IEPSPetroAuditApi epsPetroAuditAPI = new EPSPetroAuditApi(appSettings, fakeRepo); EPSPetroAuditController controller = FakeController(_cache, epsPetroAuditAPI); var epsPetroAudits = await controller.Get(versionId, start, end); var actualResult = ((Microsoft.AspNetCore.Mvc.ObjectResult)epsPetroAudits).Value; var audits = fakeRepo.epsPetroAudits.Where(s => s.versionId == versionId && Convert.ToDateTime(start) <= s.auditDate && Convert.ToDateTime(end) >= s.auditDate).ToList(); var expected = JsonConvert.SerializeObject(audits); var actual = JsonConvert.SerializeObject(actualResult); Assert.Equal(expected, actual); }