Exemple #1
0
 public IntegrationTests()
 {
     server           = new TestServer(new WebHostBuilder().UseStartup <TestStartup>());
     client           = server.CreateClient();
     context          = (PokeGymContext)server.Host.Services.GetService(typeof(PokeGymContext));
     fluentMockServer = (FluentMockServer)server.Host.Services.GetService(typeof(FluentMockServer));
     DataHelper.SeedDatabase(context);
 }
Exemple #2
0
        public PokeGymDbTestFixture()
        {
            Connection = new SqliteConnection("Datasource=:memory:");
            Connection.Open();

            var options = new DbContextOptionsBuilder <PokeGymContext>()
                          .UseSqlite(Connection)
                          .Options;

            Context = new PokeGymContext(options);
            Context.Database.EnsureCreated();

            DataHelper.SeedDatabase(Context);

            Repository = new PokeGymRepository(Context);
        }
Exemple #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkSqlite()
                                  .BuildServiceProvider();

            connection = new SqliteConnection("Datasource=:memory:");
            connection.Open();

            services.AddDbContext <PokeGymContext>(options =>
            {
                options.UseSqlite(connection);
                options.UseInternalServiceProvider(serviceProvider);
            });

            var sp = services.BuildServiceProvider();

            using (var scope = sp.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                context = scopedServices.GetRequiredService <PokeGymContext>();
                context.Database.EnsureCreated();
            }

            services.AddScoped <PokeGymRepository>();

            var settings = new PokedexClientSettings()
            {
                baseUrl = new Uri(fluentMockServer.Urls[0])
            };

            services.AddSingleton(settings);
            services.AddHttpClient <PokeDexClient>();

            services.AddSingleton(fluentMockServer);

            services.AddControllers()
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddApplicationPart(typeof(PokeGymController).Assembly);
        }
Exemple #4
0
        public static void SeedDatabase(PokeGymContext context)
        {
            var instructorBrock = new Instructor
            {
                FirstName = "Brock",
                LastName  = "Takeshi",
                GymRank   = "Gym Leader"
            };

            var instructorMisty = new Instructor
            {
                FirstName = "Misty",
                LastName  = "Kasumi",
                GymRank   = "Gym Leader"
            };


            var rockOutClass = new Class
            {
                ClassId      = 1,
                Name         = "Rocking Out",
                Description  = "Electric guitar lessons for all ages.",
                Instructor   = instructorBrock,
                Reservations = new List <Reservation>()
                {
                    new Reservation()
                    {
                        TrainerId = 1
                    },
                    new Reservation()
                    {
                        TrainerId = 2
                    },
                    new Reservation()
                    {
                        TrainerId = 3
                    }
                }
            };

            var swimClass = new Class
            {
                ClassId      = 2,
                Name         = "Aquatic Adventures",
                Description  = "Swimming lessons for children.",
                Instructor   = instructorMisty,
                Reservations = new List <Reservation>()
                {
                    new Reservation()
                    {
                        TrainerId = 1
                    },
                    new Reservation()
                    {
                        TrainerId = 2
                    },
                    new Reservation()
                    {
                        TrainerId = 3
                    },
                    new Reservation()
                    {
                        TrainerId = 4
                    }
                }
            };

            var introToPokemonBattles = new Class
            {
                ClassId      = 3,
                Name         = "Casting the First Stone",
                Description  = "Introductory class for Pokemon battles.",
                Instructor   = instructorBrock,
                Reservations = new List <Reservation>()
                {
                    new Reservation()
                    {
                        TrainerId = 5
                    },
                    new Reservation()
                    {
                        TrainerId = 2
                    },
                    new Reservation()
                    {
                        TrainerId = 3
                    },
                    new Reservation()
                    {
                        TrainerId = 6
                    },
                    new Reservation()
                    {
                        TrainerId = 7
                    },
                    new Reservation()
                    {
                        TrainerId = 8
                    }
                }
            };

            context.Classes.AddRange(new List <Class> {
                rockOutClass, swimClass, introToPokemonBattles
            });
            context.SaveChanges();
        }