public async Task BankingInfoControllerTest_Success() { //Arrange MockBankingInfoRepository repository = new MockBankingInfoRepository(); var expectedResult = repository.GetMockBankingInfo(); IDistributedCache _cache = FakeCache(); string lid = "756122"; IBankingInfoRepository mockRepo = Substitute.For <IBankingInfoRepository>(); IBankingApi dAPI = Substitute.For <IBankingApi>(); ILoggingFacade fakeLogger = FakeLogger(); IOperation fakeOperation = FakeOperation(_cache); dAPI.GetBankingInfo(Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult); BankingController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger); //Act var dinfo = await controller.GetBankingInfo(Helper.LIDTypes.TerminalNbr, lid); var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).Value; //Assert Assert.Equal(actualRecord, expectedResult.Result); }
public async Task BankingInfoControllerTest_GetAnException() { //Arrange MockBankingInfoRepository repository = new MockBankingInfoRepository(); var expectedResult = repository.GetMockBankingInfo(); IDistributedCache _cache = FakeCache(); string lid = "756122"; IBankingInfoRepository mockRepo = Substitute.For <IBankingInfoRepository>(); IBankingApi dAPI = Substitute.For <IBankingApi>(); ILoggingFacade fakeLogger = FakeLogger(); IOperation fakeOperation = FakeOperation(_cache); dAPI.GetBankingInfo(Helper.LIDTypes.TerminalNbr, lid).ThrowsForAnyArgs(new System.Exception()); BankingController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger); // Act var dinfo = await controller.GetBankingInfo(Helper.LIDTypes.TerminalNbr, "0"); var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo); // Assert Assert.Equal(actualRecord.StatusCode, 500); Assert.Equal(actualRecord.Value, "Error occured"); }
public void TestBankingInfoRepository_Success() { MockBankingInfoRepository repository = new MockBankingInfoRepository(); var expectedResult = repository.GetMockBankingInfo(); string lid = "756122"; IBankingInfoRepository mockRepo = Substitute.For <IBankingInfoRepository>(); mockRepo.GetBankingInfo(Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult.Result); // Act var actualRecord = mockRepo.GetBankingInfo(Helper.LIDTypes.TerminalNbr, lid).Result; // Assert Assert.Equal((actualRecord), expectedResult.Result); }
public void TestBankingInfoApi_Success() { //Arrange MockBankingInfoRepository repository = new MockBankingInfoRepository(); var expectedResult = repository.GetMockBankingInfo(); string lid = "756122"; IBankingInfoRepository mockRepo = Substitute.For <IBankingInfoRepository>(); IBankingApi api = Substitute.For <IBankingApi>(); IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); mockRepo.GetBankingInfo(Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult.Result); api = new BankingApi(appSettings, mockRepo); // Act var actualRecord = api.GetBankingInfo(Helper.LIDTypes.TerminalNbr, lid).Result; //Assert Assert.Equal(((IList <BankingInformation>)actualRecord.Result), (IList <BankingInformation>)expectedResult.Result); }
public void BankingInfoControllerTest_ModelState_Invalid() { MockBankingInfoRepository repository = new MockBankingInfoRepository(); var expectedResult = repository.GetMockBankingInfo(); IDistributedCache _cache = FakeCache(); string lid = "756122"; IBankingInfoRepository mockRepo = Substitute.For <IBankingInfoRepository>(); IBankingApi dAPI = Substitute.For <IBankingApi>(); ILoggingFacade fakeLogger = FakeLogger(); IOperation fakeOperation = FakeOperation(_cache); dAPI.GetBankingInfo(Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult); BankingController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger); //Act controller.ModelState.AddModelError("key", "error message"); var dinfo = controller.GetBankingInfo(Helper.LIDTypes.TerminalNbr, lid).Result; //Assert Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).StatusCode.ToString(), "400"); }