public async System.Threading.Tasks.Task TestClosingABooking()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            try
            {
                var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                              .UseSqlite(connection)
                              .Options;

                var operationalStoreOptionsMock = new Mock <OperationalStoreOptions>();
                operationalStoreOptionsMock.Object.ConfigureDbContext = dbContext => dbContext.UseSqlite(connection);
                var iOptionsMock = Options.Create <OperationalStoreOptions>(operationalStoreOptionsMock.Object);

                // Create the schema in the database
                using (var context = new ApplicationDbContext(options, iOptionsMock))
                {
                    context.Database.EnsureCreated();
                }

                // Run the test against one instance of the context
                using (var context = new ApplicationDbContext(options, iOptionsMock))
                {
                    var bookingController    = new BookingsController(context);
                    var locationController   = new LocationsController(context);
                    var parkingLotController = new ParkingLotsController(context);

                    Location location = new Location()
                    {
                        LocationLocality = "Whitefield", LocationBuilding = "TestBuilding", LocationCity = "Bangalore", LocationPinCode = 560000
                    };
                    await locationController.PostLocation(location);

                    ParkingLot newParkingLot = new ParkingLot()
                    {
                        ParkingDisplayName = "TestPL", LocationLocality = "Whitefield", LocationBuilding = "TestBuilding", LocationCity = "Bangalore", LocationPinCode = 560000
                    };
                    await parkingLotController.PostParkingLot(newParkingLot);

                    context.SaveChanges();
                    await bookingController.PostBooking(1);

                    context.SaveChanges();
                    bookingController.CloseBooking(1);
                    context.SaveChanges();
                    var booking = await bookingController.GetBooking(1);

                    Assert.True(booking.Value.IsOccupied == false);
                }
            }
            finally
            {
                connection.Close();
            }
        }
예제 #2
0
        public async System.Threading.Tasks.Task TestCreateParkingLotByIdAsync()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            try
            {
                var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                              .UseSqlite(connection)
                              .Options;

                var operationalStoreOptionsMock = new Mock <OperationalStoreOptions>();
                operationalStoreOptionsMock.Object.ConfigureDbContext = dbContext => dbContext.UseSqlite(connection);
                var iOptionsMock = Options.Create <OperationalStoreOptions>(operationalStoreOptionsMock.Object);

                // Create the schema in the database
                using (var context = new ApplicationDbContext(options, iOptionsMock))
                {
                    context.Database.EnsureCreated();
                }

                // Run the test against one instance of the context
                using (var context = new ApplicationDbContext(options, iOptionsMock))
                {
                    var        parkingLotController = new ParkingLotsController(context);
                    ParkingLot newParkingLot        = new ParkingLot()
                    {
                        ParkingDisplayName = "TestPL", LocationLocality = "Whitefield", LocationBuilding = "TestBuilding", LocationCity = "Bangalore", LocationPinCode = 560000
                    };
                    await parkingLotController.PostParkingLot(newParkingLot);

                    context.SaveChanges();
                    //Assert.Equal(1, parkingLotObj.Id);
                }


                // Use a separate instance of the context to verify correct data was saved to database
                using (var context = new ApplicationDbContext(options, iOptionsMock))
                {
                    Assert.Equal(1, context.ParkingLot.Count());
                    Assert.Equal("Whitefield", context.ParkingLot.Single().LocationLocality);
                }
            }
            finally
            {
                connection.Close();
            }
        }