Пример #1
0
            public async Task Should_not_return_inactive_videos()
            {
                //Arrange
                Genre expectedGenre = TestDataFactory.CreateGenre();
                Genre genre         = TestDataFactory.CreateGenre();

                List <Video> videos = new List <Video>()
                {
                    TestDataFactory.CreateVideo(TestDataFactory.CreateKind(), expectedGenre),
                    TestDataFactory.CreateVideo(TestDataFactory.CreateKind(), expectedGenre),
                    TestDataFactory.CreateVideo(TestDataFactory.CreateKind(), genre)
                };

                videos.First().IsInactive = true;

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.AddRange(videos);
                    context.SaveChanges();
                }

                //Act
                IEnumerable <Video> result = await RepoUnderTest.GetVideosByGenreIdAsync(expectedGenre.Id);

                //Assert
                result.Any(x => x.IsInactive).Should().BeFalse();
            }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, VODContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            // Seeds the development Database. Turn off in production
            //DbInitializer.Initialize(db);

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Пример #3
0
            public async Task Should_not_return_inactive_videos()
            {
                //Arrange
                Kind expectedKind = TestDataFactory.CreateKind();

                List <Video> videos = new List <Video>()
                {
                    TestDataFactory.CreateVideo(expectedKind),
                    TestDataFactory.CreateVideo(expectedKind),
                };

                GenData.RepeatCount = 1;
                GenData.AddManyTo(videos, TestDataFactory.CreateVideo);
                videos.First().IsInactive = true;

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.AddRange(videos);
                    context.SaveChanges();
                }

                //Act
                IEnumerable <Video> result = await RepoUnderTest.GetVideosByKindIdAsync(expectedKind.Id);

                //Assert
                result.Any(x => x.IsInactive).Should().BeFalse();
            }
Пример #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, VODContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            // add the seed data when the application is started.
            DbInitializer.Initialize(db);

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Пример #5
0
            public async Task Should_return_empty_collection()
            {
                //Arrange
                string title          = "Expected Title";
                string titleToSearch  = "not existing";
                Video  expectedVideo0 = TestDataFactory.CreateVideo();

                expectedVideo0.Title = title;
                Video expectedVideo1 = TestDataFactory.CreateVideo();

                expectedVideo1.Title = title;
                List <Video> videos = new List <Video>(2)
                {
                    expectedVideo0,
                    expectedVideo1
                };

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.AddRange(videos);
                    context.SaveChanges();
                }

                //Act
                IEnumerable <Video> result = await RepoUnderTest.GetVideosContainTitleAsync(titleToSearch);

                //Assert
                Assert.Empty(result);
            }
Пример #6
0
            public async Task Should_return_the_videos_with_specified_genre()
            {
                //Arrange
                Genre expectedGenre = TestDataFactory.CreateGenre();
                Genre genre         = TestDataFactory.CreateGenre();

                List <Video> videos = new List <Video>()
                {
                    TestDataFactory.CreateVideo(TestDataFactory.CreateKind(), expectedGenre),
                    TestDataFactory.CreateVideo(TestDataFactory.CreateKind(), expectedGenre),
                    TestDataFactory.CreateVideo(TestDataFactory.CreateKind(), genre)
                };

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.AddRange(videos);
                    context.SaveChanges();
                }

                List <Video> expectedVideos = videos.Take(2).ToList();

                //Act
                IEnumerable <Video> result = await RepoUnderTest.GetVideosByGenreIdAsync(expectedGenre.Id);

                //Assert
                result.Should().BeEquivalentTo(expectedVideos, o =>
                                               o.Excluding(x => x.Kind)
                                               .Excluding(x => x.Genre));
            }
Пример #7
0
        public static void RecreateDatabase(VODContext context)

        {
            context.Database.EnsureDeleted();

            context.Database.EnsureCreated();
        }
Пример #8
0
            public void Should_update_and_return_the_specified_video()
            {
                // Arrange
                Kind  newKind  = TestDataFactory.CreateKind();
                Genre newGenre = TestDataFactory.CreateGenre();
                Video oldVideo = TestDataFactory.CreateVideo();

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.Add(oldVideo);
                    context.Genres.Add(newGenre);
                    context.Kinds.Add(newKind);
                    context.SaveChanges();
                }

                Video newVideo = TestDataFactory.CreateVideo(newKind, newGenre);

                newVideo.Id = oldVideo.Id;

                //Act
                Video result = RepoUnderTest.Update(newVideo);

                //Assert
                result.Should().BeEquivalentTo(newVideo);
            }
Пример #9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              VODContext db)
        {
            db.SeedMembershipData();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else

            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            //app.UseCookiePolicy();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    "default",
                    "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }
Пример #10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, VODContext db)
        {
            db.SeedMembershipData();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }
Пример #11
0
            public async Task Should_return_the_videos_with_specified_kind()
            {
                //Arrange
                Kind expectedKind = TestDataFactory.CreateKind();

                List <Video> videos = new List <Video>()
                {
                    TestDataFactory.CreateVideo(expectedKind),
                    TestDataFactory.CreateVideo(expectedKind),
                };

                GenData.RepeatCount = 1;
                GenData.AddManyTo(videos, TestDataFactory.CreateVideo);

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.AddRange(videos);
                    context.SaveChanges();
                }

                List <Video> expectedVideos = videos.Take(2).ToList();

                //Act
                IEnumerable <Video> result = await RepoUnderTest.GetVideosByKindIdAsync(expectedKind.Id);

                //Assert
                result.Should().BeEquivalentTo(expectedVideos, o =>
                                               o.Excluding(x => x.Kind)
                                               .Excluding(x => x.Genre));
            }
