Exemple #1
0
        public async void CreateDuplicateReferences()
        {
            var options = TestHelpers.GetDbOptions(nameof(CreateDuplicateReferences));

            GameViewModel exptected1;
            GameViewModel exptected2;

            using (var context = new GamesKeyDbContext(options))
            {
                exptected1 = await new GamesService(context).CreateAsync(_game01);
            }

            using (var context = new GamesKeyDbContext(options))
            {
                exptected2 = await new GamesService(context).CreateAsync(_game03);
            }

            var actual = new GamesKeyDbContext(options);

            Assert.Equal(exptected1.Developer, (await actual.Developers.SingleAsync()).Name);
            Assert.Equal(exptected1.Publisher, (await actual.Publishers.SingleAsync()).Name);
            Assert.Equal(exptected1.Genres, actual.Genres.Select(g => g.Name));
            // TODO: test for correct tags as well.
            Assert.Equal(exptected1.Model, await actual.Games.FirstAsync());
            Assert.Equal(exptected2.Model, await actual.Games.LastAsync());
        }
Exemple #2
0
        public async void FindRequired()
        {
            var options = TestHelpers.GetDbOptions(nameof(FindRequired));

            using (var context = new GamesKeyDbContext(options))
            {
                await new GamesService(context).CreateAsync(_game04);
            }

            using (var context = new GamesKeyDbContext(options))
            {
                Assert.Equal(_game04, await new GamesService(context).FindAsync((await context.Games.FirstAsync()).Id));
            }
        }
Exemple #3
0
        public async void CreateRequired()
        {
            var options = TestHelpers.GetDbOptions(nameof(CreateRequired));

            using (var context = new GamesKeyDbContext(options))
            {
                var exptected = await new GamesService(context).CreateAsync(_game04);

                Assert.Empty(context.Developers);
                Assert.Empty(context.Publishers);
                Assert.Empty(context.Genres);
                Assert.Empty(context.Tags);
                Assert.Equal(exptected.Model, await context.Games.SingleAsync());
            }
        }
Exemple #4
0
        public async void Create()
        {
            var options = TestHelpers.GetDbOptions(nameof(Create));

            using (var context = new GamesKeyDbContext(options))
            {
                var exptected = await new GamesService(context).CreateAsync(_game01);

                Assert.Equal(exptected.Developer, (await context.Developers.SingleAsync()).Name);
                Assert.Equal(exptected.Publisher, (await context.Publishers.SingleAsync()).Name);
                Assert.Equal(exptected.Genres, context.Genres.Select(g => g.Name));
                Assert.Equal(exptected.Tags, context.Tags.Select(t => t.Name));
                Assert.Equal(exptected.Model, await context.Games.SingleAsync());
            }
        }
Exemple #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, GamesKeyDbContext dbcontext, UserManager <ApplicationUser> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            // Returns the angular index.html if a page is not found.
            app.UseMiddleware <NotFoundMiddleware>(env);

            // Cors configuration
            app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials().Build());

            // Serves the angular Index.html from wwwroot
            app.UseDefaultFiles();
            app.UseStaticFiles();

            app.UseAuthentication();

            dbcontext.Database.Migrate();

            if (env.IsDevelopment())
            {
                using (userManager)
                {
                    if (!userManager.Users.Any())
                    {
                        userManager.CreateAsync(new ApplicationUser {
                            UserName = "******", Email = "*****@*****.**", EmailConfirmed = true
                        }, "Password123!");
                    }
                }
            }

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}");
            });
        }
        public async void Find()
        {
            var options = TestHelpers.GetDbOptions(nameof(Find));

            using (var context = new GamesKeyDbContext(options))
            {
                await new PicturesService(context).CreateAsync(_picture01);
            }

            PictureViewModel actual;

            using (var context = new GamesKeyDbContext(options))
            {
                actual = await new PicturesService(context).FindAsync((await context.Pictures.FirstAsync()).Id);
            }

            Assert.Equal(_picture01.File, actual.File);
        }
Exemple #7
0
        public async void FindMany()
        {
            var options = TestHelpers.GetDbOptions(nameof(FindMany));

            using (var context = new GamesKeyDbContext(options))
            {
                await new GamesService(context).CreateAsync(_game01);
            }

            using (var context = new GamesKeyDbContext(options))
            {
                await new GamesService(context).CreateAsync(_game02);
            }

            using (var context = new GamesKeyDbContext(options))
            {
                var actual = new GamesService(context).Find();

                Assert.Equal(_game01.Model, actual.First().Model);
                Assert.Equal(_game02.Model, actual.Last().Model);
            }
        }
 public PicturesService(GamesKeyDbContext context)
 {
     _context = context;
 }