public async Task TransactionsInqControllerTest_Success() { // Arrange ITransactionsInqDetailsInfoRepository mockRepo = Substitute.For <ITransactionsInqDetailsInfoRepository>(); mockRepo = new MockTransactionsInqDetailsInfoRepository(); ITransactionsInqDetailsInfoTierRepository mockRepo2 = Substitute.For <ITransactionsInqDetailsInfoTierRepository>(); mockRepo2 = new MockTransactionsInqDetailsInfoTierRepository(); IDistributedCache mockCache = Substitute.For <IDistributedCache>(); IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); ITransactionsInquiryDetailsInfoApi transInqApi = new TransactionInquiryDetailsInfoApi(appSettings, mockRepo); ITransactionsInquiryDetailsInfoTierApi transInqTierApi = new TransactionsInquiryDetailsTierApi(appSettings, mockRepo2); TransactionsInquiryGeneralInfo transinqgeninfo = new TransactionsInquiryGeneralInfo(); TransactionsInquiryDetailsInfoController controller = new TransactionsInquiryDetailsInfoController(mockCache, transInqApi, transInqTierApi, null); // Act var transinquiries = await controller.Get(transinqgeninfo, 1, 10006144, "6/18/2015", "7/18/2015", 0, "0", 10, 5); // Assert var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)transinquiries).Value; ////Assert.Equal(((Wp.CIS.LynkSystems.Model.MerchantProfile)actualRecord).MerchantNbr.ToString(), "007"); }
public async Task TransactionsInqDetailsInfoRetrievalFromCache_NotAvailableInCache() { string id = "10006143"; var expectedRecord = new TransactionsInquiry { ARN = "Test ARN Code", CompleteCode = 555555 }; IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); ITransactionsInqDetailsInfoRepository mockRepo = Substitute.For <ITransactionsInqDetailsInfoRepository>(); mockRepo.GetTransactionInquiryCardNoResults(1, "", 2, "", "", null, 3, 4, 5).ReturnsForAnyArgs(new GenericPaginationResponse <TransactionsInquiry>()); //var mockRepo = new MockTransactionsInqTerminalInfoRepository(); mockRepo = new MockTransactionsInqDetailsInfoRepository(); ITransactionsInqDetailsInfoTierRepository mockRepo2 = Substitute.For <ITransactionsInqDetailsInfoTierRepository>(); mockRepo2 = new MockTransactionsInqDetailsInfoTierRepository(); IDistributedCache mockCache = FakeCache(); mockCache = new MockCacheTransactionsInqDetailsInfoTier(); ITransactionsInquiryDetailsInfoApi detailsinfo = new TransactionInquiryDetailsInfoApi(appSettings, mockRepo); ITransactionsInquiryDetailsInfoTierApi detailstierinfo = new TransactionsInquiryDetailsTierApi(appSettings, mockRepo2); TransactionsInquiryGeneralInfo transinqgeninfo = new TransactionsInquiryGeneralInfo(); //Retrieving from Cache first. var cacheRetrievedData = new Operation(mockCache).RetrieveCache(id.ToString(), new Wp.CIS.LynkSystems.Model.TransactionsInquiryGeneralInfo()); //Does not exist in mock Cache. Hence null Assert.Equal(cacheRetrievedData, null); //since no data in cache, now call the controller. The controller retrieves data and also adds to cache TransactionsInquiryDetailsInfoController controller = new TransactionsInquiryDetailsInfoController(mockCache, detailsinfo, detailstierinfo, null); //Retrieve the data from controller and also check for the data in the cache. var detailsdata = await controller.Get(transinqgeninfo, 1, 10006144, "6/18/2015", "7/18/2015", 0, "0", 10, 5); var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)detailsdata).Value; var cacheretrieveddata = new Operation(mockCache).RetrieveCache(id.ToString(), new Wp.CIS.LynkSystems.Model.TransactionsInquiryGeneralInfo()); var firstRecord = ((GenericPaginationResponse <TransactionsInquiry>)actualRecord).ReturnedRecords.FirstOrDefault(); // Check the retrieved data Assert.Equal(firstRecord.ARN, "Test ARN Code"); // Make sure the data retrieved from controller is same as the data from the cache //Assert.Equal(JsonConvert.SerializeObject(actualRecord), JsonConvert.SerializeObject(cacheretrieveddata)); Assert.Equal(JsonConvert.SerializeObject(firstRecord), JsonConvert.SerializeObject(expectedRecord)); }