public async Task <IActionResult> GetTerminalDetails(int termNbr) { await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Starting Dashboard Info GetTerminalDetails ", "DashboardInfoController.cs", "GetTerminalDetails"), CancellationToken.None); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { string key = "terminalDetails_" + termNbr.ToString(); var data = _operation.RetrieveCache(key, new TerminalDetails()); if (data == null) { //since no data in cache, now get data from DB var result = await _dashboardInfo.GetTerminalDetails(termNbr); data = result.Result; //Now add data to cache.. await _operation.AddCacheAsync(key, data); } if (data == null) { var msg = this._localizer["NoDataFound"]?.Value; return(this.StatusCode((int)System.Net.HttpStatusCode.OK, msg)); } await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Dashboard Info GetTerminalDetails Successful ", "DashboardInfoController.cs", "GetTerminalDetails"), CancellationToken.None); return(Ok(data)); } catch (Exception ex) { var msg = this._localizer?["GenericError"]?.Value; await _loggingFacade.LogExceptionAsync(ex, this.HttpContext?.Request?.Headers["UserName"], LogLevels.Error, "Error in DashboardInfoGetTerminalDetails()", CancellationToken.None); return(this.StatusCode((int)System.Net.HttpStatusCode.InternalServerError, msg)); } }
public async Task DashboardInfoControllerTest_TerminalDetailsAccountSuccess() { // Arrange int lid = 588799; MockDashboardInfoRepository repository = new MockDashboardInfoRepository(); var expectedResult = repository.GetMockTerminalDetails(); IDashboardInfoRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); IOperation fakeOperation = FakeOperation(_cache); ILoggingFacade fakeLogger = FakeLogger(); IDashboardInfoApi dAPI = Substitute.For <IDashboardInfoApi>(); dAPI.GetTerminalDetails(lid).ReturnsForAnyArgs(expectedResult); DashboardInfoController controller = FakeController(dAPI, mockRepo, _cache, fakeOperation, fakeLogger); // Act var dinfo = await controller.GetTerminalDetails(lid); var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).Value; // Assert Assert.Equal(((Wp.CIS.LynkSystems.Model.TerminalDetails)actualRecord), expectedResult.Result); }