Beispiel #1
0
        public async Task TerminalListApiTest_GetAnException_Old()
        {
            // Arrange
            string TerminalNbr = "589587";

            MockTerminalListRepository          mockTerminalListRepository = new MockTerminalListRepository();
            ApiResult <ICollection <Terminal> > expectedResult             = mockTerminalListRepository.GetMockData(TerminalNbr);
            IOptions <Settings>     optionsAccessor = Substitute.For <IOptions <Settings> >();
            ITerminalListRepository mockRepo        = Substitute.For <ITerminalListRepository>();

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

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

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

            terminalListApi.WhenForAnyArgs(x => x.GetTerminalListAsync(Arg.Any <int>())).DoNotCallBase();
            mockRepo.GetTerminalListAsync(Convert.ToInt32(TerminalNbr)).Throws(new Exception());

            terminalListApi = new TerminalListApi(optionsAccessor, mockRepo, loggingFacade);

            //Assert
            await Assert.ThrowsAsync <Exception>(() => terminalListApi.GetTerminalListAsync(Convert.ToInt32(TerminalNbr)));
        }
Beispiel #2
0
        //Would be revisiting to modify the actual way of call method.
        public void TestTerminalListRepositoryTest_Success_Old()
        {
            // Arrange
            string terminalNbr = "589587";
            string tid         = "LK429486";


            MockTerminalListRepository          mockTerminalListRepository = new MockTerminalListRepository();
            ApiResult <ICollection <Terminal> > expectedResult             = mockTerminalListRepository.GetMockData(terminalNbr);
            ILoggingFacade loggingFacade = Substitute.For <ILoggingFacade>();

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

            IOptions <DataContext>     optionsAccessor   = Substitute.For <IOptions <DataContext> >();
            IDatabaseConnectionFactory connectionFactory = Substitute.For <IDatabaseConnectionFactory>();
            ITerminalListRepository    mockRepo          = Substitute.For <ITerminalListRepository>();


            mockRepo.GetTerminalListAsync(Convert.ToInt32(terminalNbr)).ReturnsForAnyArgs(expectedResult.Result);


            // Act
            var    merchList    = mockRepo.GetTerminalListAsync(Convert.ToInt32(terminalNbr)).Result;
            var    actualRecord = (IList <Wp.CIS.LynkSystems.Model.Terminal>)merchList;
            string merchInfo    = actualRecord.Where(x => x.TerminalID == tid).FirstOrDefault().Software;


            //// Assert

            Assert.Equal(((IList <Terminal>)actualRecord).Count, 1);

            Assert.Equal(merchInfo, "LSPR3271");
        }
Beispiel #3
0
        public async Task MerchantListApiTest_Exception()
        {
            // Arrange
            int CustomerID = 191809;

            MockMerchantListRepository mockMerchantListRepository            = new MockMerchantListRepository();
            ApiResult <GenericPaginationResponse <Merchant> > expectedResult = mockMerchantListRepository.GetMockData(CustomerID);
            PaginationMerchant page = mockMerchantListRepository.GetPagination();

            IOptions <Settings>     optionsAccessor = Substitute.For <IOptions <Settings> >();
            IMerchantListRepository mockRepo        = Substitute.For <IMerchantListRepository>();
            IMerchantListApi        merchantListApi = Substitute.For <IMerchantListApi>();
            IDistributedCache       mockCache       = Substitute.For <IDistributedCache>();
            ILoggingFacade          loggingFacade   = Substitute.For <ILoggingFacade>();

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

            mockRepo.GetMerchantListAsync(CustomerID, page).Throws(new Exception());


            merchantListApi = new MerchantListApi(optionsAccessor, mockRepo, loggingFacade);


            //Assert
            await Assert.ThrowsAsync <Exception>(() => merchantListApi.GetMerchantListAsync(CustomerID, page));
        }
        //Would be revisiting to modify the actual way of call method.
        public void TestTransactionHistoryRepositoryTest_Success()
        {
            // Arrange
            string terminalId      = "LK429486";
            string transactionType = "Credit";

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

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

            IOptions <DataContext>        optionsAccessor   = Substitute.For <IOptions <DataContext> >();
            IDatabaseConnectionFactory    connectionFactory = Substitute.For <IDatabaseConnectionFactory>();
            ITransactionHistoryRepository mockRepo          = Substitute.For <ITransactionHistoryRepository>();


            mockRepo.GetTransactionHistoryAsync(terminalId, page).ReturnsForAnyArgs(expectedResult.Result);


            // Act
            var    terminalList = mockRepo.GetTransactionHistoryAsync(terminalId, page).Result;
            var    actualRecord = (IList <TransactionHistory>)terminalList.ReturnedRecords;
            string merchInfo    = actualRecord.Where(x => x.REQ_TRAN_TYPE == transactionType).FirstOrDefault().REQ_AMT;


            //// Assert

            Assert.Equal(((IList <TransactionHistory>)actualRecord).Count, 1);

            Assert.Equal(merchInfo, "589587");
        }
