private static EPSLogController FakeController(IDistributedCache cache, IEPSLogApi service, MockStringLocalizer <EPSLogController> localizer = null) { if (localizer == null) { localizer = new MockStringLocalizer <EPSLogController>(); } IOperation fakeOperation = FakeOperation(cache); ILoggingFacade fakeLogger = FakeLogger(); var controller = new EPSLogController(cache, service, localizer, fakeOperation, fakeLogger) { }; return(controller); }
public async Task EPSLogControllerTest_Success() { IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); MockEPSLogRepository fakeRepo = new MockEPSLogRepository(); IDistributedCache _cache = FakeCache(); IEPSLogApi epslogAPI = new EPSLogApi(appSettings, fakeRepo); EPSLogController controller = FakeController(_cache, epslogAPI); var epslogs = await controller.Get("07/05/2017", "07/05/2017", null, null); var actualResult = ((Microsoft.AspNetCore.Mvc.ObjectResult)epslogs).Value; var expected = JsonConvert.SerializeObject(fakeRepo.epslogs); var actual = JsonConvert.SerializeObject(actualResult); Assert.Equal(expected, actual); }
public async Task EPSLogControllerTest_FailDaterange() { IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); MockEPSLogRepository fakeRepo = new MockEPSLogRepository(); IDistributedCache _cache = FakeCache(); IEPSLogApi epslogAPI = new EPSLogApi(appSettings, fakeRepo); var localizer = new MockStringLocalizer <EPSLogController>(); localizer[0] = new LocalizedString("EPSLogDateRangeError", "Date range should not be greater than 62 days"); EPSLogController controller = FakeController(_cache, epslogAPI, localizer); var epslogs = await controller.Get("2017-04-01", "2017-07-01", null, null); var actualResult = ((Microsoft.AspNetCore.Mvc.ObjectResult)epslogs); Assert.Equal(actualResult.StatusCode, (int)System.Net.HttpStatusCode.BadRequest); Assert.Equal(actualResult.Value, "Date range should not be greater than 62 days"); }