public async Task DashboardInfoControllerTest_TerminalSuccess() { // Arrange int lid = 589547; MockActiveServicesRepository repository = new MockActiveServicesRepository(); var expectedResult = repository.GetMockData(); IActiveServicesRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); IOperation fakeOperation = FakeOperation(_cache); ILoggingFacade fakeLogger = FakeLogger(); IActiveServicesApi dAPI = Substitute.For <IActiveServicesApi>(); dAPI.GetActiveServices((int)Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult); ActiveServicesController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger); // Act var dinfo = await controller.Get((int)Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid); var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).Value; // Assert Assert.Equal(actualRecord, expectedResult.Result); }
//Would be revisiting to modify the actual way of call method. public void ActiveServicesTest_Success() { // Arrange int lid = 191809; MockActiveServicesRepository repository = new MockActiveServicesRepository(); var expectedResult = repository.GetMockData(); IOptions <DataContext> optionsAccessor = Substitute.For <IOptions <DataContext> >(); IDatabaseConnectionFactory connectionFactory = Substitute.For <IDatabaseConnectionFactory>(); IActiveServicesRepository mockRepo = Substitute.For <IActiveServicesRepository>(); mockRepo.GetActiveServices((int)Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult.Result); // Act var actualRecord = mockRepo.GetActiveServices((int)Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).Result; // Assert Assert.Equal((actualRecord), expectedResult.Result); }
public void ActiveServicesApiTest_Success() { // Arrange int lid = 589547; IOptions <Settings> optionsAccessor = Substitute.For <IOptions <Settings> >(); IActiveServicesRepository mockRepo = Substitute.For <IActiveServicesRepository>(); IActiveServicesApi api = Substitute.For <IActiveServicesApi>(); MockActiveServicesRepository repository = new MockActiveServicesRepository(); var expectedResult = repository.GetMockData().Result; mockRepo.GetActiveServices((int)Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult); api = new ActiveServicesApi(optionsAccessor, mockRepo); // Act var actualRecord = (api.GetActiveServices((int)Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).Result).Result; // Assert Assert.Equal((actualRecord), expectedResult); }
public async Task ActiveServicesControllerTerminalTest_GetAnException() { // Arrange MockActiveServicesRepository repository = new MockActiveServicesRepository(); var expectedResult = repository.GetMockData(); IActiveServicesRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); ILoggingFacade fakeLogger = FakeLogger(); var dAPI = Substitute.For <IActiveServicesApi>(); var appSettings = new Settings() { MaxNumberOfRecordsToReturn = maxRecordsToReturn }; IOptions <Settings> options = Options.Create(appSettings); IDistributedCache mockCache = Substitute.For <IDistributedCache>(); IStringLocalizer <ActiveServicesController> localizer = Substitute.For <IStringLocalizer <ActiveServicesController> >(); string key = "GenericError"; string value = "Error occured"; var localizedString = new LocalizedString(key, value); localizer[Arg.Any <string>()].ReturnsForAnyArgs(localizedString); IOperation fakeOperation = FakeOperation(_cache); dAPI.GetActiveServices((int)Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, 0).ThrowsForAnyArgs(new System.Exception()); ActiveServicesController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger); // Act var dinfo = await controller.Get((int)Wp.CIS.LynkSystems.Model.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 ActiveServicesControllerTest_ModelState_InvalidAsync() { //Arrange int lid = 589547; MockActiveServicesRepository repository = new MockActiveServicesRepository(); var expectedResult = repository.GetMockData(); IActiveServicesRepository mockRepo = FakeRepository(); IDistributedCache _cache = FakeCache(); IOperation fakeOperation = FakeOperation(_cache); ILoggingFacade fakeLogger = FakeLogger(); IActiveServicesApi dAPI = Substitute.For <IActiveServicesApi>(); dAPI.GetActiveServices((int)Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult); ActiveServicesController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger); //Act controller.ModelState.AddModelError("key", "error message"); var dinfo = controller.Get((int)Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).Result; //Assert Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).StatusCode.ToString(), "400"); }