public async Task TerminalDetailsControllerTerminalTest_GetAnException() { // Arrange ITerminalDetailsRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); ILoggingFacade fakeLogger = FakeLogger(); IDistributedCache mockCache = Substitute.For <IDistributedCache>(); IStringLocalizer <TerminalDetailsController> localizer = Substitute.For <IStringLocalizer <TerminalDetailsController> >(); string key = "GenericError"; string value = "Error occured"; var localizedString = new LocalizedString(key, value); localizer[Arg.Any <string>()].ReturnsForAnyArgs(localizedString); IOperation fakeOperation = FakeOperation(_cache); IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); ITerminalDetailsApi dAPI = new TerminalDetailsApi(appSettings, mockRepo, null); dAPI.GetTerminalDetails(0).ThrowsForAnyArgs(new System.Exception()); TerminalDetailsController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger); // Act var dinfo = await controller.GetTerminalDetails(0); var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo); // Assert Assert.Equal(actualRecord.StatusCode, 500); Assert.Equal(actualRecord.Value, "Error occured"); }
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 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); }