コード例 #1
0
 /// <summary>
 /// Sets up the context with the appropriate dependencies.
 /// </summary>
 /// <param name="repository">The repository for the domain.</param>
 /// <param name="domainFactory">The domain instance factory for the domain.</param>
 /// <param name="queryFactory">The query factory for the domain.</param>
 public static void Setup(IRepository repository,
                          IDomainFactory domainFactory,
                          IQueryFactory queryFactory)
 {
     _contextStorage.SetData(StorageKeyRepository, repository);
     _contextStorage.SetData(StorageKeyDomainFactory, domainFactory);
     _contextStorage.SetData(StorageKeyQueryFactory, queryFactory);
 }
コード例 #2
0
        /// <summary>
        /// Sets up the context with the appropriate dependencies.
        /// </summary>
        /// <param name="contextStorage">The context storage for the dependencies.</param>
        /// <param name="logger">The logger for the system.</param>
        /// <param name="networkContext">The network context to be used through the application.</param>
        public static void Setup(IContextStorage contextStorage, ILogger logger, INetworkContext networkContext)
        {
            _contextStorage = contextStorage;

            _contextStorage.SetData(StorageKeyLogger, logger);
            _contextStorage.SetData(StorageKeyNetworkContext, networkContext);
            Keys.Clear();
            Keys.Add(StorageKeyLogger);
            Keys.Add(StorageKeyNetworkContext);
        }
コード例 #3
0
        /// <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 void Set <T>(T instance)
        {
            var key = typeof(T).FullName;

            Keys.Add(key);
            _contextStorage.SetData(key, instance);
        }
コード例 #4
0
        public override bool AttachToAsync()
        {
            var currentValue = _currentContextStorage.GetData();

            _currentContextStorage = _asyncContextStorage;
            _currentContextStorage.SetData(currentValue);
            return(true);
        }
コード例 #5
0
        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);
        }
コード例 #6
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);
            });
        }
コード例 #7
0
 /// <summary>
 /// Sets up the context with the appropriate dependencies.
 /// </summary>
 /// <param name="repository">The repository for the tests.</param>
 /// <param name="createNewRepo">Function that will create a new repository.</param>
 public static void Setup(IAsyncRepository repository, Func <IAsyncRepository> createNewRepo)
 {
     ContextStorage.SetData(StorageKeyRepository, repository);
     _createNewRepo = createNewRepo;
 }
コード例 #8
0
 /// <summary>
 /// This method can be used for arranging tests to force a transaction to exist in the composite test agent's primary transaction context storage.
 /// </summary>
 /// <param name="transaction"></param>
 public void SetTransactionOnPrimaryContextStorage(ITransaction transaction)
 {
     _primaryTransactionContextStorage.SetData(transaction as IInternalTransaction);
 }
コード例 #9
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>();
 }