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); }
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); }
public TranslateCommands(SearchesService searches, IGoogleApiService google) { _searches = searches; _google = google; }
public async Task GetProductsBySearchTextAsyncShouldReturnNullIfNoSuchProducts() { 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 user = new ApplicationUser { FirstName = UserFirstName, LastName = UserLastName, }; await dbContext.Users.AddAsync(user); await dbContext.SaveChangesAsync(); var category = new ProductCategory { Name = CategoryName, }; await dbContext.ProductCategories.AddAsync(category); await dbContext.SaveChangesAsync(); for (int i = 0; i < 3; i++) { var product = new Product { Name = ProductName, Description = ProductDescription, Price = ProductPrice, CategoryId = category.Id, }; product.Images.Add(new Image { Url = ImageUrl, }); product.Comments.Add(new Comment { Text = CommentText, ProductId = product.Id, AuthorId = user.Id, }); await dbContext.Products.AddAsync(product); await dbContext.SaveChangesAsync(); } var searchModel = new SearchViewModel { Text = SearchText, }; var expected = await searchesService.GetProductsBySearchTextAsync(searchModel); Assert.Null(expected); }