public async Task TerminalDetailsControllerTest_TerminalSuccess() { // Arrange int lid = 589547; MockTerminalDetailsInfoRepository repository = new MockTerminalDetailsInfoRepository(); var expectedResult = repository.GetMockTerminalDetails(); ITerminalDetailsRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); IOperation fakeOperation = FakeOperation(_cache); ILoggingFacade fakeLogger = FakeLogger(); ITerminalDetailsApi dAPI = Substitute.For <ITerminalDetailsApi>(); dAPI.GetTerminalDetails(lid).ReturnsForAnyArgs(expectedResult); TerminalDetailsController controller = FakeController(dAPI, _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.EAndPData)actualRecord), expectedResult.Result); }
private TerminalDetailsController FakeController(ITerminalDetailsApi dashboardInfo, IDistributedCache mockCache, IOperation fakeOperation, ILoggingFacade fakeLogger) { var localizer = new MockStringLocalizer <TerminalDetailsController>(); localizer[0] = new LocalizedString("GenericError", "Error occured"); return(new TerminalDetailsController(mockCache, dashboardInfo, localizer, fakeOperation, fakeLogger)); }
/// <summary> /// /// </summary> /// <param name="cache"></param> /// <param name="terminalDetailsApi"></param> /// <param name="localizer"></param> /// <param name="operation"></param> /// <param name="loggingFacade"></param> public TerminalDetailsController(IDistributedCache cache, ITerminalDetailsApi terminalDetailsApi, IStringLocalizer <TerminalDetailsController> localizer , IOperation operation, ILoggingFacade loggingFacade) { _loggingFacade = loggingFacade; _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Starting Terminal Details Controller", "TerminalDetailsController.cs", "TerminalDetailsController"), CancellationToken.None); _terminalDetailsApi = terminalDetailsApi; _cache = cache; _localizer = localizer; _operation = operation; }
public void TerminalDetailsInfoApiTest_TerminalDetailsException() { // Arrange int CustomerID = 191809; IOptions <Settings> optionsAccessor = Substitute.For <IOptions <Settings> >(); ITerminalDetailsRepository mockRepo = Substitute.For <ITerminalDetailsRepository>(); ITerminalDetailsApi dashboardInfoApi = Substitute.For <ITerminalDetailsApi>(); mockRepo.GetTerminalDetails(CustomerID).ThrowsForAnyArgs(new Exception()); dashboardInfoApi = new TerminalDetailsApi(optionsAccessor, mockRepo, null); // Assert Assert.Throws <Exception>(() => dashboardInfoApi.GetTerminalDetails(CustomerID)); }
public void TerminalDetailsControllerTest_ModelState_Invalid() { //Arrange int lid = 589547; MockTerminalDetailsInfoRepository repository = new MockTerminalDetailsInfoRepository(); var expectedResult = repository.GetMockTerminalDetails(); ITerminalDetailsRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); IOperation fakeOperation = FakeOperation(_cache); ILoggingFacade fakeLogger = FakeLogger(); ITerminalDetailsApi dAPI = Substitute.For <ITerminalDetailsApi>(); dAPI.GetTerminalDetails(lid).ReturnsForAnyArgs(expectedResult); TerminalDetailsController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger); //Act controller.ModelState.AddModelError("key", "error message"); var dinfo = controller.GetTerminalDetails(lid).Result; //Assert Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).StatusCode.ToString(), "400"); }
public void TerminalDetailsInfoApiTest_TerminalDetailsSuccess() { // Arrange int lid = 589547; MockTerminalDetailsInfoRepository repository = new MockTerminalDetailsInfoRepository(); ITerminalDetailsRepository mockRepo = Substitute.For <ITerminalDetailsRepository>(); ITerminalDetailsSettlementInfoRepository mockSettlementRepo = Substitute.For <ITerminalDetailsSettlementInfoRepository>(); ITerminalDetailsApi api = Substitute.For <ITerminalDetailsApi>(); IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); var expectedResult = repository.GetMockTerminalDetails().Result; var expectedSettlementResult = repository.GetMockTerminalSettlementInfo().Result; mockRepo.GetTerminalDetails(lid).ReturnsForAnyArgs(expectedResult); mockSettlementRepo.GetTerminalSettlementInfo(lid).ReturnsForAnyArgs(expectedSettlementResult); api = new TerminalDetailsApi(appSettings, mockRepo, mockSettlementRepo); // Act var actualRecord = (api.GetTerminalDetails(lid).Result); // Assert Assert.Equal((actualRecord), expectedResult); }