public async Task ItRemovesTheIngredient()
        {
            var original = new Recipe(name: nameof(ItRemovesTheIngredient));

            var toDelete = original.AddIngredient(new Ingredient(Guid.NewGuid().ToString()),
                                                  UnitOfMeasure.Cup, 2M);

            original.AddIngredient(new Ingredient(Guid.NewGuid().ToString()), UnitOfMeasure.Pint, 5M);

            await AppFixture.InsertAsync(original);

            var request = new RemoveIngredientRequest
            {
                RecipeModelKey           = new ModelUpdateIdentifier(original),
                RecipeIngredientModelKey = new ModelUpdateIdentifier(toDelete)
            };

            await AppFixture.SendAsync(request);

            var saved = await AppFixture.ExecuteDbContextAsync(async db =>
            {
                return(await db.Recipes.Where(x => x.Id == original.Id).Include(x => x.RecipeIngredients)
                       .FirstOrDefaultAsync());
            });

            saved.RecipeIngredients.Should().HaveCount(1);
            saved.RecipeIngredients[0].UnitOfMeasure.Should().Be(UnitOfMeasure.Pint);
        }
예제 #2
0
 public ConfirmedOrdersHubTests()
 {
     _fixture          = new AppFixture();
     _toGoOrdersHelper = new ToGoOrderTestsHelper(_fixture);
     _authTestsHelper  = new AuthTestsHelper(_fixture);
     _hubUrl           = _fixture.GetCompleteServerUrl("/confirmedOrders");
 }
        public async Task ItAddsAnIngredient()
        {
            var ingredientName = Guid.NewGuid().ToString();

            var recipe = new Recipe(name: nameof(ItAddsAnIngredient));
            await AppFixture.InsertAsync(recipe);

            var result = await AppFixture.SendAsync(new AddIngredientRequest
            {
                RecipeKey     = new ModelUpdateIdentifier(recipe),
                Name          = ingredientName,
                Quantity      = 42M,
                UnitOfMeasure = UnitOfMeasure.Pint
            });

            var saved = await AppFixture.ExecuteDbContextAsync(db => db.RecipeIngredients
                                                               .Include(ri => ri.Ingredient)
                                                               .Include(ri => ri.Recipe)
                                                               .Where(ri => ri.Key == result.Key)
                                                               .FirstOrDefaultAsync());

            saved.Ingredient.Name.Should().Be(ingredientName);
            saved.Recipe.Key.Should().Be(recipe.Key);
            saved.UnitOfMeasure.Should().Be(UnitOfMeasure.Pint);
            saved.Quantity.Should().Be(42M);
        }
예제 #4
0
        public async Task ItMapsItAsStringToString()
        {
            var result = await AppFixture.SendAsync(new GetUnitsOfMeasureRequest());

            foreach (var refData in result)
            {
                var isMemberOfEnum = UnitOfMeasure.TryFromName(refData.Code, out _);
                isMemberOfEnum.Should()
                .BeTrue(because: $"'{refData.Code}' should be a member of the UnitOfMeasure enum");
            }
        }
예제 #5
0
 public ServerFixture(
     TimeoutFixture timeout,
     ServicesFixture services,
     AppFixture app,
     EndPointFixture endPoint)
 {
     _timeout  = timeout;
     _services = services;
     _app      = app;
     _endPoint = endPoint;
 }
        public async Task ItDeletesRecipeAndIngredients()
        {
            var recipe     = new Recipe(name: nameof(ItDeletesRecipeAndIngredients));
            var ingredient = new Ingredient(Guid.NewGuid().ToString());

            recipe.AddIngredient(ingredient, UnitOfMeasure.Cup, 10M);
            await AppFixture.InsertAsync(recipe);

            await AppFixture.SendAsync(new RemoveRecipeRequest()
            {
                RecipeKey = new ModelUpdateIdentifier(recipe)
            });

            var deleted = await AppFixture.ExecuteDbContextAsync(db => db.GetRecipe(recipe.Key));

            deleted.Should().BeNull(because: "it was soft-deleted");

            var deletedIngredient = await AppFixture.FindAsync <RecipeIngredient>(ingredient.Key);

            deletedIngredient.Should().BeNull(because: "it was soft-deleted");
        }
        public async Task ARecipeIsCreated()
        {
            var cmd = new CreateRecipeCommand
            {
                Name        = "Chocolate Cake",
                Description = "Best birthday cake",
                PrepTime    = Duration.FromMinutes(15),
                CookTime    = Duration.FromHours(1)
            };

            var result = await AppFixture.SendAsync(cmd);

            result.Key.Should().NotBe(Guid.Empty);
            result.Version.Should().Be(1);

            var saved = await AppFixture.FindAsync <Recipe>(result.Key);

            saved.Name.Should().Be("Chocolate Cake");
            saved.Description.Should().Be("Best birthday cake");
            saved.CookTime.Should().Be(Duration.FromMinutes(60));
        }
예제 #8
0
        public async Task ItBumpsTheVersionAndEditTime()
        {
            var original = new Recipe(name: nameof(ItBumpsTheVersionAndEditTime));

            await AppFixture.InsertAsync(original);

            await AppFixture.ExecuteDbContextAsync(async db =>
            {
                var saved  = await db.Recipes.FirstOrDefaultAsync(x => x.Key == original.Key);
                saved.Name = "Milk";
            });

            var updated = await AppFixture.FindAsync <Recipe>(original.Key);

            updated.Name.Should().Be("Milk");
            updated.Version.Should().Be(2);

            updated.UpdatedAt.ToUnixTimeMilliseconds().Should()
            .BeGreaterThan(original.UpdatedAt.ToUnixTimeMilliseconds(),
                           because: "updated timestamps should be bumped on change");
            updated.CreatedAt.Should().Be(original.CreatedAt, because: "created timestamps are never changed");
        }