Example #1
0
        public async Task ItSoftDeletesRecords()
        {
            var original = new Recipe(name: nameof(ItSoftDeletesRecords));
            await AppFixture.InsertAsync(original);

            await AppFixture.ExecuteDbContextAsync(async db =>
            {
                var saved = await db.Recipes.FindAsync(original.Id);
                saved.Should().NotBeNull("we just saved it");

                saved.SoftDelete();
                // db.Remove(saved);
            });

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

            deleted.Should().BeNull("Recipe {0} was soft-deleted", original.Key);
        }
        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));
        }
Example #4
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");
        }