public void Dispose()
        {
            //Force the created transaction to finish if necessary so that it won't be garbage collected and harvested
            //by another test.
            var transaction = _primaryTransactionContextStorage.GetData();

            transaction?.Finish();

            _container.Dispose();
        }
        private IInternalTransaction TryGetInternalTransaction(IContextStorage <IInternalTransaction> transactionContext)
        {
            try
            {
                if (transactionContext == null)
                {
                    return(null);
                }

                return(transactionContext.GetData());
            }
            catch (Exception exception)
            {
                Log.Error($"ITransactionContext threw an exception when calling GetData with {TransactionContextKey}: {exception}");
                return(null);
            }
        }
        public bool SetTransactionOnAsyncContext(IInternalTransaction transaction)
        {
            if (_asyncContext == null)
            {
                return(false);
            }

            if (_asyncContext.GetData() == null)
            {
                _asyncContext.SetData(transaction);
                if (Log.IsFinestEnabled)
                {
                    transaction.LogFinest($"Attached to {_asyncContext}");
                }
            }

            return(true);
        }
示例#4
0
        private static void DictionaryTransactionContext(IContextStorage <IInternalTransaction> transactionContext)
        {
            const string key        = "TEST";
            var          dictionary = new Dictionary <string, object>();

            Mock.Arrange(() => transactionContext.CanProvide).Returns(true);
            Mock.Arrange(() => transactionContext.SetData((IInternalTransaction)Arg.AnyObject)).DoInstead((object value) =>
            {
                dictionary[key] = value;
            });
            Mock.Arrange(() => transactionContext.GetData()).Returns(() =>
            {
                if (!dictionary.ContainsKey(key))
                {
                    return(null);
                }

                object value;
                dictionary.TryGetValue(key, out value);
                return(value as IInternalTransaction);
            });
        }
示例#5
0
 private static void ThrowingTransactionContext(IContextStorage <IInternalTransaction> transactionContext)
 {
     Mock.Arrange(() => transactionContext.CanProvide).Returns(true);
     Mock.Arrange(() => transactionContext.SetData((IInternalTransaction)Arg.AnyObject)).Throws <Exception>();
     Mock.Arrange(() => transactionContext.GetData()).Throws <Exception>();
 }
 /// <summary>
 /// Gets a generic type from the context.
 /// </summary>
 /// <typeparam name="T">the type of instance to return.</typeparam>
 /// <returns>The instance if stored in the context.</returns>
 public static T Get <T>()
 {
     return(_contextStorage.GetData <T>(typeof(T).FullName));
 }