Пример #12
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, VODContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            //12장
            //app.UseCookiePolicy();

            // Uncomment to recreate the database. ALL DATA WILL BE LOST !
            // DbInitializer.RecreateDatabase(db);
            //Uncomment to seed the database
            DbInitializer.Initialize(db);


            app.UseAuthentication();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Пример #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, VODContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            DbInitializer.Initialize(db);

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
Пример #14
0
        public VODContext CreateContext()
        {
            if (this.Connection == null)
            {
                this.Connection = new SqliteConnection("DataSource=:memory:");

                this.Connection.Open();

                DbContextOptions <VODContext> options = CreateOptions();
                using VODContext context = new VODContext(options);
                context.Database.EnsureCreated();
            }

            return(new VODContext(CreateOptions()));
        }
Пример #15
0
            public async Task Should_return_null()
            {
                //Arrange
                Video expectedVideo = TestDataFactory.CreateVideo();

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.Add(expectedVideo);
                    context.SaveChanges();
                }

                //Act
                Video result = await RepoUnderTest.GetAsync(new Guid());

                //Assert
                Assert.Null(result);
            }
Пример #16
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, VODContext db)
        {
            //LoggerFactory.AddConsole(Configuration.GetSection("Logging"));
            //loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //DbInitializer.RecreateDatabase(db);
            DbInitializer.Initialize(db);

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
Пример #17
0
            public async Task Should_return_the_expected_genre()
            {
                //Arrange
                Genre expectedGenre = TestDataFactory.CreateGenre();

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Genres.Add(expectedGenre);
                    context.SaveChanges();
                }

                //Act
                Genre result = await RepoUnderTest.GetAsync(expectedGenre.Id);

                //Assert
                result.Should().BeEquivalentTo(expectedGenre);
            }
Пример #18
0
            public async Task Should_return_the_expected_Kind()
            {
                //Arrange
                Kind expectedKind = TestDataFactory.CreateKind();

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Kinds.Add(expectedKind);
                    context.SaveChanges();
                }

                //Act
                Kind result = await RepoUnderTest.GetAsync(expectedKind.Id);

                //Assert
                result.Should().BeEquivalentTo(expectedKind);
            }
Пример #19
0
            public async Task Should_return_the_expected_video()
            {
                //Arrange
                Video expectedVideo = TestDataFactory.CreateVideo();

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.Add(expectedVideo);
                    context.SaveChanges();
                }

                //Act
                Video result = await RepoUnderTest.GetAsync(expectedVideo.Id);

                //Assert
                result.Should().BeEquivalentTo(expectedVideo, o =>
                                               o.Excluding(x => x.Kind)
                                               .Excluding(x => x.Genre));
            }
Пример #20
0
            public async Task Should_return_all_genres()
            {
                //Arrange
                GenData.RepeatCount = 3;
                List <Genre> expectedGenres = new List <Genre>(GenData.RepeatCount);

                GenData.AddManyTo(expectedGenres, TestDataFactory.CreateGenre);

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Genres.AddRange(expectedGenres);
                    context.SaveChanges();
                }

                //Act
                IEnumerable <Genre> result = await RepoUnderTest.GetAsync();

                //Assert
                result.Should().BeEquivalentTo(expectedGenres);
            }
Пример #21
0
            public async Task Should_return_empty_kind_does_not_exist()
            {
                //Arrange
                GenData.RepeatCount = 3;
                List <Video> expectedVideos = new List <Video>(GenData.RepeatCount);

                GenData.AddManyTo(expectedVideos, TestDataFactory.CreateVideo);

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.AddRange(expectedVideos);
                    context.SaveChanges();
                }

                //Act
                IEnumerable <Video> result = await RepoUnderTest.GetVideosByKindIdAsync(Guid.NewGuid());

                //Assert
                Assert.Empty(result);
            }
Пример #22
0
            public async Task Should_return_all_videos()
            {
                //Arrange
                GenData.RepeatCount = 3;
                List <Video> expectedVideos = new List <Video>(GenData.RepeatCount);

                GenData.AddManyTo(expectedVideos, TestDataFactory.CreateVideo);

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.AddRange(expectedVideos);
                    context.SaveChanges();
                }

                //Act
                IEnumerable <Video> result = await RepoUnderTest.GetAsync();

                //Assert
                result.Should().BeEquivalentTo(expectedVideos, o =>
                                               o.Excluding(x => x.Kind)
                                               .Excluding(x => x.Genre));
            }
