public void ReturnsListOfIds_WhenCategories_Present()
        {
            var options            = DbContextMock.GetOptions("ReturnsListOfIds_WhenCategories_Present");
            var searchedCategories = new List <string>()
            {
                "Test1", "Test2", "TestTest"
            };

            using (var context = new BubaTubeDbContext(options))
            {
                context.Categories.AddRange(CategoryMockData.GetListOfCategoryModels());
                context.SaveChanges();

                var categoryGetService = new CategoryQueries(context, fakeMapper);
                var result             = categoryGetService.TakeApprovedCategoryIds(searchedCategories);

                var test1FromDb = context.Categories
                                  .FirstOrDefault(x => x.CategoryName == "Test1");

                var test2FromDb = context.Categories
                                  .FirstOrDefault(x => x.CategoryName == "Test2");

                Assert.NotEmpty(result);
                Assert.Equal(2, result.Count());
                Assert.Contains(result, x => x == test1FromDb.Id);
                Assert.Contains(result, x => x == test2FromDb.Id);
            }
        }
        public void ReturnsEmptyList_WhenCategory_NotApproved()
        {
            var options            = DbContextMock.GetOptions("ReturnsEmptyList_WhenCategory_NotApproved");
            var searchedCategories = new List <string>()
            {
                "Test0"
            };

            using (var context = new BubaTubeDbContext(options))
            {
                context.Categories.AddRange(CategoryMockData.GetListOfCategoryModels());
                context.SaveChanges();

                var categoryGetService = new CategoryQueries(context, fakeMapper);
                var result             = categoryGetService.TakeApprovedCategoryIds(searchedCategories);

                Assert.Empty(result);
            }
        }
        public void ReturnsAllCategories()
        {
            var options            = DbContextMock.GetOptions("ReturnsAllCategories");
            var searchedCategories = new List <string>()
            {
                "Test0"
            };
            IList <int> result;

            using (var context = new BubaTubeDbContext(options))
            {
                context.Categories.AddRange(CategoryMockData.GetListOfCategoryModels());
                context.SaveChanges();

                var categoryGetService = new CategoryQueries(context, fakeMapper);
                result = categoryGetService.TakeAllCategoryIds(searchedCategories);

                Assert.Equal(1, result.Count);
            }
        }
        public async Task CreatesNavigationProperty_VideoCategory()
        {
            var options             = DbContextMock.GetOptions("CreatesNavigationProperty_VideoCategory");
            var mockFile            = new Mock <IFormFile>();
            var mockFileCommands    = new Mock <IFileCommands>();
            var mockFileQueries     = new Mock <IFileQueries>();
            var mockCategoryQueries = new Mock <ICategoryQueries>();
            var categories          = new List <string>();

            using (var context = new BubaTubeDbContext(options))
            {
                context.Categories.AddRange(CategoryMockData.GetListOfCategoryModels());
                context.SaveChanges();

                var categoryFromDb = context.Categories
                                     .First(x => x.IsАpproved == true);
                mockCategoryQueries
                .Setup(mock => mock.TakeAllCategoryIds(categories))
                .Returns(new List <int>()
                {
                    categoryFromDb.Id
                });

                var model = this.GetVideoDto();
                model.Categories = categories;

                var uploadVideoService = new VideoCommands(
                    context,
                    mockFileCommands.Object,
                    mockFileQueries.Object,
                    mockCategoryQueries.Object,
                    fakeMapper);

                await uploadVideoService.Save(model, mockFile.Object);

                Assert.Equal(categoryFromDb.CategoryName,
                             context.VideoCategory.First().Category.CategoryName);
            }
        }