Beispiel #5
0
        public void ContactListControllerTest_ModelState_Invalid()
        {
            //Arrange

            var page = GetContactListObject();

            string ssn = "3425";

            MockContactListRepository mockContactListRepository = new MockContactListRepository();
            ApiResult <GenericPaginationResponse <Demographics> > expectedResult = mockContactListRepository.GetMockData(ssn);

            IStringLocalizer <ContactListController> localizer
                = Substitute.For <IStringLocalizer <ContactListController> >();
            ILoggingFacade loggingFacade = Substitute.For <ILoggingFacade>();

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

            IDistributedCache mockCache     = FakeCache();
            IOperation        fakeOperation = Substitute.ForPartsOf <Operation>(mockCache);

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


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

            //Act
            controller.ModelState.AddModelError("key", "error message");
            var result = controller.GetContactList(page);

            //Assert
            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)result.Result).StatusCode.ToString(), "400");
        }
Beispiel #6
0
        //UnitTest for validating the Invalid Model Data.
        public void TerminalListController_ModelState_Invalid_Old()
        {
            //Arrange
            string TerminalNbr = "589587";

            MockTerminalListRepository          mockTerminalListRepository = new MockTerminalListRepository();
            ApiResult <ICollection <Terminal> > expectedResult             = mockTerminalListRepository.GetMockData(TerminalNbr);

            IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >();

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

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

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

            IDistributedCache mockCache       = FakeCache();
            ITerminalListApi  terminalListApi = Substitute.For <ITerminalListApi>();
            IOperation        fakeOperation   = Substitute.For <Operation>(mockCache);

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

            //Act
            controller.ModelState.AddModelError("key", "error message");
            var result = controller.GetTerminalList(Convert.ToInt32(TerminalNbr));

            //Assert
            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)result.Result).StatusCode.ToString(), "400");
        }
        //Would be revisiting to modify the actual way of call method.
        public void MerchantListRepositoryTest_Success()
        {
            // Arrange
            int    CustomerID = 191809;
            string mid        = "191807";


            MockMerchantListRepository mockMerchantListRepository            = new MockMerchantListRepository();
            ApiResult <GenericPaginationResponse <Merchant> > expectedResult = mockMerchantListRepository.GetMockData(CustomerID);
            PaginationMerchant page = mockMerchantListRepository.GetPagination();

            IOptions <DataContext>     optionsAccessor   = Substitute.For <IOptions <DataContext> >();
            IDatabaseConnectionFactory connectionFactory = Substitute.For <IDatabaseConnectionFactory>();
            IMerchantListRepository    mockRepo          = Substitute.For <IMerchantListRepository>();
            ILoggingFacade             loggingFacade     = Substitute.For <ILoggingFacade>();

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

            mockRepo.GetMerchantListAsync(CustomerID, page).ReturnsForAnyArgs(expectedResult.Result);

            // Act
            var    merchList    = mockRepo.GetMerchantListAsync(CustomerID, page).Result;
            var    actualRecord = (IList <Wp.CIS.LynkSystems.Model.Merchant>)merchList.ReturnedRecords;
            string merchInfo    = actualRecord.Where(x => x.MID == mid).FirstOrDefault().Name;


            //// Assert

            Assert.Equal(((IList <Merchant>)actualRecord).Count, 2);

            Assert.Equal(merchInfo, "ABC Corp");
        }
