Пример #1
0
        public async Task GetProgramsBySearchTextAsyncShouldReturnNullIfTextIsLessThanFourSymbols()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var searchesService = new SearchesService(dbContext, mapper);

            var searchModel = new SearchViewModel
            {
                Text = InvalidSearchText,
            };

            var expected = await searchesService.GetProgramsBySearchTextAsync(searchModel);

            Assert.Null(expected);
        }
Пример #2
0
        public async Task GetProgramsBySearchTextAsyncShouldReturnNullIfNoSuchPrograms()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var searchesService = new SearchesService(dbContext, mapper);

            var category = new ProgramCategory
            {
                Name        = CategoryName,
                Description = CategoryDescription,
            };

            await dbContext.ProgramCategories.AddAsync(category);

            await dbContext.SaveChangesAsync();

            for (int i = 0; i < 3; i++)
            {
                var program = new Program
                {
                    Title       = ProgramTitle,
                    Description = ProgramDescription,
                    CategoryId  = category.Id,
                };

                program.Images.Add(new Image
                {
                    Url = ImageUrl,
                });

                await dbContext.Programs.AddAsync(program);

                await dbContext.SaveChangesAsync();
            }

            var searchModel = new SearchViewModel
            {
                Text = SearchText,
            };

            var expected = await searchesService.GetProgramsBySearchTextAsync(searchModel);

            Assert.Null(expected);
        }