Пример #1
0
        public async Task <IActionResult> GetDashBoardInfoSearch(Model.Helper.LIDTypes LIDType, string LID)
        {
            await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Starting Dashboard Info GetDashBoardInfo LIDType : " + LIDType
                                                       + ", LID Value: " + LID, "DashboardInfoController.cs", "GetDashBoardInfo"), CancellationToken.None);

            if (!ModelState.IsValid)
            {
                await _loggingFacade.LogAsync(new LogEntry(LogLevels.Error, ModelState.ToString(), "DashboardInfoController.cs", "GetDashBoardInfo"), CancellationToken.None);

                return(BadRequest(ModelState));
            }

            try
            {
                string key  = "dashboardInfo_" + "_" + LIDType + "_" + LID.ToString();
                var    data = _operation.RetrieveCache(key, new DashboardInfo());

                if (data == null)
                {
                    //since no data in cache, now get data from DB
                    await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Before Database call of Service's method (GetDashboardSearchResultsPagination) for LIDType "
                                                               + LIDType + " LID Value " + LID, "DashboardInfoController.cs", "Get"), CancellationToken.None);

                    //call the Services for Data Retrieval from Database.
                    var result = await _dashboardInfo.GetDashboardSearchResultsPagination(LIDType, Convert.ToInt32(LID));

                    await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "After Database call of Service's method (GetDashboardSearchResultsPagination) for LIDType "
                                                               + LIDType + " LID Value " + LID, "DashboardInfoController.cs", "Get"), CancellationToken.None);


                    data = result.Result;
                    //Now add data to cache..
                    await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Adding into the Cache with Cache Key " + key,
                                                               "DashboardInfoController.cs", "Get"), CancellationToken.None);

                    await _operation.AddCacheAsync(key, data);
                }
                if (data == null)
                {
                    var msg = this._localizer["NoDataFound"]?.Value;
                    await _loggingFacade.LogAsync(new LogEntry(LogLevels.Error, msg, "DashboardInfoController.cs", "Get"), CancellationToken.None);

                    return(this.StatusCode((int)System.Net.HttpStatusCode.OK, msg));
                }
                else
                {
                    await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Retrieved the Data from the Cache with Cache Key " + key,
                                                               "DashboardInfoController.cs", "Get"), CancellationToken.None);

                    return(Ok(data));
                }
            }
            catch (Exception ex)
            {
                var msg = this._localizer?["GetDashboardInfoErrorMessage"]?.Value;
                await _loggingFacade.LogExceptionAsync(ex, this.HttpContext?.Request?.Headers["UserName"], LogLevels.Error, "Error in GetDashBoardInfoSearch()", CancellationToken.None);

                return(this.StatusCode((int)System.Net.HttpStatusCode.InternalServerError, msg));
            }
        }
Пример #2
0
        public async Task DashboardInfoControllerTest_GetDashBoardInfoSearch_Success()
        {
            // Arrange
            int lid = 589547;
            MockDashboardInfoRepository repository = new MockDashboardInfoRepository();
            var expectedResult = repository.GetMockCustomerData();

            IDashboardInfoRepository mockRepo = FakeRepository();
            IDistributedCache        _cache   = FakeCache();
            IOperation        fakeOperation   = FakeOperation(_cache);
            ILoggingFacade    fakeLogger      = FakeLogger();
            IDashboardInfoApi dAPI            = Substitute.For <IDashboardInfoApi>();

            dAPI.GetDashboardSearchResultsPagination(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.CustomerNbr, lid).ReturnsForAnyArgs(expectedResult);
            DashboardInfoController controller = FakeController(dAPI, mockRepo, _cache, fakeOperation, fakeLogger);
            // Act
            var dinfo = await controller.GetDashBoardInfoSearch(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.CustomerNbr, Convert.ToString(lid));

            var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).Value;

            // Assert
            Assert.Equal(((Wp.CIS.LynkSystems.Model.DashboardInfo)actualRecord).DemographicsInfoCust, repository.custDemographicsList);
        }