Beispiel #8
0
        ///Unit Test for the RetrieveCache()
        public async Task MerchantListControllerTest_GetDataFromCache_Old()
        {
            string TerminalNbr = "589587";
            MockTerminalListRepository mockTerminalListRepository = new MockTerminalListRepository();

            ApiResult <ICollection <Terminal> > expectedResult = mockTerminalListRepository.GetMockData(TerminalNbr);

            IDistributedCache       mockCache = Substitute.For <IDistributedCache>();
            ITerminalListRepository mockRepo  = Substitute.For <ITerminalListRepository>();
            IStringLocalizer <TerminalListController> localizer
                = Substitute.For <IStringLocalizer <TerminalListController> >();
            ITerminalListApi mockTerminalListApi = Substitute.For <ITerminalListApi>();

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

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

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

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

            fakeOperation.RetrieveCache("FakeStringID", new List <Terminal>()).ReturnsForAnyArgs(expectedResult.Result);

            TerminalListController controller = new TerminalListController(mockCache, mockTerminalListApi, localizer, fakeOperation, loggingFacade);


            //ACT
            var terminalList = await controller.GetTerminalList(Convert.ToInt32(TerminalNbr));

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

            //Assert
            Assert.Equal(JsonConvert.SerializeObject(actualRecord), JsonConvert.SerializeObject(expectedResult.Result));
        }
Beispiel #9
0
        public async Task TransactionHistoryApiTest_GetAnException()
        {
            // Arrange
            string terminalId      = "LK429486";
            string transactionType = "Credit";
            MockTransactionHistoryRepository mockTransactionHistoryRepository          = new MockTransactionHistoryRepository();
            ApiResult <GenericPaginationResponse <TransactionHistory> > expectedResult = mockTransactionHistoryRepository.GetMockData(transactionType);
            PaginationTransactionHistory page = mockTransactionHistoryRepository.GetPagination();

            IOptions <Settings>           optionsAccessor = Substitute.For <IOptions <Settings> >();
            ITransactionHistoryRepository mockRepo        = Substitute.For <ITransactionHistoryRepository>();

            IDistributedCache      mockCache       = Substitute.For <IDistributedCache>();
            ILoggingFacade         loggingFacade   = Substitute.For <ILoggingFacade>();
            ITransactionHistoryApi terminalListApi = Substitute.For <ITransactionHistoryApi>();

            terminalListApi.WhenForAnyArgs(x => x.GetTransactionHistoryAsync(Arg.Any <string>(), Arg.Any <PaginationTransactionHistory>())).DoNotCallBase();
            mockRepo.GetTransactionHistoryAsync(terminalId, page).Throws(new Exception());

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

            terminalListApi = new TransactionHistoryApi(optionsAccessor, mockRepo, loggingFacade);


            // Assert

            await Assert.ThrowsAsync <Exception>(() => terminalListApi.GetTransactionHistoryAsync(terminalId, page));
        }
Beispiel #10
0
        public async Task TerminalListApiTest_GetAnException()
        {
            // Arrange
            int TerminalNbr = 589587;

            MockTerminalListRepository mockTerminalListRepository            = new MockTerminalListRepository();
            ApiResult <GenericPaginationResponse <Terminal> > expectedResult = mockTerminalListRepository.GetMockData(TerminalNbr);
            PaginationTerminal page = mockTerminalListRepository.GetPagination();

            IOptions <Settings>     optionsAccessor = Substitute.For <IOptions <Settings> >();
            ITerminalListRepository mockRepo        = Substitute.For <ITerminalListRepository>();

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

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

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

            terminalListApi.WhenForAnyArgs(x => x.GetTerminalListAsync(Arg.Any <int>(), Arg.Any <PaginationTerminal>())).DoNotCallBase();
            mockRepo.GetTerminalListAsync(TerminalNbr, page).Throws(new Exception());

            terminalListApi = new TerminalListApi(optionsAccessor, mockRepo, loggingFacade);


            // Act
            var terminalList = await terminalListApi.GetTerminalListAsync(TerminalNbr, page);

            // Assert
            Assert.Equal(((IList <string>)terminalList.ErrorMessages).First(), "InternalServerError");
        }
