Example #1
0
        private void InitContext()
        {
            var rand = new Random();

            CocktailsContext = new CocktailsContext(CreateContextOptions());

            var flavors = Enumerable.Range(1, 100)
                          .Select(i => new Flavor
            {
                Id           = Guid.NewGuid(),
                Name         = $"Flavor{i}",
                ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next())
            });

            var categories = Enumerable.Range(1, 100)
                             .Select(i => new Category
            {
                Id           = Guid.NewGuid(),
                Name         = $"Category{i}",
                ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next())
            });

            CocktailsContext.Flavors.AddRange(flavors);
            CocktailsContext.Categories.AddRange(categories);

            CocktailsContext.SaveChanges();

            var ingredients = Enumerable.Range(1, 100)
                              .Select(i => new Ingredient
            {
                Id           = Guid.NewGuid(),
                Name         = $"Ingredient{i}",
                FlavorId     = CocktailsContext.Flavors.ToArray()[i - 1].Id,
                CategoryId   = CocktailsContext.Categories.ToArray()[i - 1].Id,
                ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next())
            });

            CocktailsContext.Ingredients.AddRange(ingredients);

            CocktailsContext.SaveChanges();

            var cocktails = Enumerable.Range(1, 100)
                            .Select(i => new Cocktail
            {
                Id           = Guid.NewGuid(),
                Name         = $"Cocktail{i}",
                ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next())
            });

            CocktailsContext.Cocktails.AddRange(cocktails);

            CocktailsContext.SaveChanges();
        }
Example #2
0
        public RecipeImporterTests()
        {
            var builder = new DbContextOptionsBuilder <CocktailsContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            _db  = new CocktailsContext(builder.Options);
            _sut = new RecipeImporter(_db);

            _db.Library.Add(new Library
            {
                Id   = LibraryId,
                Name = LibraryName
            });
            _db.SaveChanges();
        }
Example #3
0
        public async Task GetFlavorWithCorrectId()
        {
            var id     = Guid.NewGuid();
            var flavor = new Flavor {
                Id = id, Name = "flavor"
            };

            CocktailsContext.Add(flavor);
            CocktailsContext.SaveChanges();

            var result = await _repository.GetSingleAsync(x => x.Where(y => y.Id == id), _token);

            Assert.IsNotNull(result);
            Assert.AreEqual(flavor.Id, result.Id);
            Assert.AreEqual(flavor.Name, result.Name);
        }
        public void GetCocktailsByNameTest()
        {
            const string nameKeyword = "Name ";

            var item1 = CocktailsContext.Cocktails.ToArray()[0];
            var item2 = CocktailsContext.Cocktails.ToArray()[1];

            item1.Name = nameKeyword + 1;
            item2.Name = nameKeyword + 2;

            CocktailsContext.SaveChanges();

            var result = QueryFunctions.CocktailsByNameFunction(CocktailsContext.Cocktails, nameKeyword).ToArray();

            Assert.AreEqual(2, result.Length);
            Assert.Contains(item1, result);
            Assert.Contains(item2, result);
        }