public void Get_NoInput_ReturnsFourObjects() { // Arrange handled in [TestInitialized] // Act var actual = _controller.Get().ToList(); // Assert (multiple results, so multiple asserts here) Assert.AreEqual(4, actual.Count); }
public async void Get_ReturnsData() { // arrange var targetId = IdentifierHelper.LocationId; var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.Get(It.IsAny <Guid>())) .ReturnsAsync(() => new Result <Location>(ResultCode.Success, TestLocation())); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); dataStructureConverterMoq.Setup(x => x.ConvertAndMap <LocationModel, Location>(It.IsAny <string>(), It.IsAny <Location>())) .Returns(new Dictionary <string, object> { { "location", TestLocation() } }); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Get(targetId); var okResult = result as OkObjectResult; var response = okResult.Value as Dictionary <string, object>; // assert Assert.NotNull(response.Values); }
public async void Get_WithBadId() { // arrange var targetId = Guid.Empty; var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.Get(It.IsAny <Guid>())) .ReturnsAsync(() => new Result <Location>(ResultCode.Success, TestLocation())); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Get(targetId); var badRequestResult = result as BadRequestObjectResult; // assert Assert.NotNull(badRequestResult); }
public async void Get_WhenNotFound() { // arrange var targetId = Guid.NewGuid(); var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.Get(It.IsAny <Guid>())) .ReturnsAsync(() => new Result <Location>(ResultCode.NotFound)); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Get(targetId); var notFoundResult = result as NotFoundResult; // assert Assert.Equal(404, notFoundResult.StatusCode); }
public async void Get_WhenFound() { // arrange var errorCodeConverter = new ErrorCodeConverter(); var targetId = IdentifierHelper.LocationId; var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.Get(It.IsAny <Guid>())) .ReturnsAsync(() => new Result <Location>(ResultCode.Success, TestLocation())); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Get(targetId); var okResult = result as OkObjectResult; var response = okResult.Value as Dictionary <string, object>; // assert Assert.Equal(200, okResult.StatusCode); }
public void Get() { var data = new List <Location> { new Location { id = 1, gogId = "ChIJ_w0bJLzUf0cRy_s3-sYl0UU", address = "Via Zamboni, 16/d, 40126 Bologna, Italia", telephone = "051 1889 9835", description = null, geolocation = "(44.495439, 11.348128999999972)", name = "Lab16", openingHours = "Lunedì: 07:00–03:00 | Martedì: 07:00–03:00 | Mercoledì: 07:00–03:00 | Giovedì: 07:00–03:00 | Venerdì: 07:00–03:00 | Sabato: 17:30–03:30 | Domenica: 17:30–03:30", rating = 4.4F, website = "http://www.lab16.it/", url = "https://plus.google.com/108077084127565302676/about?hl=it-IT" } }.AsQueryable(); var mockSet = new Mock <DbSet <Location> >(); mockSet.As <IQueryable <Location> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Location> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Location> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Location> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); //TODO: Start MOCKING var mockContext = new Mock <databaseEF>(); mockContext.Setup(c => c.locations).Returns(mockSet.Object); var service = new LocationsController(mockContext.Object); Assert.AreEqual("Lab16", service.Get(data.First().id).name); }
public void WhenRequestingAGivenLocationById_ReturnesCorrectResponseData() { // Arrange _service.Setup(locationService => locationService.GetLocationById(10)).Returns(new Location { Id = 10, Name = "Location1" }); _mockMapper.Setup(x => x.Map <Location, LocationViewModel>(It.IsAny <Location>())) .Returns(new LocationViewModel { Id = 10, Name = "Location1" }); var controller = new LocationsController(_service.Object, _userManager) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; // Act var response = controller.Get(10); var contentResult = response as OkNegotiatedContentResult <LocationViewModel>; // Assert Assert.IsNotNull(response); Assert.IsNotNull(contentResult); Assert.AreEqual(10, contentResult.Content.Id); Assert.AreEqual("Location1", contentResult.Content.Name); }
public void LocationControllerShouldReturnACity() { Locations location1 = new Locations { Id = 1, City = "Somehwere", PostalCode = "something", States = "Somewhere", StreetAddress = "somewhere" }; var location2 = new Locations { Id = 2, City = "Somehwere1", PostalCode = "something1", States = "Somewhere1", StreetAddress = "somewhere1" }; string city = "Somehwere"; int id = 1; var repoMock = new Mock <IZVRPubRepository>(); repoMock.Setup(c => c.GetLocationByCity(city)).Returns(location1); var controller = new LocationsController(repoMock.Object); var result = controller.Get(id); }
public async Task When_Get_Succeeds() { var response = await _controller.Get(_mockDtoOptions.Object).ConfigureAwait(false); var result = response.ExecuteAsync(new CancellationToken()).Result; Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK)); }
public async Task ShouldReturnLocationsData() { //Act var locationsResponse = await _locationsController.Get(); //Assert Assert.IsInstanceOfType(locationsResponse, typeof(List <LocationDto>)); }
public void TestGetAllLocations() { // Get all locations from repository var collection = _controller.Get(); // verify all locations are retrieved Assert.AreEqual(collection.Count(), _locations.Count); }
public void Get_AtLeastOneLocationExists_ReturnsLocations() { LocationsController sut = CreateSut(); IEnumerable <Location> actual = sut.Get(""); Assert.That(actual.Count(), Is.AtLeast(1)); }
public void Get_AtLeastOneLocationExists_MapsProperties() { LocationsController sut = CreateSut(); Location actual = sut.Get("").First(); Assert.That(actual.Username, Is.Not.Empty); Assert.That(actual.Lat, Is.Not.Null); Assert.That(actual.Lng, Is.Not.Null); Assert.That(actual.Speed, Is.Not.Null); }
public void LocationsController_Get_ReturnAllElementsInRepo_WhenGivenNoParameters() { var result = controller.Get(); var resultObjectResult = result as ObjectResult; var resultObject = resultObjectResult.Value as IEnumerable <Location>; Assert.IsType <ObjectResult>(result); Assert.Equal(3, resultObject.Count()); }
public async Task GetByLatitudeAndLongitude_Returns404NotFound_IfLocationNotFound(double latitude, double longitude) { //Arrange var request = new Request() { Latitude = latitude, Longitude = longitude }; _mediatorMock.Setup(a => a.Send(It.IsAny <Request>(), It.IsAny <CancellationToken>())) .ReturnsAsync(() => null); var controller = new LocationsController(_mediatorMock.Object); //Act var result = await controller.Get(request); //Assert Assert.NotNull(result); Assert.IsType <NotFoundResult>(result); }
public void WebApi_Locations_Get() { // Arrange Mock <ILogger <LocationsController> > mockLogger = new Mock <ILogger <LocationsController> >(); Mock <ILocationRepository> mockLocationRepository = new Mock <ILocationRepository>(); mockLocationRepository.Setup(m => m.GetLocations).Returns((new Location[] { new Location { LocationId = 1, ParentId = 0, Description = "L1" }, new Location { LocationId = 2, ParentId = 1, Description = "L2" }, new Location { LocationId = 3, ParentId = 1, Description = "L3" }, new Location { LocationId = 4, ParentId = 1, Description = "L4" }, new Location { LocationId = 5, ParentId = 1, Description = "L5" } }).AsQueryable <Location>()); LocationsController controller = new LocationsController(mockLogger.Object, mockLocationRepository.Object); // Act OkObjectResult result = controller.Get("1", "9999") as OkObjectResult; var locations = JsonConvert.DeserializeObject <List <Location> >(result.Value.ToString()); // Assert Assert.AreEqual("L1", locations[0].Description); Assert.AreEqual("L2", locations[1].Description); Assert.AreEqual("L3", locations[2].Description); Assert.AreEqual("L4", locations[3].Description); Assert.AreEqual("L5", locations[4].Description); }
public async Task GetByLatitudeAndLongitude_Returns200OkWithOvject_IfLocationFound(double latitude, double longitude) { //Arrange var request = new Request() { Latitude = latitude, Longitude = longitude }; _mediatorMock.Setup(a => a.Send(It.IsAny <Request>(), It.IsAny <CancellationToken>())) .ReturnsAsync(() => new Location()); var controller = new LocationsController(_mediatorMock.Object); //Act var result = await controller.Get(request); //Assert Assert.NotNull(result); var okObject = Assert.IsType <OkObjectResult>(result); var response = Assert.IsType <Location>(okObject.Value); Assert.NotNull(response); }
public void Get_LocationTest() { var result = _locationController.Get(); Assert.NotNull(result.Value); }