Beispiel #11
0
        public async Task ContactListApiTest_Exception()
        {
            // Arrange
            LidTypeEnum            LIDType = LidTypeEnum.CustomerNbr;
            string                 LID     = "";
            PaginationDemographics page    = new PaginationDemographics();

            string ssn = "3425";
            MockContactListRepository mockContactListRepository = new MockContactListRepository();
            ApiResult <GenericPaginationResponse <Demographics> > expectedResult = mockContactListRepository.GetMockData(ssn);

            ILoggingFacade      loggingFacade   = Substitute.For <ILoggingFacade>();
            IOptions <Settings> optionsAccessor = Substitute.For <IOptions <Settings> >();

            IContactListRepository mockRepo       = Substitute.For <IContactListRepository>();
            IContactListApi        contactListApi = Substitute.For <IContactListApi>();
            IDistributedCache      mockCache      = Substitute.For <IDistributedCache>();

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

            mockRepo.GetContactListAsync(LIDType, LID, page).Throws(new Exception());


            contactListApi = new ContactListApi(optionsAccessor, mockRepo, loggingFacade);

            //Assert
            await Assert.ThrowsAsync <Exception>(() => contactListApi.GetContactListAsync(LIDType, LID, page));
        }
Beispiel #12
0
        //Would be revisiting to modify the actual way of call method.
        public void ContactListRepositoryTest_Success()
        {
            // Arrange
            LidTypeEnum LIDType = LidTypeEnum.CustomerNbr;
            string      LID     = "";

            PaginationDemographics page = new PaginationDemographics();

            int    NameAddressID = 3301636;
            string ssn           = "3425";

            MockContactListRepository mockContactListRepository = new MockContactListRepository();
            ApiResult <GenericPaginationResponse <Demographics> > expectedResult = mockContactListRepository.GetMockData(ssn);

            IOptions <DataContext>     optionsAccessor   = Substitute.For <IOptions <DataContext> >();
            IDatabaseConnectionFactory connectionFactory = Substitute.For <IDatabaseConnectionFactory>();
            IContactListRepository     mockRepo          = Substitute.For <IContactListRepository>();
            ILoggingFacade             loggingFacade     = Substitute.For <ILoggingFacade>();

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

            mockRepo.GetContactListAsync(LIDType, LID, page).ReturnsForAnyArgs(expectedResult.Result);

            // Act
            var    contactList  = mockRepo.GetContactListAsync(LIDType, LID, page).Result;
            var    actualRecord = (IList <Wp.CIS.LynkSystems.Model.Demographics>)contactList.ReturnedRecords;
            string contactInfo  = actualRecord.Where(x => x.NameAddressID == NameAddressID).FirstOrDefault().Name;


            //// Assert

            Assert.Equal(((IList <Demographics>)actualRecord).Count, 3);

            Assert.Equal(contactInfo, "Golden Corral Corporation");
        }
Beispiel #13
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);
        }
Beispiel #14
0
        //Mock API Call and unit test for the API call with returning mock ContactList.
        public async Task CaseHistoryControllerTest_Success()
        {
            // Arrange
            var page = GetCaseHistoryObject();

            page.lidTypeEnum = LidTypeEnum.Terminal;
            page.LIDValue    = "FakeStringID";

            int    lid     = 648988;
            int    CaseID  = 8715123;
            string ExtraId = null;

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


            ICaseHistoryRepository mockRepo = Substitute.For <ICaseHistoryRepository>();


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

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

            IDistributedCache mockCache     = FakeCache();
            IOperation        fakeOperation = Substitute.ForPartsOf <Operation>(mockCache);


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

            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);

            caseHistoryApi.GetCaseHistory(page.lidTypeEnum, page.LIDValue, ExtraId, page.Page).ReturnsForAnyArgs(expectedResult);

            // Act

            var casehistory = await controller.Get(page);

            var    actualRecord    = ((Microsoft.AspNetCore.Mvc.ObjectResult)casehistory).Value;
            string casehistoryInfo = ((IList <Wp.CIS.LynkSystems.Model.CaseHistory>)
                                          ((GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory>)actualRecord).ReturnedRecords).Where(x => x.caseId == CaseID).FirstOrDefault().orgDeptName;

            var recordCount = ((GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory>)actualRecord).ReturnedRecords;


            // Assert
            Assert.Equal(recordCount.ToList().Count, 6);


            Assert.Equal(casehistoryInfo, "Customer Care");
        }
