public async Task Get_ShouldReturnAllPeopleWithin50MilesLondonIfResponseOk() { _peopleDataProvider = new MockPeopleDataProvider(); var testPeople = GetListOfPeople(); PeopleController peopleController = new PeopleController(_peopleDataProvider); var actionResult = await peopleController.GetLondonPeopleWithinFiftyMiles() as OkObjectResult; var returnList = actionResult.Value as List <Person>; //Assert Assert.IsNotNull(actionResult); Assert.IsInstanceOfType(actionResult.Value, typeof(IEnumerable <Person>)); Person p1 = new Person { id = 135, first_name = "Mechelle", last_name = "Boam", email = "*****@*****.**", ip_address = "113.71.242.187", latitude = -6.5115909, longitude = 105.652983 }; Person p2 = new Person { id = 396, first_name = "Terry", last_name = "Stowgill", email = "*****@*****.**", ip_address = "143.190.50.240", latitude = -6.7098551, longitude = 111.3479498 }; Person p3 = new Person { id = 107, first_name = "Marty", last_name = "Aldiss", email = "*****@*****.**", ip_address = "36.21.197.237", latitude = 51.6553959, longitude = 0.0572553 }; CollectionAssert.DoesNotContain(returnList, p1); CollectionAssert.DoesNotContain(returnList, p2); Assert.IsTrue(returnList.Contains(p3)); }
public async Task FiftyMilesReturnsNotFound_GivenEmptyResult() { _peopleDataProvider = new MockEmptyPeopleDataProvider(); PeopleController peopleController = new PeopleController(_peopleDataProvider); var actionResult = await peopleController.GetLondonPeopleWithinFiftyMiles() as NotFoundObjectResult; //Assert Assert.IsNotNull(actionResult); Assert.IsTrue(actionResult.StatusCode == 404); }
public PersonController() { // Not, strictly speaking DI, since we're self-injecting, but the only dependency is the factory // so we'll let it go for now. It's a pattern that's sometimes hard to avoid without tying yourself // up in knots - I still haven't found a satisfactory (!) alternative for injecting DataContext // (ViewModels) into Views without adopting a full/over-blown framework that insists I frame my // application architecture to fit their model (eg., Prism) _serviceLogger = ContainerFactory.ResolveInstance <ILogger>(); _dataProvider = ContainerFactory.ResolveInstance <IPeopleDataProvider>(); }
public async Task Get_ShouldReturnAllPeopleFromProviderIfResponseOk() { _peopleDataProvider = new MockPeopleDataProvider(); var testPeople = GetListOfPeople(); PeopleController peopleController = new PeopleController(_peopleDataProvider); var actionResult = await peopleController.GetLondonPeople() as OkObjectResult; var returnList = actionResult.Value as List <Person>; //Assert Assert.IsNotNull(actionResult); Assert.IsInstanceOfType(actionResult.Value, typeof(IEnumerable <Person>)); Assert.AreEqual(returnList.Count, testPeople.Count); }
public PeopleController(IPeopleDataProvider peopleDataProvider) { this.peopleDataProvider = peopleDataProvider; }