예제 #1
0
 private void RunResultAssertions(object result)
 {
     using (var aggregator = new ExceptionAggregator())
     {
         foreach (var action in _resultAssertions)
         {
             aggregator.Try(() => action(result));
         }
     }
 }
예제 #2
0
 private void RunExceptionAssertions(Exception e)
 {
     using (var aggregator = new ExceptionAggregator())
     {
         foreach (var action in _exceptionAssertions)
         {
             aggregator.Try(() => action(e));
         }
     }
 }
        /// <summary>
        /// Adds an assertion to check that an entity of the specified type exists in the database, also running the specified assertions against it.
        /// </summary>
        /// <typeparam name="TDbContext">The type of the database context.</typeparam>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="fixture">The fixture.</param>
        /// <param name="id">The identifier.</param>
        /// <param name="assertions">The assertions.</param>
        /// <returns></returns>
        public static IMvcFunctionalTestFixture ShouldExistInDatabase <TDbContext, TEntity>(this IMvcFunctionalTestFixture fixture,
                                                                                            object id,
                                                                                            params Action <TEntity>[] assertions)
            where TDbContext : DbContext
            where TEntity : class =>
        fixture.PostRequestResolvedServiceShould <TDbContext>(async ctx =>
        {
            var existing = await ctx.Set <TEntity>().FindAsync(id);
            existing.Should().NotBeNull();

            using (var aggregator = new ExceptionAggregator())
            {
                foreach (var assertion in assertions)
                {
                    aggregator.Try(() => assertion(existing));
                }
            }
        });