Beispiel #15
0
        public async Task MerchantListControllerTest_NoDataFound()
        {
            // Arrange
            int CustomerID = 191809;

            IConfigurationRoot configurationRoot = Substitute.For <IConfigurationRoot>();

            configurationRoot = GetConfiguration(configurationRoot);
            MockMerchantListRepository mockMerchantListRepository            = new MockMerchantListRepository();
            ApiResult <GenericPaginationResponse <Merchant> > expectedResult = mockMerchantListRepository.GetMockData(CustomerID);
            PaginationMerchant page      = mockMerchantListRepository.GetPagination();
            MerchantListInput  pageinput = new MerchantListInput();

            pageinput.LIDValue    = CustomerID.ToString();
            pageinput.lidTypeEnum = Wp.CIS.LynkSystems.Model.Enums.LidTypeEnum.Customer;
            pageinput.Page        = page;
            IDistributedCache mockCache = Substitute.For <IDistributedCache>();

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

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

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

            loggingFacade.WhenForAnyArgs(x => x.LogAsync(Arg.Any <LogLevels>(), Arg.Any <string>(), Arg.Any <CancellationToken>())).DoNotCallBase();
            IMerchantListApi merchantListApi = Substitute.For <IMerchantListApi>();
            IOperation       fakeOperation   = Substitute.For <Operation>(mockCache);

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

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

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


            merchantListApi.GetMerchantListAsync(CustomerID, page).ReturnsForAnyArgs(response);
            MerchantListController controller
                = new MerchantListController(mockCache, merchantListApi, localizer, fakeOperation, loggingFacade);


            // Act
            var merchList = await controller.GetMerchantList(pageinput);

            // Assert

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

            Assert.Equal(((GenericPaginationResponse <Merchant>)actualMerchantList).ModelMessage, localizer["NoDataFound"].Value);
        }
Beispiel #16
0
        public async Task ContactListControllerTest_NoDataFound()
        {
            // Arrange

            var page = GetContactListObject();

            page.lidTypeEnum = LidTypeEnum.Terminal;

            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>();

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

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

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

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

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

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


            contactListApi.GetContactListAsync(page.lidTypeEnum, page.LIDValue, page.Page).ReturnsForAnyArgs(response);
            ContactListController controller
                = new ContactListController(mockCache, contactListApi, localizer, fakeOperation, loggingFacade);


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

            // Assert

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

            var actualContactList = ((Microsoft.AspNetCore.Mvc.ObjectResult)contactList).Value;

            Assert.Equal(((GenericPaginationResponse <Demographics>)actualContactList).ModelMessage, localizer["NoDataFound"].Value);
        }
Beispiel #17
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");
        }
Beispiel #18
0
        public async Task TerminalListControllerTest_NoDataFound()
        {
            // Arrange
            int TerminalNbr = 589587;


            MockTerminalListRepository mockTerminalListRepository            = new MockTerminalListRepository();
            ApiResult <GenericPaginationResponse <Terminal> > expectedResult = mockTerminalListRepository.GetMockData(TerminalNbr);
            PaginationTerminal page = mockTerminalListRepository.GetPagination();

            TerminalListInput pageinput = new TerminalListInput();

            pageinput.LIDValue    = TerminalNbr.ToString();
            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>();

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

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

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


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


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

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

            terminalListApi.GetTerminalListAsync(TerminalNbr, page).ReturnsForAnyArgs(response);
            TerminalListController fakecontroller
                = FakeController(mockCache, terminalListApi, localizer, fakeOperation, loggingFacade);


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

            // Assert

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

            Assert.Equal(((GenericPaginationResponse <Terminal>)actualTerminalList).ModelMessage, localizer["NoDataFound"].Value);
        }
Beispiel #19
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);
        }
Beispiel #20
0
        public async Task CaseHistoryControllerTest_FailToRetrieveData()
        {
            // Arrange
            var page = GetCaseHistoryObject();

            page.lidTypeEnum = LidTypeEnum.Terminal;

            int    lid     = 648988;
            string ExtraId = null;

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

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

            IDistributedCache mockCache     = FakeCache();
            IOperation        fakeOperation = Substitute.ForPartsOf <Operation>(mockCache);



            string key   = "NoDataFound";
            string value = "No data found for provided ID";

            var localizedString = new LocalizedString(key, value);

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

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

            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>();

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

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

            casehistoryApi.GetCaseHistory(page.lidTypeEnum, page.LIDValue, ExtraId, page.Page).ReturnsForAnyArgs(response);
            CaseHistoryController controller = new CaseHistoryController(mockCache, casehistoryApi, localizer, fakeOperation, loggingFacade);


            // Act
            var casehisotryList = await controller.Get(page);

            // Assert

            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)casehisotryList).StatusCode, 200);
        }
