示例#1
0
        /// <summary>
        /// Passed reference to the created service provider to be asserted.
        /// The assert method can create instances of servers to assert their state.
        /// </summary>
        /// <param name="assert">The assert method.</param>
        /// <returns>Self Reference.</returns>
        public ContainerAssert Services(Action <IServiceProvider> assert)
        {
            if (assert == null)
            {
                throw new ArgumentNullException(nameof(assert));
            }

            _fixture.AssureCompositeAppStarted();

            _testServiceScope = _testServiceScope ?? _fixture.AppUnderTest.CreateServiceScope().ServiceProvider;

            assert(_testServiceScope);
            return(this);
        }
示例#2
0
        /// <summary>
        /// Allows an unit-test to act on the server-provider associated with the
        /// composite-application.
        /// </summary>
        /// <param name="act">Method called to act on the service provider.</param>
        /// <returns>Self Reference.</returns>
        public async Task <ContainerAct> OnServices(Func <IServiceProvider, Task> act)
        {
            if (_actedOn)
            {
                throw new InvalidOperationException("The container can only be acted on once.");
            }

            _fixture.AssureCompositeAppStarted();

            _actedOn = true;
            try
            {
                var testScope = _fixture.AppUnderTest.CreateServiceScope();
                _testServiceScope = testScope.ServiceProvider;

                await act(_testServiceScope).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _resultingException = ex;
            }

            return(this);
        }