예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="TerminalID"></param>
        /// <returns></returns>
        public async Task <ApiResult <GenericPaginationResponse <Terminal> > > GetTerminalListAsync(int merchantID, PaginationTerminal Page)
        {
            await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Starting Terminal List GetTerminalListAsync for MerchantID - " + merchantID,
                                                       "TerminalListApi.cs", "GetTerminalListAsync"), CancellationToken.None);

            ApiResult <GenericPaginationResponse <Terminal> > response = new ApiResult <GenericPaginationResponse <Terminal> >();
            var errorkey = GlobalErrorCode.Succeeded;

            try
            {
                response.Result = await _terminalRepository.GetTerminalListAsync(merchantID, Page);

                await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "fteched Terminal List resultset from DB for MerchantID - " + merchantID,
                                                           "TerminalListApi.cs", "GetTerminalListAsync"), CancellationToken.None);

                return(response);
            }
            catch (Exception ex)
            {
                errorkey = GlobalErrorCode.InternalServerError;
                await _loggingFacade.LogAsync(new LogEntry(LogLevels.Error, "Error Occured  for MerchantID - " + merchantID + " " + errorkey.ToString() + ex.Message, "TerminalListApi.cs",
                                                           "GetTerminalListAsync"), CancellationToken.None);

                response.AddErrorMessage(errorkey.ToString());
                return(response);
            }
        }
예제 #2
0
        public async Task <ApiResult <bool> > CreateVersion(CommanderVersion commanderVersion)
        {
            ApiResult <bool> response = new ApiResult <bool>();

            try
            {
                bool   isValid           = false;
                string regularExpression = @"^[A-Z\s.0-9#$*()?!+_-]{1,20}$";
                Regex  regex             = new Regex(regularExpression, RegexOptions.Singleline);
                Match  m = regex.Match(commanderVersion.VersionDescription);
                isValid = m.Success;
                if (isValid)
                {
                    response.Result = await _commanderVersionRepository.CreateVersionAsync(commanderVersion);
                }
                else
                {
                    response.AddErrorMessage(CommanderVersionErrorCodes.CommanderCreateversionsVersionFormatErrorMsg.ToString());
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(response);
        }
예제 #3
0
        public async Task CaseHistoryControllerTest_APICallHasErrorMessage()
        {
            // Arrange
            var    page    = GetCaseHistoryObject();
            string ExtraId = null;



            MockCaseHistoryRepository mockCaseHistoryRepository = new MockCaseHistoryRepository();
            ApiResult <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory> > expectedResult = mockCaseHistoryRepository.GetMockData(648988);

            IDistributedCache mockCache = Substitute.For <IDistributedCache>();


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

            fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory> >())).DoNotCallBase();

            IStringLocalizer <CaseHistoryController> localizer = Substitute.For <IStringLocalizer <CaseHistoryController> >();

            string key             = "InternalServerError";
            string value           = "Some Server Error Occurs while retrieving the data";
            var    localizedString = new LocalizedString(key, value);

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


            ICaseHistoryApi caseHistoryApi = Substitute.For <ICaseHistoryApi>();

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

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


            CaseHistoryController controller = new CaseHistoryController(mockCache, caseHistoryApi, localizer, fakeOperation, loggingFacade);


            ApiResult <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory> > response = new ApiResult <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory> >();

            response.Result = new GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory>();

            var errorkey = GlobalErrorCode.InternalServerError;

            response.AddErrorMessage(errorkey.ToString());


            caseHistoryApi.GetCaseHistory(page.lidTypeEnum, page.LIDValue, ExtraId, page.Page).ThrowsForAnyArgs(new Exception());

            // Act

            var casehistoryList = await controller.Get(page);

            // Assert

            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)casehistoryList).StatusCode, 500);

            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)casehistoryList).Value, localizer["InternalServerError"].Value);
        }