Beispiel #21
0
        //Mock API Call and unit test for the API call with returning mock MerchantList.
        public async Task MerchantListControllerTest_Success()
        {
            // Arrange
            int    CustomerID = 191809;
            string mid        = "191807";

            IConfigurationRoot configurationRoot = Substitute.For <IConfigurationRoot>();

            configurationRoot = GetConfiguration(configurationRoot);
            MockMerchantListRepository mockMerchantListRepository            = new MockMerchantListRepository();
            ApiResult <GenericPaginationResponse <Merchant> > expectedResult = mockMerchantListRepository.GetMockData(CustomerID);
            PaginationMerchant page      = mockMerchantListRepository.GetPagination();
            MerchantListInput  pageinput = new MerchantListInput();

            pageinput.LIDValue    = CustomerID.ToString();
            pageinput.lidTypeEnum = Wp.CIS.LynkSystems.Model.Enums.LidTypeEnum.Customer;
            pageinput.Page        = page;

            IDistributedCache       mockCache = Substitute.For <IDistributedCache>();
            IMerchantListRepository mockRepo  = Substitute.For <IMerchantListRepository>();
            IStringLocalizer <MerchantListController> localizer
                = Substitute.For <IStringLocalizer <MerchantListController> >();
            IMerchantListApi mockMerchantListApi = Substitute.For <IMerchantListApi>();
            ILoggingFacade   loggingFacade       = Substitute.For <ILoggingFacade>();

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

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

            fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <GenericPaginationResponse <Merchant> >())).DoNotCallBase();
            fakeOperation.WhenForAnyArgs(x => x.AddCacheAsync(Arg.Any <string>(), Arg.Any <GenericPaginationResponse <Merchant> >())).DoNotCallBase();
            MerchantListController controller = new MerchantListController(mockCache, mockMerchantListApi, localizer, fakeOperation, loggingFacade);

            mockMerchantListApi.GetMerchantListAsync(CustomerID, page).ReturnsForAnyArgs(expectedResult);
            // Act
            var merchList = await controller.GetMerchantList(pageinput);

            var    actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)merchList).Value;
            string merchInfo    = ((IList <Merchant>)((GenericPaginationResponse <Merchant>)actualRecord).ReturnedRecords).Where(x => x.MID == mid).FirstOrDefault().Name;


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

            Assert.Equal(recordCount.ToList().Count, 2);


            Assert.Equal(merchInfo, "ABC Corp");
        }
Beispiel #22
0
        public async Task TransactionHistoryControllerTest_GetAnException()
        {
            // 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> >();

            IStringLocalizer <TransactionHistoryController> localizer = Substitute.For <IStringLocalizer <TransactionHistoryController> >();
            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);
            ILoggingFacade loggingFacade = Substitute.For <ILoggingFacade>();

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

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

            TransactionHistoryController fakecontroller
                = FakeController(mockCache, terminalListApi, localizer, fakeOperation, loggingFacade);

            terminalListApi.GetTransactionHistoryAsync(terminalId, page).Throws(new Exception());
            // Act
            var terminalList = await fakecontroller.GetTransactionHistory(pageinput);

            // Assert

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

            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).Value, localizer["InternalServerError"].Value);
        }
Beispiel #23
0
        //Unit Test for the RetrieveCache()
        public async Task CaseHistoryControllerTest_GetDataFromCache()
        {
            var page = GetCaseHistoryObject();

            page.lidTypeEnum = LidTypeEnum.Terminal;
            page.LIDValue    = "FakeStringID";

            int lid = 648988;

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

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

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

            caseHistoryApi
            .GetCaseHistory(Arg.Any <LidTypeEnum>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <PaginationCaseHistory>())
            .Returns(Task.FromResult <ApiResult <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory> > >(expectedResult));

            IDistributedCache mockCache = FakeCache();


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

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

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

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

            fakeOperation.RetrieveCache("_FakeStringID", new GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory>()).ReturnsForAnyArgs(expectedResult.Result);
            CaseHistoryController controller = new CaseHistoryController(mockCache, caseHistoryApi, localizer, fakeOperation, loggingFacade);

            //ACT

            var contactList = await controller.Get(page);

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

            //Assert
            Assert.Equal(JsonConvert.SerializeObject(actualRecord), JsonConvert.SerializeObject(expectedResult.Result));
        }
