Exemplo n.º 1
0
        public async Task ParkingLotShouldBeReturned()
        {
            using (var context = await NewParkSharkInMemoryTestContext())
            {
                //Setup test data
                var division = new Division("Apple", "Apple Computer", "Steve Jobs");
                await context.ParkSharkDbContext.Divisions.AddAsync(division);

                var parkingLot1 = new ParkingLot(
                    "PL1",
                    division.Id,
                    new Contact("Maarten", "00554433", null, "*****@*****.**",
                                new Address("Streety", "Numbery", "Codey", "Namey")),
                    BuildingTypes.Underground,
                    15.55m,
                    500
                    );
                await context.ParkSharkDbContext.ParkingLots.AddAsync(parkingLot1);

                var parkingLot2 = new ParkingLot(
                    "PL2",
                    division.Id,
                    new Contact("John", "005777433", null, "*****@*****.**",
                                new Address("Streety2", "Numbery3", "Codey4", "Namey5")),
                    BuildingTypes.Underground,
                    15.55m,
                    500
                    );
                await context.ParkSharkDbContext.ParkingLots.AddAsync(parkingLot2);

                await context.ParkSharkDbContext.SaveChangesAsync();

                var parkingLotService = new ParkingLotService(context.ParkSharkDbContext);

                var controller        = new ParkingLotsController(context.Mapper, parkingLotService);
                var parkingLot1Result = GetResult <ParkingLotDto>((await controller.GetParkingLot(parkingLot1.Id)));
                var parkingLot2Result = GetResult <ParkingLotDto>((await controller.GetParkingLot(parkingLot2.Id)));

                Assert.AreEqual(parkingLot1.Name, parkingLot1Result.Name);
                Assert.AreEqual(parkingLot1.Capacity, parkingLot1Result.Capacity);
                Assert.AreEqual(parkingLot1.BuildingType.Name, parkingLot1Result.BuildingType.Name);
                Assert.AreEqual(parkingLot1.Contact.Email, parkingLot1Result.Contact.Email);
                Assert.AreEqual(parkingLot1.Contact.Address.Street, parkingLot1Result.Contact.Address.Street);

                Assert.AreEqual(parkingLot2.Name, parkingLot2Result.Name);
                Assert.AreEqual(parkingLot2.Capacity, parkingLot2Result.Capacity);
                Assert.AreEqual(parkingLot2.BuildingType.Name, parkingLot2Result.BuildingType.Name);
                Assert.AreEqual(parkingLot2.Contact.Email, parkingLot2Result.Contact.Email);
                Assert.AreEqual(parkingLot2.Contact.Address.Street, parkingLot2Result.Contact.Address.Street);
            }
        }
Exemplo n.º 2
0
        public void TestUpdateParkingLot()
        {
            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 updatedParkingLot    = new ParkingLot()
                    {
                        Id = 1, ParkingDisplayName = "NewName", LocationLocality = "Whitefield", LocationBuilding = "TestBuilding", LocationCity = "Bangalore", LocationPinCode = 560000
                    };
                    var parkingLotObjUpdated = parkingLotController.PutParkingLot(1, updatedParkingLot);
                    var getParkingLotObj     = parkingLotController.GetParkingLot(1);
                    Assert.Equal(updatedParkingLot.ParkingDisplayName, getParkingLotObj.Result.Value.ParkingDisplayName);
                }
            }
            finally
            {
                connection.Close();
            }
        }