Exemple #1
0
        public async Task TransactionHistoryControllerTest_Success()
        {
            // Arrange

            string terminalId      = "LK429486";
            string transactionType = "Credit";


            MockTransactionHistoryRepository mockTransactionHistoryRepository = new MockTransactionHistoryRepository();
            ApiResult <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.TransactionHistory> > expectedResult = mockTransactionHistoryRepository.GetMockData(transactionType);
            PaginationTransactionHistory page = mockTransactionHistoryRepository.GetPagination();

            TransactionHistoryInput pageinput = new TransactionHistoryInput();

            pageinput.LIDValue    = terminalId;
            pageinput.lidTypeEnum = Wp.CIS.LynkSystems.Model.Enums.LidTypeEnum.Customer;
            pageinput.Page        = page;

            IDistributedCache   mockCache   = Substitute.For <IDistributedCache>();
            IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >();
            IStringLocalizer <TransactionHistoryController> localizer
                = Substitute.For <IStringLocalizer <TransactionHistoryController> >();

            ILoggingFacade loggingFacade = Substitute.For <ILoggingFacade>();

            IOperation fakeOperation = Substitute.For <Operation>(mockCache);

            fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <ICollection <Wp.CIS.LynkSystems.Model.TransactionHistory> >())).DoNotCallBase();
            fakeOperation.WhenForAnyArgs(x => x.AddCacheAsync(Arg.Any <string>(), Arg.Any <ICollection <Wp.CIS.LynkSystems.Model.TransactionHistory> >())).DoNotCallBase();
            ITransactionHistoryApi terminalListApi = Substitute.For <ITransactionHistoryApi>();

            loggingFacade.WhenForAnyArgs(x => x.LogAsync(Arg.Any <LogLevels>(), Arg.Any <string>(), Arg.Any <CancellationToken>())).DoNotCallBase();

            TransactionHistoryController controller
                = new TransactionHistoryController(mockCache, terminalListApi, localizer, fakeOperation, loggingFacade);

            terminalListApi.GetTransactionHistoryAsync(terminalId, page).ReturnsForAnyArgs(expectedResult);
            // Act
            var terminalList = await controller.GetTransactionHistory(pageinput);

            var    actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).Value;
            string terminalInfo = ((IList <TransactionHistory>)((GenericPaginationResponse <TransactionHistory>)actualRecord).ReturnedRecords)
                                  .Where(x => x.REQ_TRAN_TYPE == transactionType).FirstOrDefault().REQ_AMT;


            // Assert
            var recordCount = ((GenericPaginationResponse <TransactionHistory>)actualRecord).ReturnedRecords;

            Assert.Equal(recordCount.ToList().Count, 1);
            //Assert.Equal(((IList<Wp.CIS.LynkSystems.Model.TransactionHistory>)actualRecord).Count, 1);

            Assert.Equal(terminalInfo, "589587");
        }
Exemple #2
0
        public async Task TransactionHistoryControllerTest_NoDataFound()
        {
            // Arrange
            string terminalId      = "LK429486";
            string transactionType = "Credit";


            MockTransactionHistoryRepository mockTransactionHistoryRepository          = new MockTransactionHistoryRepository();
            ApiResult <GenericPaginationResponse <TransactionHistory> > expectedResult = mockTransactionHistoryRepository.GetMockData(transactionType);
            PaginationTransactionHistory page = mockTransactionHistoryRepository.GetPagination();

            TransactionHistoryInput pageinput = new TransactionHistoryInput();

            pageinput.LIDValue    = terminalId;
            pageinput.lidTypeEnum = Wp.CIS.LynkSystems.Model.Enums.LidTypeEnum.Customer;
            pageinput.Page        = page;

            IDistributedCache   mockCache     = Substitute.For <IDistributedCache>();
            IOptions <Settings> appSettings   = Substitute.For <IOptions <Settings> >();
            IOperation          fakeOperation = Substitute.For <Operation>(mockCache);
            ILoggingFacade      loggingFacade = Substitute.For <ILoggingFacade>();

            IStringLocalizer <TransactionHistoryController> localizer = Substitute.For <IStringLocalizer <TransactionHistoryController> >();
            string key             = "NoDataFound";
            string value           = "No data found for provided ID";
            var    localizedString = new LocalizedString(key, value);

            localizer[Arg.Any <string>()].ReturnsForAnyArgs(localizedString);

            loggingFacade.WhenForAnyArgs(x => x.LogAsync(Arg.Any <LogLevels>(), Arg.Any <string>(), Arg.Any <CancellationToken>())).DoNotCallBase();

            ITransactionHistoryApi terminalListApi = Substitute.For <ITransactionHistoryApi>();


            ApiResult <GenericPaginationResponse <TransactionHistory> > response = new ApiResult <GenericPaginationResponse <TransactionHistory> >();

            response.Result = new GenericPaginationResponse <TransactionHistory>();

            terminalListApi.GetTransactionHistoryAsync(terminalId, page).ReturnsForAnyArgs(response);
            TransactionHistoryController fakecontroller
                = FakeController(mockCache, terminalListApi, localizer, fakeOperation, loggingFacade);


            // Act
            var terminalList = await fakecontroller.GetTransactionHistory(pageinput);

            // Assert

            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).StatusCode, 200);
            var actualTransactionHistory = ((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).Value;

            Assert.Equal(((GenericPaginationResponse <TransactionHistory>)actualTransactionHistory).ModelMessage, localizer["NoDataFound"].Value);
        }
