private DashboardInfoController FakeController(IDashboardInfoApi dashboardInfo, IDashboardInfoRepository mockRepo, IDistributedCache mockCache, IOperation fakeOperation, ILoggingFacade loggingFacade) { var localizer = new MockStringLocalizer <DashboardInfoController>(); localizer[0] = new LocalizedString("GenericError", "Error occured"); return(new DashboardInfoController(mockCache, dashboardInfo, localizer, fakeOperation, loggingFacade)); }
public async Task DashboardInfoControllerTest_MerchantSuccess() { // Arrange int lid = 589547; MockDashboardInfoRepository repository = new MockDashboardInfoRepository(); var expectedResult = repository.GetMockMerchantData(); IDashboardInfoRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); IOperation fakeOperation = FakeOperation(_cache); ILoggingFacade fakeLogger = FakeLogger(); IDashboardInfoApi dAPI = Substitute.For <IDashboardInfoApi>(); dAPI.GetDashboardSearchResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.MerchantNbr, lid).ReturnsForAnyArgs(expectedResult); DashboardInfoController controller = FakeController(dAPI, mockRepo, _cache, fakeOperation, fakeLogger); // Act var dinfo = await controller.Get(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.MerchantNbr, lid); var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).Value; // Assert Assert.Equal(((Wp.CIS.LynkSystems.Model.DashboardInfo)actualRecord).MerchInfo.customerID, 393727); Assert.Equal(((Wp.CIS.LynkSystems.Model.DashboardInfo)actualRecord).CustProfile.customerID, 393727); Assert.Equal(((Wp.CIS.LynkSystems.Model.DashboardInfo)actualRecord).TermInfo, null); }
public void DashboardInfoControllerTest_GetDashBoardInfoSearch_ModelState_Invalid() { //Arrange int lid = 589547; MockDashboardInfoRepository repository = new MockDashboardInfoRepository(); var expectedResult = repository.GetMockTerminalData(); IDashboardInfoRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); IOperation fakeOperation = FakeOperation(_cache); ILoggingFacade fakeLogger = FakeLogger(); IDashboardInfoApi dAPI = Substitute.For <IDashboardInfoApi>(); fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <Wp.CIS.LynkSystems.Model.DashboardInfo>())).DoNotCallBase(); dAPI.GetDashboardSearchResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult); DashboardInfoController controller = FakeController(dAPI, mockRepo, _cache, fakeOperation, fakeLogger); //Act controller.ModelState.AddModelError("key", "error message"); var dinfo = controller.GetDashBoardInfoSearch(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, Convert.ToString(lid)).Result; //Assert Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).StatusCode.ToString(), "400"); }
public async Task DashboardInfoControllerTest_MerchantAccountSuccess() { // Arrange int lid = 589547; MockDashboardInfoRepository repository = new MockDashboardInfoRepository(); var expectedResult = repository.GetMockMerchantData(); IDashboardInfoRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); IOperation fakeOperation = FakeOperation(_cache); ILoggingFacade fakeLogger = FakeLogger(); IDashboardInfoApi dAPI = Substitute.For <IDashboardInfoApi>(); dAPI.GetDashboardSearchResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.MerchantNbr, lid).ReturnsForAnyArgs(expectedResult); DashboardInfoController controller = FakeController(dAPI, mockRepo, _cache, fakeOperation, fakeLogger); // Act var dinfo = await controller.Get(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.MerchantNbr, lid); var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).Value; // Assert Assert.Equal(((Wp.CIS.LynkSystems.Model.DashboardInfo)actualRecord).DemographicsInfoCust, repository.custDemographicsList); Assert.Equal(((Wp.CIS.LynkSystems.Model.DashboardInfo)actualRecord).DemographicsInfoMerch, repository.merchDemographicsList); Assert.Equal(((Wp.CIS.LynkSystems.Model.DashboardInfo)actualRecord).DemographicsInfoTerm, null); Assert.Equal(((Wp.CIS.LynkSystems.Model.DashboardInfo)actualRecord).MerchInfo.merchFedTaxID, "561005071"); Assert.Equal(((Wp.CIS.LynkSystems.Model.DashboardInfo)actualRecord).MerchInfo.acquiringBank, "Citizens Trust Tier 1 Tier 2"); }
public void DashboardInfoApiTest_CustomerSuccess() { // Arrange int lid = 589547; MockDashboardInfoRepository repository = new MockDashboardInfoRepository(); IDashboardInfoRepository mockRepo = Substitute.For <IDashboardInfoRepository>(); IDashboardInfoApi api = Substitute.For <IDashboardInfoApi>(); var appSettings = new Settings() { MaxNumberOfRecordsToReturn = maxRecordsToReturn }; IOptions <Settings> options = Options.Create(appSettings); var expectedResult = repository.GetMockCustomerData().Result; mockRepo.GetDashboardSearchResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.CustomerNbr, lid, maxRecordsToReturn).ReturnsForAnyArgs(expectedResult); api = new DashboardInfoApi(options, mockRepo); // Act var actualRecord = (api.GetDashboardSearchResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.CustomerNbr, lid).Result).Result; // Assert Assert.Equal((actualRecord), expectedResult); Assert.Equal((actualRecord).MerchInfo, null); Assert.Equal((actualRecord).CustProfile.customerID, 393727); Assert.Equal((actualRecord).TermInfo, null); }
/// <summary> /// /// </summary> /// <param name="cache"></param> /// <param name="dashboardInfo"></param> /// <param name="localizer"></param> /// <param name="operation"></param> /// <param name="loggingFacade"></param> public DashboardInfoController(IDistributedCache cache, IDashboardInfoApi dashboardInfo, IStringLocalizer <DashboardInfoController> localizer , IOperation operation, ILoggingFacade loggingFacade) { _loggingFacade = loggingFacade; _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Starting Dashboard Info Controller", "DashboardInfoController.cs", "DashboardInfoController"), CancellationToken.None); _dashboardInfo = dashboardInfo; _cache = cache; _localizer = localizer; _operation = operation; }
public async Task DashboardInfoApiTest_TerminalDetailsException() { // Arrange int CustomerID = 191809; // IOptions<Settings> optionsAccessor = Options.Create(appSettings); IOptions <Settings> optionsAccessor = Substitute.For <IOptions <Settings> >(); IDashboardInfoRepository mockRepo = Substitute.For <IDashboardInfoRepository>(); IDashboardInfoApi dashboardInfoApi = Substitute.For <IDashboardInfoApi>(); mockRepo.GetTerminalDetails(CustomerID).ThrowsForAnyArgs(new Exception()); dashboardInfoApi = new DashboardInfoApi(optionsAccessor, mockRepo); // Assert await Assert.ThrowsAsync <Exception>(() => dashboardInfoApi.GetTerminalDetails(CustomerID)); }
public async Task DashboardInfoApiTest_Exception() { // Arrange int CustomerID = 191809; var appSettings = new Settings() { MaxNumberOfRecordsToReturn = maxRecordsToReturn }; IOptions <Settings> optionsAccessor = Options.Create(appSettings); IDashboardInfoRepository mockRepo = Substitute.For <IDashboardInfoRepository>(); IDashboardInfoApi dashboardInfoApi = Substitute.For <IDashboardInfoApi>(); mockRepo.GetDashboardSearchResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.CustomerID, CustomerID, maxRecordsToReturn).ThrowsForAnyArgs(new Exception()); dashboardInfoApi = new DashboardInfoApi(optionsAccessor, mockRepo); // Assert await Assert.ThrowsAsync <Exception>(() => dashboardInfoApi.GetDashboardSearchResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.CustomerID, CustomerID)); }
public void DashboardInfoApiTest_TerminalDetailsSuccess() { // Arrange int lid = 589547; MockDashboardInfoRepository repository = new MockDashboardInfoRepository(); IDashboardInfoRepository mockRepo = Substitute.For <IDashboardInfoRepository>(); IDashboardInfoApi api = Substitute.For <IDashboardInfoApi>(); IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); var expectedResult = repository.GetMockTerminalDetails().Result; mockRepo.GetTerminalDetails(lid).ReturnsForAnyArgs(expectedResult); api = new DashboardInfoApi(appSettings, mockRepo); // Act var actualRecord = (api.GetTerminalDetails(lid).Result).Result; // Assert Assert.Equal((actualRecord), expectedResult); }
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); }
public async Task DashboardInfoControllerTest_TerminalDetailsAccountSuccess() { // Arrange int lid = 588799; MockDashboardInfoRepository repository = new MockDashboardInfoRepository(); var expectedResult = repository.GetMockTerminalDetails(); IDashboardInfoRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); IOperation fakeOperation = FakeOperation(_cache); ILoggingFacade fakeLogger = FakeLogger(); IDashboardInfoApi dAPI = Substitute.For <IDashboardInfoApi>(); dAPI.GetTerminalDetails(lid).ReturnsForAnyArgs(expectedResult); DashboardInfoController controller = FakeController(dAPI, mockRepo, _cache, fakeOperation, fakeLogger); // Act var dinfo = await controller.GetTerminalDetails(lid); var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).Value; // Assert Assert.Equal(((Wp.CIS.LynkSystems.Model.TerminalDetails)actualRecord), expectedResult.Result); }