Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
0
        public void CantGetLocationInEmptyDatabase()
        {
            // 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
            };
            //Act
            var getLocationResult = testLocationController.GetLocation(8191).Result.Value;

            //Assert
            Assert.AreEqual(getLocationResult, null);
            ClearAllChanges();
        }