예제 #4
0
        public async Task ContactListControllerTest_APICallHasErrorMessage()
        {
            // Arrange
            var page = GetContactListObject();

            string             ssn = "3425";
            IConfigurationRoot configurationRoot = Substitute.For <IConfigurationRoot>();

            configurationRoot = GetConfiguration(configurationRoot);
            MockContactListRepository mockContactListRepository = new MockContactListRepository();
            ApiResult <GenericPaginationResponse <Demographics> > expectedResult = mockContactListRepository.GetMockData(ssn);
            ILoggingFacade loggingFacade = Substitute.For <ILoggingFacade>();

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

            IDistributedCache mockCache = Substitute.For <IDistributedCache>();

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

            fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <ICollection <Demographics> >())).DoNotCallBase();

            IStringLocalizer <ContactListController> localizer
                = Substitute.For <IStringLocalizer <ContactListController> >();
            string key             = "InternalServerError";
            string value           = "Some Server Error Occurs while retrieving the data";
            var    localizedString = new LocalizedString(key, value);

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

            IContactListApi contactListApi = Substitute.For <IContactListApi>();

            ContactListController controller
                = new ContactListController(mockCache, contactListApi, localizer, fakeOperation, loggingFacade);


            ApiResult <GenericPaginationResponse <Demographics> > response = new ApiResult <GenericPaginationResponse <Demographics> >();
            var errorkey = GlobalErrorCode.InternalServerError;

            response.AddErrorMessage(errorkey.ToString());
            contactListApi.GetContactListAsync(page.lidTypeEnum, page.LIDValue, page.Page).ReturnsForAnyArgs(response);;



            // Act
            var contactList = await controller.GetContactList(page);

            // Assert

            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)contactList).StatusCode, 500);

            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)contactList).Value, localizer["InternalServerError"].Value);
        }
예제 #5
0
        public async Task <ApiResult <ICollection <EPSPetroAudit> > > GetEPSPetroAuditByVersion(int versionID, string startDate, string endDate)
        {
            ApiResult <ICollection <EPSPetroAudit> > response = new ApiResult <ICollection <EPSPetroAudit> >();

            try
            {
                var errorkey = EPSPetroAuditErrorCodes.Succeeded;
                if (versionID <= 0)
                {
                    errorkey = EPSPetroAuditErrorCodes.InValidVersionIdError;
                }
                else if (string.IsNullOrEmpty(startDate) || string.IsNullOrEmpty(endDate))
                {
                    errorkey = EPSPetroAuditErrorCodes.DatesErrorMsg;
                }
                else if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
                {
                    DateTime start;
                    DateTime.TryParse(startDate, out start);
                    DateTime end;
                    DateTime.TryParse(endDate, out end);
                    if ((end - start).TotalDays > 30)
                    {
                        errorkey = EPSPetroAuditErrorCodes.DateRangeError;
                    }
                }

                if (errorkey == EPSPetroAuditErrorCodes.Succeeded)
                {
                    response.Result = await _epsPetroAuditRepository.GetEPSPetroAuditsAsync(versionID, startDate, endDate);
                }
                else
                {
                    response.AddErrorMessage(errorkey.ToString());
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(response);
        }
예제 #6
0
        public async Task <ApiResult <ICollection <EPSPetroAuditDetails> > > GetEPSPetroAuditDetails(int auditID)
        {
            ApiResult <ICollection <EPSPetroAuditDetails> > response = new ApiResult <ICollection <EPSPetroAuditDetails> >();

            try
            {
                if (auditID <= 0)
                {
                    response.AddErrorMessage(EPSPetroAuditErrorCodes.InValidAuditIdError.ToString());
                }
                else
                {
                    response.Result = await _epsPetroAuditRepository.GetEPSPetroAuditDetailsAsync(auditID);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(response);
        }
예제 #7
0
        public async Task <ApiResult <ICollection <EPSLog> > > GetEPSLogAsync(string startDate, string endDate, int?LidType, string Lid)
        {
            ApiResult <ICollection <EPSLog> > response = new ApiResult <ICollection <EPSLog> >();
            var errorkey = EPSLogErrorCodes.Succeeded;

            try
            {
                if (string.IsNullOrEmpty(startDate) || string.IsNullOrEmpty(endDate))
                {
                    errorkey = EPSLogErrorCodes.EPSLogDateRangeError;
                }
                else if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
                {
                    DateTime start = Convert.ToDateTime(startDate);
                    DateTime end   = Convert.ToDateTime(endDate);
                    if ((end - start).TotalDays > 62)
                    {
                        errorkey = EPSLogErrorCodes.EPSLogDateRangeError;
                    }
                }


                if (errorkey == EPSLogErrorCodes.Succeeded)
                {
                    response.Result = await _epsLogRepository.GetEPSLogAsync(startDate, endDate, LidType, Lid);
                }
                else
                {
                    response.AddErrorMessage(errorkey.ToString());
                }
            }
            catch
            {
                throw;
            }

            return(response);
        }