Beispiel #24
0
        //Mock API Call and unit test for the API call with returning mock ContactList.
        public async Task ContactListControllerTest_Success()
        {
            // Arrange

            var page = GetContactListObject();

            int                NameAddressID     = 3301636;
            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>();
            IContactListRepository mockRepo  = Substitute.For <IContactListRepository>();
            IStringLocalizer <ContactListController> localizer
                = Substitute.For <IStringLocalizer <ContactListController> >();
            IContactListApi mockContactListApi = Substitute.For <IContactListApi>();

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

            fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <GenericPaginationResponse <Demographics> >())).DoNotCallBase();
            fakeOperation.WhenForAnyArgs(x => x.AddCacheAsync(Arg.Any <string>(), Arg.Any <GenericPaginationResponse <Demographics> >())).DoNotCallBase();
            ContactListController controller = new ContactListController(mockCache, mockContactListApi, localizer, fakeOperation, loggingFacade);

            mockContactListApi.GetContactListAsync(page.lidTypeEnum, page.LIDValue, page.Page).ReturnsForAnyArgs(expectedResult);
            // Act
            var contactList = await controller.GetContactList(page);

            var    actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)contactList).Value;
            string contactInfo  = ((IList <Demographics>)(((GenericPaginationResponse <Demographics>)actualRecord).ReturnedRecords)).Where(x => x.NameAddressID == NameAddressID).FirstOrDefault().Name;


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

            Assert.Equal(recordCount.ToList().Count, 3);

            Assert.Equal(contactInfo, "Golden Corral Corporation");
        }
Beispiel #25
0
        public void MerchantListControllerTest_ModelState_Invalid()
        {
            //Arrange
            int CustomerID = 191807;

            IConfigurationRoot configurationRoot = Substitute.For <IConfigurationRoot>();

            configurationRoot = GetConfiguration(configurationRoot);
            MockMerchantListRepository mockMerchantListRepository            = new MockMerchantListRepository();
            ApiResult <GenericPaginationResponse <Merchant> > expectedResult = mockMerchantListRepository.GetMockData(CustomerID);

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

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

            PaginationMerchant page      = mockMerchantListRepository.GetPagination();
            MerchantListInput  pageinput = new MerchantListInput();

            pageinput.LIDValue    = CustomerID.ToString();
            pageinput.lidTypeEnum = Wp.CIS.LynkSystems.Model.Enums.LidTypeEnum.Customer;
            pageinput.Page        = page;


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

            IMerchantListApi merchantListApi = Substitute.For <IMerchantListApi>();

            IDistributedCache mockCache     = FakeCache();
            IOperation        fakeOperation = Substitute.ForPartsOf <Operation>(mockCache);



            MerchantListController controller =
                new MerchantListController(mockCache, merchantListApi, localizer, fakeOperation, loggingFacade);

            //Act
            controller.ModelState.AddModelError("key", "error message");
            var result = controller.GetMerchantList(pageinput);

            //Assert
            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)result.Result).StatusCode.ToString(), "400");
        }
Beispiel #26
0
        public async Task TerminalListControllerTest_FailToRetrieveData_Old()
        {
            // Arrange
            string TerminalNbr = "589587";

            MockTerminalListRepository          mockTerminalListRepository = new MockTerminalListRepository();
            ApiResult <ICollection <Terminal> > expectedResult             = mockTerminalListRepository.GetMockData(TerminalNbr);

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

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

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


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

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

            ApiResult <ICollection <Terminal> > response = new ApiResult <ICollection <Terminal> >();


            terminalListApi.GetTerminalListAsync(Convert.ToInt32(TerminalNbr)).ReturnsForAnyArgs(response);
            TerminalListController fakecontroller
                = FakeController(mockCache, terminalListApi, localizer, fakeOperation, loggingFacade);


            // Act
            var terminalList = await fakecontroller.GetTerminalList(Convert.ToInt32(TerminalNbr));

            // Assert

            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).StatusCode, 200);

            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).Value, localizer["NoDataFound"].Value);
        }
