Taijutsu.Data.Internal.DataContext.Complete C# (CSharp) Method

Complete() public method

public Complete ( ) : void
return void
        public virtual void Complete()
        {
            AssertNotDisposed();

            if (completed.HasValue)
            {
                if (!completed.Value)
                {
                    throw new Exception(string.Format("Data context has already been completed without success."));
                }

                return;
            }

            try
            {
                if (subordinatesCount != 0)
                {
                    throw new Exception("Unit of work can not be successfully completed, because not all subordinates are completed.");
                }

                if (BeforeCompleted != null)
                {
                    try
                    {
                        BeforeCompleted(this, new FinishedEventArgs(true));
                    }
                    finally
                    {
                        BeforeCompleted = null;
                    }
                }

                if (session.IsValueCreated)
                {
                    session.Value.Complete();
                }

                completed = true;
            }
            catch
            {
                completed = false;
                throw;
            }

            if (AfterCompleted != null)
            {
                try
                {
                    AfterCompleted(this, new FinishedEventArgs(true));
                }
                finally
                {
                    AfterCompleted = null;
                }
            }
        }

Usage Example

        public virtual void ShouldCallRealCompleteOnlyOnce()
        {
            var config = new UnitOfWorkConfig(string.Empty, IsolationLevel.ReadCommitted, Require.New);
            var sessionBuilder = new Lazy<IDataSession>(() => session, false);
            var policy = new ImmediateTerminationPolicy();

            using (var context = new DataContext(config, sessionBuilder, policy))
            {
                Awaken(context);
                context.Complete();
                context.Complete();
            }

            session.Received(1).Complete();
        }
All Usage Examples Of Taijutsu.Data.Internal.DataContext::Complete