public void Can_Delete_Valid_Locations() { //Arrange - create a location Location loc = new Location { Id = 2, Name = "Test", Address1 = "123 N. Address", City = "Troy", Zip = "87654" }; // Arrange - create the mock repository Mock <ILocationRepository> mock = new Mock <ILocationRepository>(); mock.Setup(m => m.Locations).Returns(new Location[] { new Location { Id = 1, Name = "L1", Address1 = "123 N. Address", City = "Troy", Zip = "87654" }, loc, new Location { Id = 3, Name = "L3", Address1 = "123 N. Address", City = "Troy", Zip = "87654" } }); // Arrange - create the controller LocationsController target = new LocationsController(mock.Object); // Act - delete the product target.Delete(loc.Id); //Assert - ensure that the repository delete method was called with the correct location mock.Verify(m => m.DeleteLocation(loc.Id)); }
private async void GetAllVehicles_ReturnsData() { // arrange var locationId = IdentifierHelper.LocationId; var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.GetVehicles(It.IsAny <Guid>())) .ReturnsAsync(() => new Result <IEnumerable <Vehicle> >(ResultCode.Success, TestVehicles())); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); dataStructureConverterMoq.Setup(x => x.ConvertAndMap <IEnumerable <VehicleModel>, IEnumerable <Vehicle> >(It.IsAny <string>(), It.IsAny <IEnumerable <Vehicle> >())) .Returns(new Dictionary <string, object> { { "vehicles", VehicleModelHelper.GetMany() } }); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.GetAllVehicles(locationId); var okResult = result as OkObjectResult; var response = okResult.Value as Dictionary <string, object>; // assert Assert.NotNull(response.Values); }
public void Initialize() { var seattle = new Location { LocationId = 1, Country = "UnitedStates", City = "Seattle", CountryCode = "US", LocationTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time") }; var paris = new Location { LocationId = 2, Country = "France", City = "Paris", CountryCode = "FR", LocationTimeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time") }; _locations = new List <Location> { seattle, paris }; var repository = new LocationRepository { GetAll = () => _locations.AsQueryable() }; //Create an instance of controller with a fake repository that retrieve data from list instead of db _controller = new LocationsController(repository); }
public async void Put_WhenNotValid() { // arrange var testLocation = TestLocationModel(); var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.Update(It.IsAny <Location>())) .ReturnsAsync(() => new Result <Guid>(ResultCode.BadRequest, TestLocation().Id)); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Put(testLocation.Id, testLocation); var badRequestResult = result as BadRequestResult; // assert Assert.NotNull(badRequestResult); }
public async void GetAll_WhenNotFound() { // arrange var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.GetAll()) .ReturnsAsync(() => new Result <IEnumerable <Location> >(ResultCode.NotFound)); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.GetAll(); var notFoundResult = result as NotFoundResult; // assert Assert.NotNull(notFoundResult); }
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 Post_WhenValid() { // arrange var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.Insert(It.IsAny <Location>())) .ReturnsAsync(() => new Result <Guid>(ResultCode.Success, TestLocation().Id)); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Post(TestLocationModel()); var createdAtRouteResult = result as CreatedAtRouteResult; // assert Assert.NotNull(createdAtRouteResult); }
public void LocationIndex_WithLocations_DisplaysLocations() { var mockCustomerRepo = new Mock <ICustomerRepo>(); var mockStoreRepo = new Mock <IStoreRepo>(); var mockProductRepo = new Mock <IProductRepo>(); var mockOrderRepo = new Mock <IOrderRepo>(); var mockShoppingCartRepo = new Mock <IShoppingCart>(); Dictionary <int, int> products = new Dictionary <int, int>() { { 1, 10 }, { 2, 20 }, }; mockStoreRepo.Setup(r => r.GetAllStores()) .Returns(new List <Store> { new Store(1, "Store", products) }); var controller = new LocationsController(new NullLogger <LocationsController>(), mockStoreRepo.Object, mockCustomerRepo.Object, mockOrderRepo.Object, mockProductRepo.Object, mockShoppingCartRepo.Object); IActionResult actionResult = controller.Index(); var viewResult = Assert.IsAssignableFrom <ViewResult>(actionResult); var locations = Assert.IsAssignableFrom <IEnumerable <LocationViewModel> >(viewResult.Model); var locationsList = locations.ToList(); Assert.Equal(1, locationsList.Count()); Assert.Equal("Store", locationsList[0].Name); Assert.Equal(products, locationsList[0].Inventory); Assert.Null(viewResult.ViewName); }
public void Details_ReturnsAView_WithInventoryAndOrders() { // Arrange int id = 1; var mockLocationRepo = new Mock <ILocationRepository>(); mockLocationRepo.Setup(repo => repo.GetWithInventory(id)) .Returns(LocationWithInventory()); var mockOrderRepository = new Mock <IOrderRepository>(); mockOrderRepository.Setup(repo => repo.GetByLocationId(id)) .Returns(ListOfTwoOrders()); var controller = new LocationsController(mockLocationRepo.Object, mockOrderRepository.Object, null); // Act var result = controller.Details(id); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <LocationWithOrderAndInventoryViewModel>(viewResult.ViewData.Model); Assert.Equal("Walmart", model.Name); var inventory = Assert.IsAssignableFrom <IEnumerable <InventoryViewModel> >(model.Inventory); Assert.Equal(2, inventory.Count()); var orders = Assert.IsAssignableFrom <IEnumerable <OrderViewModel> >(model.Orders); Assert.Equal(2, orders.Count()); }
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); }
/// <summary> /// Activate this method when a login is successful to navigate to a MainPage and remove the /// Former pages for the Navigation. /// It will also update all the search filter for the app, and its crucial that they are in this /// method and not just the startup method. /// </summary> public static void SuccessfulLoginAction() { // NavPage.Navigation.PopModalAsync(); DbLocation dbLocation = new DbLocation(); StudyGroupsController sgc = new StudyGroupsController(); LocationsController lc = new LocationsController(); JobTypesController jtc = new JobTypesController(); CoursesController cc = new CoursesController(); NavPage.Navigation.InsertPageBefore(new MainPage(), NavPage.Navigation.NavigationStack.First()); NavPage.Navigation.PopToRootAsync(); if (dbLocation.GetAllLocations().Count != 0) { lc.CompareServerHash(); sgc.CompareServerHash(); jtc.CompareServerHash(); cc.CompareServerHash(); } else { cc.UpdateCoursesFromServer(); jtc.UpdateJobTypesFromServer(); sgc.UpdateStudyGroupsFromServer(); lc.UpdateLocationsFromServer(); } }
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 void LocationControllerShouldReturnAll() { 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" }; var repoMock = new Mock <IZVRPubRepository>(); repoMock.Setup(c => c.GetLocations()).Returns(new List <Locations> { location1, location2 }); var controller = new LocationsController(repoMock.Object); var result = controller.GetAll(); Assert.NotNull(result.Value); Assert.Same(location1, result.Value[0]); }
public void Setup() { var claim = new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", _userId.ToString()); Thread.CurrentPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim> { claim })); var connectionString = ConfigurationManager.ConnectionStrings["DataContext"].ConnectionString; _context = new DataContext(connectionString); _facade = new LocationFacade(_context, new LocationValidator()); ODataHelper oDataHelper = new ODataHelper(); _controller = new LocationsController(oDataHelper, _facade); _controller.Request = new HttpRequestMessage(); _controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); // Setting the URI of the request here is needed for the API POST method to work _controller.Request.RequestUri = new Uri("http://tempuri.com"); /* * TODO: akrone - Taking on some Techincal Debt doing this, but pulling the Seeder into it's own project would need to * be merged into other development work going on for sprint 60 */ Seeder.SeedWithTestData(_context); }
public async Task LocationsControllerShouldNotPersistTheSameLocationTwice() { var location = new LocationModel { Name = "Prime Spot", StreetAddress = "777 E Wisconsin Ave", City = "Milwaukee", State = "WI", ZipCode = "53202" }; var mockGeocoder = new Mock <IGeocoder>(); var geocodeWithGoodAddress = new GoogleGeocodeResponse { results = new List <Result> { new Result { formatted_address = "This is a nicely formatted address." } } }; mockGeocoder.Setup(g => g.GetGeocodeAsync(location)).Returns(Task.FromResult(geocodeWithGoodAddress)); var locationsController = new LocationsController(null, Context, mockGeocoder.Object); var result = await locationsController.Create(location) as ViewResult; result = await locationsController.Create(location) as ViewResult; Assert.Equal("The given address already exists. Enter a new address", result.ViewData["Error"]); }
public void CanGetAllLocationsInDatabase() { // Arrange Everything We Need For Our Unit Tests options = new DbContextOptionsBuilder <ApplicationDBContext>() .UseInMemoryDatabase(databaseName: "TestRevatureHousingData") .Options; testContext = new ApplicationDBContext(options); dummyLocationsData = new LocationDummyData(); dummyLocations = dummyLocationsData.LocationsList; testLocationRepository = new LocationRepository(testContext); testLocationController = new LocationsController(testLocationRepository); dummyConstantLocation = new Location() { LocationID = 3 }; //Arrange Populate(); //Act var allLocations = testLocationController.GetLocation().Result.ToList(); var allDummyLocations = dummyLocations.Count; Assert.AreEqual(allLocations.Count, allDummyLocations); //Clearing Changes ClearAllChanges(); }
public void LocationsController_Create_Post_Invalid_Model_Should_Send_Back_For_Edit() { // Arrange var mock = new Mock <LocationsBackend>(context); var controller = new LocationsController(context, mock.Object); // Get mock data as view model var dataMock = new LocationsDataMock(); var dataRaw = dataMock.GetAllViewModelList()[0]; var data = new AllTablesViewModel(dataRaw); // Make ModelState Invalid controller.ModelState.AddModelError("test", "test"); // Act var result = controller.Create(data) as ViewResult; // Assert Assert.IsNotNull(result); Assert.AreEqual("Create Post", result.ViewName); }
public void CannotUpdateLocationWithWrongSignature() { // Arrange Everything We Need For Our Unit Tests options = new DbContextOptionsBuilder <ApplicationDBContext>() .UseInMemoryDatabase(databaseName: "TestRevatureHousingData") .Options; testContext = new ApplicationDBContext(options); dummyLocationsData = new LocationDummyData(); dummyLocations = dummyLocationsData.LocationsList; testLocationRepository = new LocationRepository(testContext); testLocationController = new LocationsController(testLocationRepository); dummyConstantLocation = new Location() { LocationID = 3 }; //Arrange Location locale = new Location() { LocationID = 5 }; var postResponse = testLocationController.PostLocation(locale); //Act var putResponse = testLocationController.PutLocation(128923, locale).Result; //Assert Assert.IsInstanceOfType(putResponse, typeof(BadRequestObjectResult)); // Clearing Changes ClearAllChanges(); }
public async void GetAll_WhenFound() { // arrange var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.GetAll()) .ReturnsAsync(() => new Result <IEnumerable <Location> >(ResultCode.Success, TestLocations())); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.GetAll(); var okResult = result as OkObjectResult; var response = okResult.Value as Dictionary <string, object>; // assert Assert.Equal(200, okResult.StatusCode); }
public void CannotDeleteLocationNotInDatabase() { // Arrange Everything We Need For Our Unit Tests options = new DbContextOptionsBuilder <ApplicationDBContext>() .UseInMemoryDatabase(databaseName: "TestRevatureHousingData") .Options; testContext = new ApplicationDBContext(options); dummyLocationsData = new LocationDummyData(); dummyLocations = dummyLocationsData.LocationsList; testLocationRepository = new LocationRepository(testContext); testLocationController = new LocationsController(testLocationRepository); dummyConstantLocation = new Location() { LocationID = 3 }; //Arrange Populate(); //Act var deleteResult = testLocationController.DeleteLocation(12728).Result.Result; var deleteStatusCode = (deleteResult as StatusCodeResult); //Assert Assert.IsInstanceOfType(deleteResult, typeof(NotFoundResult)); Assert.AreEqual(deleteStatusCode.StatusCode, 404); // Clearing Changes ClearAllChanges(); }
public async void Post_WhenConflict() { // arrange var testLocation = TestLocationModel(); var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.Insert(It.IsAny <Location>())) .ReturnsAsync(() => new Result <Guid>(ResultCode.Conflict, TestLocation().Id)); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Post(testLocation); var conflictResult = result as StatusCodeResult; // assert Assert.Equal(409, conflictResult.StatusCode); }
public void CanGetLocationByTrainingCenterInDatabase() { // Arrange Everything We Need For Our Unit Tests options = new DbContextOptionsBuilder <ApplicationDBContext>() .UseInMemoryDatabase(databaseName: "TestRevatureHousingData") .Options; testContext = new ApplicationDBContext(options); dummyLocationsData = new LocationDummyData(); dummyLocations = dummyLocationsData.LocationsList; testLocationRepository = new LocationRepository(testContext); testLocationController = new LocationsController(testLocationRepository); dummyConstantLocation = new Location() { LocationID = 3 }; //Arrange Populate(); //Act var GetLocationWithProviderResult = testLocationController.GetLocationByTrainingCenter(14.ToString()).Result.Value.ToList()[0]; //Assert Assert.IsInstanceOfType(GetLocationWithProviderResult, typeof(Location)); //Clearing Changes ClearAllChanges(); }
public async void Delete_WhenNotFound() { // arrange var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.Delete(It.IsAny <Guid>())) .ReturnsAsync(() => ResultCode.NotFound); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Delete(TestLocation().Id); var notFoundResult = result as NotFoundResult; // assert Assert.NotNull(notFoundResult); }
public void CantGetLocationByTrainingCenterNotInDatabase() { // Arrange Everything We Need For Our Unit Tests options = new DbContextOptionsBuilder <ApplicationDBContext>() .UseInMemoryDatabase(databaseName: "TestRevatureHousingData") .Options; testContext = new ApplicationDBContext(options); dummyLocationsData = new LocationDummyData(); dummyLocations = dummyLocationsData.LocationsList; testLocationRepository = new LocationRepository(testContext); testLocationController = new LocationsController(testLocationRepository); dummyConstantLocation = new Location() { LocationID = 3 }; //Arrange Populate(); string inValidTrainingCenter = "InValidTrainingCenter"; //Act var GetLocationWithProviderResult = testLocationController.GetLocationByTrainingCenter(inValidTrainingCenter).Result.Value.ToList(); //Assert Assert.AreEqual(GetLocationWithProviderResult.Count(), 0); ClearAllChanges(); }
public async void GetAllVehicles_WithBadId() { // arrange var targetId = Guid.Empty; var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.GetVehicles(It.IsAny <Guid>())) .ReturnsAsync(() => new Result <IEnumerable <Vehicle> >(ResultCode.Success, TestVehicles())); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.GetAllVehicles(targetId); var badRequestResult = result as BadRequestObjectResult; // assert Assert.NotNull(badRequestResult); }
public void CannotAddSameLocationTwiceInDatabase() { // Arrange Everything We Need For Our Unit Tests options = new DbContextOptionsBuilder <ApplicationDBContext>() .UseInMemoryDatabase(databaseName: "TestRevatureHousingData") .Options; testContext = new ApplicationDBContext(options); dummyLocationsData = new LocationDummyData(); dummyLocations = dummyLocationsData.LocationsList; testLocationRepository = new LocationRepository(testContext); testLocationController = new LocationsController(testLocationRepository); dummyConstantLocation = new Location() { LocationID = 3 }; //Arrange Location dummyLocation = dummyConstantLocation; var postResponse = testLocationController.PostLocation(dummyLocation); //Act var secondPostResult = testLocationController.PostLocation(dummyLocation); var postStatusCode = (secondPostResult as StatusCodeResult); //Assert Assert.IsInstanceOfType(secondPostResult, typeof(StatusCodeResult)); Assert.AreEqual(postStatusCode.StatusCode, 409); //Clearing Changes ClearAllChanges(); }
public async void GetAll_ReturnsData() { // arrange var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.GetAll()) .ReturnsAsync(() => new Result <IEnumerable <Location> >(ResultCode.Success, TestLocations())); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); dataStructureConverterMoq.Setup(x => x.ConvertAndMap <IEnumerable <LocationModel>, IEnumerable <Location> >(It.IsAny <string>(), It.IsAny <IEnumerable <Location> >())) .Returns(new Dictionary <string, object> { { "locations", TestLocations() } }); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.GetAll(); var okResult = result as OkObjectResult; var response = okResult.Value as Dictionary <string, object>; // assert Assert.NotNull(response.Values); }
public async Task LocationsControllerDoesNotReturnAddressIfAddressNotFound() { var badLocation = new LocationModel { Name = "Imaginary Spot", StreetAddress = "1313 Mockingbird Ln", City = "Keflavik", State = "CZ", ZipCode = "98765" }; var badGeocode = new GoogleGeocodeResponse { results = Enumerable.Empty <Result>().ToList() }; var mockGeocoder = new Mock <IGeocoder>(); mockGeocoder.Setup(g => g.GetGeocodeAsync(badLocation)).Returns(Task.FromResult(badGeocode)); var locationsController = new LocationsController(null, Context, mockGeocoder.Object); var result = await locationsController.Create(badLocation) as ViewResult; Assert.Equal( "This address could not be found. Please check this address and try again!", result.ViewData["Error"]); }
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 Cannot_Edit_Nonexistent_Location() { // Arrange - create the mock repository Mock <ILocationRepository> mock = new Mock <ILocationRepository>(); mock.Setup(m => m.Locations).Returns(new List <Location> { new Location { Id = 1, Name = "L1", State = "MI" }, new Location { Id = 2, Name = "L2", State = "IL" }, new Location { Id = 3, Name = "L3", State = "MI" } }); // Arrange LocationsController target = new LocationsController(mock.Object); //Action Location result = (Location)target.Edit(4).ViewData.Model; //Assert Assert.IsNull(result); }