protected static void BeginInit(string dbName) { try { if (TransactionFactory == null) { var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); log4net.Config.XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); LogManager.GetLogger(TestClass).Info("Starting in-memory database for unit tests"); TransactionFactory = new DefaultTransactionFactory( () => new SQLiteConnection( "Data Source=:memory:;Version=3;New=True;Pooling=True;Max Pool Size=1;foreign_keys = ON"), DefaultTransactionFactory.DbSqllite); } var transaction = TransactionFactory.CreateTransaction(); Assert.IsNotNull(transaction); Connection = transaction.Connection; Assert.IsNotNull(Connection); } catch (System.Exception ex) { LogManager.GetLogger(TestClass).Fatal(string.Format("Exception during database {0} startup.", dbName), ex); } }
public static ITransaction ToTransaction(ITransactionFactory transactionFactory, IQuickTransaction quickTransaction) { var result = transactionFactory.CreateTransaction(quickTransaction.Account, quickTransaction.Category, quickTransaction.Name, quickTransaction.Total, DateTime.Now, 0, quickTransaction.Weight, null, null); return(result); }
public ITransaction CreateTransaction(IAccount account, ICategory category, string name, decimal total, DateTime timestamp, long id, decimal weight, IProduct product, ITransaction parentTransaction) { var transaction = TransactionFactory.CreateTransaction(account, category, name, total, timestamp, id, weight, product, parentTransaction); return(CreateTransaction(transaction)); }
private ITransaction CreateTransaction(IAccountStorage accountManager, ICategoryStorage categoryManager, ITransactionFactory factory) { var transactionName = "Test Transaction"; var transactionTotal = 213.00m; var account = accountManager.CreateAccount("Test account", "Account Description", "EUR"); var category = categoryManager.CreateCategory("Sample category", "Category Description", 0, null); var result = factory.CreateTransaction(account, category, transactionName, transactionTotal, DateTime.Now, 0, 0.12m, null, null); return(result); }
private async Task Invoke(RequestMessage message, CancellationToken cancellationToken) { using var trace = tracing.StartTrace(message.RequestDetails.TraceHeader); tracing.AddAnnotation("event", "rest-call"); using var transaction = transactionFactory.CreateTransaction(); using var logScope = logger.BeginScope("{@requestId}", message.RequestDetails.Id); using var serviceScope = scopeFactory.CreateScope(); var invoker = serviceScope.GetService <IRequestInvoker>(); await invoker.Invoke(message, cancellationToken); transaction.Complete(); }
public IEnumerable <ITransaction> CreateTransactionsFromFile(string filePath, SupportedTransactionTypes transactionsType) { var stringTransactions = LoadTransactionsFromFile(filePath); ICollection <ITransaction> transactions = new List <ITransaction>(); stringTransactions.ForEach(x => { var transaction = _transactionsFactory.CreateTransaction(x, transactionsType); if (transaction != NoneTransaction.Instance) { transactions.Add(transaction); } }); return(transactions); }
public async Task ShouldInvokeAllReceivedMessagesThenCompleteTransactions( RequestMessage message1, RequestMessage message2, IScope scope1, IScope scope2, IRequestInvoker invoker1, IRequestInvoker invoker2, ITransaction transaction1, ITransaction transaction2, [Frozen] ITransactionFactory transactionFactory, [Frozen] IRequestMessageRelay relay, [Frozen] IScopeFactory scopeFactory, [Target] DefaultRequestWorker worker, CancellationToken cancellationToken ) { transactionFactory.CreateTransaction().Returns(transaction1, transaction2); scope1.GetService <IRequestInvoker>().Returns(invoker1); scope2.GetService <IRequestInvoker>().Returns(invoker2); scopeFactory.CreateScope().Returns(scope1, scope2); relay.Receive(Any <CancellationToken>()).Returns(new[] { message1, message2 }); await worker.Run(cancellationToken); Received.InOrder(async() => { transactionFactory.Received().CreateTransaction(); scopeFactory.Received().CreateScope(); scope1.Received().GetService <IRequestInvoker>(); await invoker1.Received().Invoke(Is(message1), Is(cancellationToken)); transaction1.Received().Complete(); transactionFactory.Received().CreateTransaction(); scopeFactory.Received().CreateScope(); scope2.Received().GetService <IRequestInvoker>(); await invoker2.Received().Invoke(Is(message2), Is(cancellationToken)); transaction2.Received().Complete(); }); }
public static ITransaction Convert(IDictionary <string, object> line, ITransactionFactory transactionFactory, IAccountStorage accountStorage, ICategoryStorage categoryStorage) { var id = (long)line["id"]; var timestamp = DateTime.Parse(line["timestamp"].ToString()); var accountId = (long)(line["accountId"]); var categoryId = (long)(line["categoryId"]); var name = line["name"].ToString(); var total = decimal.Parse(line["total"].ToString()); var account = accountStorage.GetAllAccounts().FirstOrDefault(x => x?.Id == accountId); var category = categoryStorage.GetAllCategories().FirstOrDefault(x => x?.Id == categoryId); var weight = decimal.Parse(line["weight"].ToString()); //var productId = (line["productId"] is System.DBNull)? 0: (long)line["productId"];//Add Product Storage //var parentId = (line["parentId"] is System.DBNull) ? 0 : (long)line["parentId"]; //var isComplexTransaction = (long) line["isComplexTransaction"] > 0; var transaction = (Transaction)transactionFactory.CreateTransaction(account, category, name, total, timestamp, id, weight, null, null); transaction.Id = id; transaction.Timestamp = timestamp; return(transaction); }
private static ITransaction SetupDb() { try { if (_transactionFactory == null) { var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); log4net.Config.XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); LogManager.GetLogger(typeof(DbUtilsTests)).Info("Starting in-memory database for unit tests"); _transactionFactory = new DefaultTransactionFactory( () => new SQLiteConnection( "Data Source=:memory:;Version=3;New=True;Pooling=True;Max Pool Size=1;foreign_keys = ON"), DefaultTransactionFactory.DbSqllite); } return(_transactionFactory.CreateTransaction()); } catch (System.Exception ex) { LoggerManager.GetLogger(Assembly.GetExecutingAssembly(), typeof(DbUtilsTests)).Log(typeof(DbUtilsTests), Level.Fatal, "Exception during database startup.", ex); return(null); } }
public void Intercept(IInvocation invocation) { if (!_intercepted) { _intercepted = true; bool newTransaction = false; try { if (_transaction.Closed) { _transaction = _transactionFactory.CreateTransaction(); newTransaction = true; } _dataRetrievalOperationLayer.LoadChildrenFromRelation(_parentRoEntity, _applicableParentType, _transaction, _relation, true); } finally { if (newTransaction) { DbMgtUtility.Close(_transaction); _transaction = null; } } EntityInfo entityInfo = CacheManager.GetEntityInfo(_parentRoEntity); PropertyInfo property = entityInfo.GetProperty(_relation.AttributeName); Object objectToInvoke = property.GetValue(_parentRoEntity, new object[] {}); invocation.ReturnValue = invocation.Method.Invoke(objectToInvoke, new object[] {}); } else { invocation.Proceed(); } }