Пример #23
0
            public async Task Should_return_empty_collection()
            {
                //Arrange
                Genre notIncludedGenre = TestDataFactory.CreateGenre();

                GenData.RepeatCount = 3;
                List <Video> videos = new List <Video>(GenData.RepeatCount);

                GenData.AddManyTo(videos, TestDataFactory.CreateVideo);

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.AddRange(videos);
                    context.Genres.Add(notIncludedGenre);
                    context.SaveChanges();
                }

                //Act
                IEnumerable <Video> result = await RepoUnderTest.GetVideosByGenreIdAsync(notIncludedGenre.Id);

                //Assert
                Assert.Empty(result);
            }
Пример #24
0
            public async Task Should_not_return_inactive_videos()
            {
                //Arrange
                GenData.RepeatCount = 3;
                List <Video> videos = new List <Video>(GenData.RepeatCount);

                GenData.AddManyTo(videos, TestDataFactory.CreateVideo);
                videos.Last().IsInactive = true;

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.AddRange(videos);
                    context.SaveChanges();
                }

                List <Video> expectedVideos = videos.Take(2).ToList();

                //Act
                IEnumerable <Video> result = await RepoUnderTest.GetAsync();

                //Assert
                result.Any(x => x.IsInactive).Should().BeFalse();
            }
Пример #25
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, VODContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseMigrationsEndPoint(); //https://github.com/dotnet/aspnetcore/pull/24588
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();

            // app.UseCookiePolicy();

            //Uncomment to seed the database
            //DbInitializer.Initialize(dbContext);

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapRazorPages();

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }
Пример #26
0
            public async Task Should_return_videos_with_specified_title()
            {
                //Arrange
                string expectedTitle = "Expected Title";
                string titleToSearch = "EXPected";

                Video expectedVideo0 = TestDataFactory.CreateVideo();

                expectedVideo0.Title = expectedTitle;
                Video expectedVideo1 = TestDataFactory.CreateVideo();

                expectedVideo1.Title = expectedTitle;
                List <Video> videos = new List <Video>(2)
                {
                    expectedVideo0,
                    expectedVideo1
                };

                GenData.RepeatCount = 3;
                GenData.AddManyTo(videos, () => TestDataFactory.CreateVideo());

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.AddRange(videos);
                    context.SaveChanges();
                }

                List <Video> expectedVideos = videos.Take(2).ToList();

                //Act
                IEnumerable <Video> result = await RepoUnderTest.GetVideosContainTitleAsync(titleToSearch);

                //Assert
                result.Should().BeEquivalentTo(expectedVideos, o =>
                                               o.Excluding(x => x.Kind)
                                               .Excluding(x => x.Genre));
            }
Пример #27
0
            public void Should_update_and_return_the_specified_genre()
            {
                // Arrange
                Genre oldGenre = TestDataFactory.CreateGenre();

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Genres.Add(oldGenre);
                    context.SaveChanges();
                }

                Genre newGenre = new Genre()
                {
                    Id     = oldGenre.Id,
                    Name   = "new genre",
                    Videos = null
                };

                // Act
                Genre result = RepoUnderTest.Update(newGenre);

                // Assert
                result.Should().BeEquivalentTo(newGenre);
            }
Пример #28
0
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder
            .UseEnvironment("Testing")
            .ConfigureTestServices(services =>
            {
                DbContextOptions <VODContext> options = new
                                                        DbContextOptionsBuilder <VODContext>()
                                                        .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                        .Options;

                services.AddScoped <VODContext>(serviceProvider => new TestVODContext(options));

                services.Replace(ServiceDescriptor.Scoped(_ => new UsersContextFactory().InMemoryUserManager));

                ServiceProvider sp = services.BuildServiceProvider();

                using IServiceScope scope = sp.CreateScope();

                IServiceProvider scopedServices = scope.ServiceProvider;
                VODContext db = scopedServices.GetRequiredService <VODContext>();
                db.Database.EnsureCreated();
            });
        }
Пример #29
0
            public async Task Should_return_empty_collection()
            {
                //Arrange
                Kind         kindWithoutVideos = TestDataFactory.CreateKind();
                Kind         kind   = TestDataFactory.CreateKind();
                List <Video> videos = new List <Video>()
                {
                    TestDataFactory.CreateVideo(kind),
                    TestDataFactory.CreateVideo(kind)
                };

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Videos.AddRange(videos);
                    context.Kinds.Add(kindWithoutVideos);
                    context.SaveChanges();
                }

                //Act
                IEnumerable <Video> result = await RepoUnderTest.GetVideosByKindIdAsync(kindWithoutVideos.Id);

                //Assert
                Assert.Empty(result);
            }
Пример #30
0
            public void Should_update_and_return_the_specified_Kind()
            {
                // Arrange
                Kind oldKind = TestDataFactory.CreateKind();

                using (VODContext context = ContextFactory.CreateContext())
                {
                    context.Kinds.Add(oldKind);
                    context.SaveChanges();
                }

                Kind newKind = new Kind()
                {
                    Id     = oldKind.Id,
                    Name   = "new Kind",
                    Videos = null
                };

                // Act
                Kind result = RepoUnderTest.Update(newKind);

                // Assert
                result.Should().BeEquivalentTo(newKind);
            }