public async void GetAllLocations_ShouldReturnOk() { WebApiTestsHelper.Lock(); // Arrange SetUp(); var locations = new List <Location> { new Location { Id = 1, Name = "Warsaw", LocationSnapshots = new List <LocationSnapshot> { new LocationSnapshot(), new LocationSnapshot() } }, new Location { Id = 2, Name = "Lisbon", LocationSnapshots = new List <LocationSnapshot> { new LocationSnapshot() } } }; var locationDataService = Substitute.For <ILocationDataService>(); locationDataService.GetAllLocationsAsync() .Returns(_ => { var tcs = new TaskCompletionSource <IEnumerable <Location> >(); tcs.SetResult(locations); return(tcs.Task); }); // Act var sit = new LocationsController(locationDataService, Substitute.For <ILogger <LocationsController> >()); var result = await sit.GetAllLocations(); // Assert var dtos = WebApiTestsHelper.ExtractGenericCollectionFromActionResult <OkObjectResult, IEnumerable <LocationDto> >(result) .ToList(); for (var i = 0; i < dtos.Count; i++) { Assert.Equal(locations[i].Id, dtos[i].Id); Assert.Equal(locations[i].Name, dtos[i].Name); Assert.Equal(locations[i].LocationSnapshots.Count, dtos[i].SnapshotsCount); } WebApiTestsHelper.Unlock(); }