Beispiel #27
0
        ///Unit Test for the RetrieveCache()
        public async Task TransactionHistoryControllerTest_GetDataFromCache()
        {
            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>();
            ITransactionHistoryRepository mockRepo  = Substitute.For <ITransactionHistoryRepository>();
            IStringLocalizer <TransactionHistoryController> localizer
                = Substitute.For <IStringLocalizer <TransactionHistoryController> >();
            ITransactionHistoryApi mockTransactionHistoryApi = Substitute.For <ITransactionHistoryApi>();
            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.RetrieveCache("FakeStringID", new GenericPaginationResponse <Wp.CIS.LynkSystems.Model.TransactionHistory>()).ReturnsForAnyArgs(expectedResult.Result);

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

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


            //ACT
            var terminalList = await controller.GetTransactionHistory(pageinput);

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

            //Assert
            Assert.Equal(JsonConvert.SerializeObject(actualRecord), JsonConvert.SerializeObject(expectedResult.Result));
        }
Beispiel #28
0
        public async Task TerminalListControllerTest_Success_Old()
        {
            // Arrange
            string TerminalNbr = "589587";
            string TerminalID  = "LK429486";
            MockTerminalListRepository          mockTerminalListRepository = new MockTerminalListRepository();
            ApiResult <ICollection <Terminal> > expectedResult             = mockTerminalListRepository.GetMockData(TerminalNbr);

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

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

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

            fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <ICollection <Terminal> >())).DoNotCallBase();
            fakeOperation.WhenForAnyArgs(x => x.AddCacheAsync(Arg.Any <string>(), Arg.Any <ICollection <Terminal> >())).DoNotCallBase();
            ITerminalListApi       terminalListApi = Substitute.For <ITerminalListApi>();
            TerminalListController controller
                = new TerminalListController(mockCache, terminalListApi, localizer, fakeOperation, loggingFacade);

            terminalListApi.GetTerminalListAsync(Convert.ToInt32(TerminalNbr)).ReturnsForAnyArgs(expectedResult);
            // Act
            var terminalList = await controller.GetTerminalList(Convert.ToInt32(TerminalNbr));

            var    actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).Value;
            string terminalInfo = ((IList <Terminal>)((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).Value).Where(x => x.TerminalID == TerminalID).FirstOrDefault().Software;


            // Assert

            Assert.Equal(((IList <Terminal>)actualRecord).Count, 1);

            Assert.Equal(terminalInfo, "LSPR3271");
        }
Beispiel #29
0
        //UnitTest for validating the Invalid Model Data.
        public void TransactionHistoryController_ModelState_Invalid()
        {
            //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.ToString();
            pageinput.lidTypeEnum = Wp.CIS.LynkSystems.Model.Enums.LidTypeEnum.Customer;
            pageinput.Page        = page;

            IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >();

            IStringLocalizer <TransactionHistoryController> localizer
                = Substitute.For <IStringLocalizer <TransactionHistoryController> >();
            ILoggingFacade loggingFacade = Substitute.For <ILoggingFacade>();

            IDistributedCache      mockCache       = FakeCache();
            ITransactionHistoryApi terminalListApi = Substitute.For <ITransactionHistoryApi>();
            IOperation             fakeOperation   = Substitute.For <Operation>(mockCache);

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

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

            //Act
            controller.ModelState.AddModelError("key", "error message");
            var result = controller.GetTransactionHistory(pageinput);

            //Assert
            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)result.Result).StatusCode.ToString(), "400");
        }
Beispiel #30
0
        //Unit Test for the RetrieveCache()
        public async Task ContactListControllerTest_GetDataFromCache()
        {
            var page = GetContactListObject();

            page.lidTypeEnum = LidTypeEnum.Terminal;
            page.LIDValue    = "123456";

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

            IDistributedCache      mockCache = Substitute.For <IDistributedCache>();
            IContactListRepository mockRepo  = Substitute.For <IContactListRepository>();
            IStringLocalizer <ContactListController> localizer
                = Substitute.For <IStringLocalizer <ContactListController> >();
            IContactListApi mockContactListApi = Substitute.For <IContactListApi>();

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

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

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

            fakeOperation.RetrieveCache("_123456", new GenericPaginationResponse <Demographics>()).ReturnsForAnyArgs(expectedResult.Result);
            ContactListController controller = new ContactListController(mockCache, mockContactListApi, localizer, fakeOperation, loggingFacade);


            //ACT

            var contactList = await controller.GetContactList(page);

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

            //Assert
            Assert.Equal(JsonConvert.SerializeObject(actualRecord), JsonConvert.SerializeObject(expectedResult.Result));
        }