Exemple #3
0
        public async Task <IActionResult> GetTransactionHistory([FromBody] TransactionHistoryInput pageinput)
        {
            try
            {
                await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Web Api call for Transaction History Controller " + pageinput.lidTypeEnum.ToString() + ", Value - "
                                                           + pageinput.LIDValue, "TransactionHistoryController.cs", "GetTransactionHistory"),
                                              CancellationToken.None);

                string terminalId = pageinput.LIDValue;
                PaginationTransactionHistory page = pageinput.Page;

                var key = UniqueCachingKey(pageinput);

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

                    return(BadRequest(ModelState));
                }

                //first check if the data is in cache..
                var data = _operation.RetrieveCache(key, new GenericPaginationResponse <TransactionHistory>());

                if (data == null)
                {
                    await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "calling the GetTransactionHistoryAsync for resultset(Transaction Hostory)  " + pageinput.lidTypeEnum.ToString() + ", Value - "
                                                               + pageinput.LIDValue,
                                                               "TransactionHistoryController.cs", "GetTransactionHistory"), CancellationToken.None);

                    var result = await _transactionHistoryApi.GetTransactionHistoryAsync(terminalId, page);

                    if (result.ErrorMessages.Count == 0)
                    {
                        if (result.Result != null && result.Result.TotalNumberOfRecords > 0)
                        {
                            await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "got the resultset for the GetTransactionHistoryAsync  " + pageinput.lidTypeEnum.ToString() + ", Value - "
                                                                       + pageinput.LIDValue, "TransactionHistoryController.cs",
                                                                       "GetTransactionHistory"), CancellationToken.None);

                            await _operation.AddCacheAsync(key, result.Result);

                            await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Added to Cache for the Terminal List resultset  " + pageinput.lidTypeEnum.ToString() + ", Value - "
                                                                       + pageinput.LIDValue,
                                                                       "TransactionHistoryController.cs", "GetTransactionHistory"), CancellationToken.None);

                            return(Ok(result.Result));
                        }
                        else
                        {
                            var msg = this._localizer["NoDataFound"]?.Value;
                            await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "GetTransactionHistoryAsync No Data Found  " + pageinput.lidTypeEnum.ToString() + ", Value - "
                                                                       + pageinput.LIDValue, "TransactionHistoryController.cs",
                                                                       "GetTransactionHistory"), CancellationToken.None);

                            result.Result.ModelMessage = msg;
                            return(Ok(result.Result));
                        }
                    }
                    else
                    {
                        var msg = this._localizer?["InternalServerError"]?.Value;
                        await _loggingFacade.LogAsync(new LogEntry(LogLevels.Error, "Error Occured  for " + pageinput.lidTypeEnum.ToString() + ", Value - "
                                                                   + pageinput.LIDValue + " " + msg, "TransactionHistoryController.cs",
                                                                   "GetTransactionHistory"), CancellationToken.None);

                        return(this.StatusCode((int)System.Net.HttpStatusCode.InternalServerError, msg));
                    }
                }
                await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "GetTransaction History Got resultset from Cache  " + key + ", Value - "
                                                           + pageinput.LIDValue, "TransactionHistoryController.cs",
                                                           "GetTransactionHistory"), CancellationToken.None);

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

                return(this.StatusCode((int)System.Net.HttpStatusCode.InternalServerError, msg));
            }
        }