public async Task MemoInfoControllerTest_TerminalSuccess() { // Arrange int lid = 589547; MockMemoInfoRepository repository = new MockMemoInfoRepository(); var expectedResult = repository.GetMockMemoInfo(); IMemoInfoRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); IOperation fakeOperation = FakeOperation(_cache); ILoggingFacade fakeLogger = FakeLogger(); IMemoInfoApi dAPI = Substitute.For <IMemoInfoApi>(); dAPI.GetMemoResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult); MemoInfoController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger); // Act var dinfo = await controller.Get(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid); var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).Value; // Assert Assert.Equal(((Wp.CIS.LynkSystems.Model.MemoList)actualRecord), expectedResult.Result); }
//Would be revisiting to modify the actual way of call method. public void MemoInfoTest_TerminalSuccess() { // Arrange int lid = 191809; MockMemoInfoRepository repository = new MockMemoInfoRepository(); var expectedResult = repository.GetMockMemoInfo(); IOptions <DataContext> optionsAccessor = Substitute.For <IOptions <DataContext> >(); IDatabaseConnectionFactory connectionFactory = Substitute.For <IDatabaseConnectionFactory>(); IMemoInfoRepository mockRepo = Substitute.For <IMemoInfoRepository>(); mockRepo.GetMemoResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult.Result); // Act var actualRecord = mockRepo.GetMemoResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).Result; // Assert Assert.Equal(actualRecord, expectedResult.Result); }
public void MemoInfoApiTest_Success() { // Arrange int lid = 589547; MockMemoInfoRepository repository = new MockMemoInfoRepository(); IMemoInfoRepository mockRepo = Substitute.For <IMemoInfoRepository>(); IMemoInfoApi api = Substitute.For <IMemoInfoApi>(); IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); var expectedResult = repository.GetMockMemoInfo().Result; mockRepo.GetMemoResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult); api = new MemoInfoApi(appSettings, mockRepo); // Act var actualRecord = (api.GetMemoResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).Result).Result; // Assert Assert.Equal((actualRecord), expectedResult); }
public void MemoInfoControllerTest_ModelState_Invalid() { //Arrange int lid = 589547; MockMemoInfoRepository repository = new MockMemoInfoRepository(); var expectedResult = repository.GetMockMemoInfo(); IMemoInfoRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); IOperation fakeOperation = FakeOperation(_cache); ILoggingFacade fakeLogger = FakeLogger(); IMemoInfoApi dAPI = Substitute.For <IMemoInfoApi>(); dAPI.GetMemoResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult); MemoInfoController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger); //Act controller.ModelState.AddModelError("key", "error message"); var dinfo = controller.Get(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).Result; //Assert Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).StatusCode.ToString(), "400"); }