public static IEnumerable <IEnumerable <dynamic> > ToResultSets(
     this SimpleTransaction db,
     string sql,
     IDictionary <string, object> parameters)
 {
     return(db.GetAdoAdapter().ToResultSets(sql, parameters));
 }
Example #2
0
        void transaction_OnTransactionCompleted(BotEngine sender, EventTransactionCompletedArgs e)
        {
            ConsoleHelpers.WriteLine(string.Format("Transaction {0} committed {1} objects, and completed in {2} ms.",
                                                   e.Transaction.TransactionId, e.Transaction.Commits, e.Transaction.elapsedMs));

            foreach (var model in sender.SceneNodes.Models.FindAll(p => p.Action.Contains("@key=unittest")))
            {
                sender.DeleteObject(model);
            }

            // create a second transaction
            var transaction = new SimpleTransaction <Model>(sender);

            transaction.OnTransactionCompleted += transaction_OnTransactionCompleted2;
            for (int h = 0; h < 1; h++)
            {
                for (int j = 0; j < 15; j++)
                {
                    for (int i = 0; i < 15; i++)
                    {
                        transaction.Add(new Model()
                        {
                            ModelName   = "bzmb0.rwx",
                            Action      = "@key=unittest",
                            Description = "Bot created object teet",
                            Position    = new Vector3((i * 120) + (-h * 1600), j * 120, 2000)
                        });
                    }
                }
            }
            sender.AddObjects(transaction);
        }
        public void CalculateTotalTransaction_AmountProvided_ReturnsSameAmount()
        {
            const int baseAmount        = 100;
            var       simpleTransaction = new SimpleTransaction(baseAmount);

            var totalTransaction = simpleTransaction.CalculateTotalTransaction();

            Assert.That(totalTransaction, Is.EqualTo(baseAmount), "Calculated transaction should equal the base amount");
        }
        public void CalculateTotalTransaction_AmountProvided_ReturnsSameAmount()
        {
            const int baseAmount = 100;
            var simpleTransaction = new SimpleTransaction(baseAmount);

            var totalTransaction = simpleTransaction.CalculateTotalTransaction();

            Assert.That(totalTransaction, Is.EqualTo(baseAmount),
                "Calculated transaction should be equal to the base amount.");
        }
Example #5
0
        public void AssignFields()
        {
            BasicMessageFormatter formatter = new BasicMessageFormatter();
            Message message = new Message();

            // Add field Formatters.
            for (int i = 0; i < _fixedMessageFormatter.Length; i++)
            {
                if (_fixedMessageFormatter[i] != null)
                {
                    formatter.FieldFormatters.Add(_fixedMessageFormatter[i]);
                }
            }

            // Replace field formatter for field number 6, to perform
            // a complete AssignFields test.
            formatter.FieldFormatters.Add(new BinaryFieldFormatter(6,
                                                                   new FixedLengthManager(20), BinaryEncoder.GetInstance()));

            // Perform test for invalid parameters.
            try {
                formatter.AssignFields(null, null);
                Assert.Fail();
            } catch (ArgumentNullException e) {
                Assert.IsTrue(e.ParamName == "message");
            }

            try {
                formatter.AssignFields(message, null);
                Assert.Fail();
            } catch (ArgumentNullException e) {
                Assert.IsTrue(e.ParamName == "fieldsContainer");
            }

            // Perform a simple test.
            SimpleTransaction simpleTransaction = new SimpleTransaction();

            simpleTransaction.Terminal       = 106;
            simpleTransaction.CustomerName   = "John Doe";
            simpleTransaction.AdditionalData = "Some data";
            formatter.AssignFields(message, simpleTransaction);

            Assert.IsFalse(simpleTransaction.InvalidPropertyHasBeenTaken);
            Assert.IsFalse(message.Fields.Contains(1));
            Assert.IsFalse(message.Fields.Contains(2));
            Assert.IsTrue(message.Fields.Contains(5));
            Assert.IsTrue(simpleTransaction.Terminal.ToString().Equals(
                              message[5].ToString()));
            Assert.IsTrue(message.Fields.Contains(6));
            Assert.IsTrue(simpleTransaction.CustomerName.Equals(
                              message[6].ToString()));
            Assert.IsTrue(message.Fields.Contains(30));
            Assert.IsTrue(simpleTransaction.AdditionalData.Equals(
                              message[30].ToString()));
        }
        private static AdoAdapter GetAdoAdapter(this SimpleTransaction db)
        {
            var adapter    = db.GetAdapter();
            var adoAdapter = adapter as AdoAdapter;

            if (adoAdapter == null)
            {
                throw new NotSupportedException("Only Simple.Data.Ado adapters are supported by Simple.Data.RawSql");
            }
            return(adoAdapter);
        }
Example #7
0
        public void ProcessTransaction_TransactionValueGiven_TellerSubmitsGivenTransactionToTheRepository()
        {
            //Arrange
            var sut         = TellerFactory();
            var transaction = new SimpleTransaction(10);

            //Act
            sut.ProcessTransaction(transaction);
            Mock.Get(_accountRepository).Verify(x => x.ProcessTransaction(transaction), Times.Once(),
                                                "The teller should forward the process transaction request to the repository.");
        }
Example #8
0
        public void CalculateTotalTransaction_AmountProvided_ReturnsSameAmount()
        {
            //Arrange
            const int baseAmount = 100;
            var       sut        = new SimpleTransaction(baseAmount);

            //Act
            var totalTransaction = sut.CalculateTotalTransaction();

            //Assert
            totalTransaction.Should().Be(baseAmount);
        }
        public void ProcessTransaction_FirstTransaction_StoredTransactionsContainOnlyThatOne()
        {
            var transaction = new SimpleTransaction(10);

            _accountRepository.ProcessTransaction(transaction);

            var transactions = _accountRepository.GetTransactions();

            Assert.That(transactions.Count, Is.EqualTo(1),
                "First transaction should be stored in the transaction list.");
            Assert.That(transactions.Single(), Is.EqualTo(transaction),
            "First transaction should return the same balance.");
        }
Example #10
0
        public void ProcessTransaction_TransactionValueGiven_TellerSubmitsGivenTransactionToTheRepository()
        {
            var transaction = new SimpleTransaction(10);
            var processTransactionTrigger = new ManualResetEvent(false);
            Mock.Get(_accountRepository).Setup(x => x.ProcessTransaction(transaction))
                .Callback(() => processTransactionTrigger.Set());

            _teller.ProcessTransaction(transaction);

            processTransactionTrigger.WaitOne(TimeSpan.FromSeconds(1));
             Mock.Get(_accountRepository).Verify(x => x.ProcessTransaction(transaction), Times.Once(),
                 "The Teller should forward the process transaction request to the repository.");
        }
        public void ProcessTansaction_FirstTransaction_ReturnsCurrentBalanceSameAsTransaction()
        {
            var transaction = new SimpleTransaction(10);

            _accountRepository.ProcessTransactions(transaction);

            var transactions = _accountRepository.GetTransactions();

            Assert.That(transactions.Count(), Is.EqualTo(1),
                        "First transaction should be stored in the transaction list.");
            Assert.That(transactions.Single(), Is.EqualTo(transaction),
                        "First transaction should be the only item stored.");
        }
Example #12
0
        public void RetrieveFields()
        {
            BasicMessageFormatter formatter = new BasicMessageFormatter();
            Message message = new Message();

            // Add field Formatters.
            for (int i = 0; i < _fixedMessageFormatter.Length; i++)
            {
                if (_fixedMessageFormatter[i] != null)
                {
                    formatter.FieldFormatters.Add(_fixedMessageFormatter[i]);
                }
            }

            // Replace field formatter for field number 6, to perform
            // a complete AssignFields test.
            formatter.FieldFormatters.Add(new BinaryFieldFormatter(6,
                                                                   new FixedLengthManager(20), BinaryEncoder.GetInstance()));

            // Perform test for invalid parameters.
            try {
                formatter.RetrieveFields(null, null);
                Assert.Fail();
            } catch (ArgumentNullException e) {
                Assert.IsTrue(e.ParamName == "message");
            }

            try {
                formatter.RetrieveFields(message, null);
                Assert.Fail();
            } catch (ArgumentNullException e) {
                Assert.IsTrue(e.ParamName == "fieldsContainer");
            }

            // Perform a simple test.
            message.Fields.Add(1, "01");
            message.Fields.Add(2, "02");
            message.Fields.Add(5, "1385");
            message.Fields.Add(6, "John Doe");
            message.Fields.Add(30, "Random data");
            SimpleTransaction simpleTransaction = new SimpleTransaction();

            formatter.RetrieveFields(message, simpleTransaction);

            Assert.IsFalse(simpleTransaction.InvalidPropertyHasBeenAssigned);
            Assert.IsNotNull(simpleTransaction.RetrieveBranch());
            Assert.IsTrue(simpleTransaction.RetrieveBranch().Equals("01"));
            Assert.IsTrue(simpleTransaction.Terminal == 1385);
            Assert.IsTrue(simpleTransaction.AdditionalData.Equals("Random data"));
        }
Example #13
0
        public void ProcessTansaction_TransactionValuesGiven_TellerSubmitsGivenTransactionToTheRepository()
        {
            var transaction = new SimpleTransaction(10);
            var processTransactionTrigger = new ManualResetEvent(false);

            Mock.Get(_accountRepository).Setup(x => x.ProcessTransactions(transaction))
            .Callback(() => processTransactionTrigger.Set());

            _teller.ProcessTransaction(transaction);

            processTransactionTrigger.WaitOne(TimeSpan.FromSeconds(1));
            Mock.Get(_accountRepository).Verify(x => x.ProcessTransactions(transaction), Times.Once(),
                                                "The teller should forward the process transaction request to the repository.");
        }
 public static object ToScalar(this SimpleTransaction db, string sql, object parameters)
 {
     return(db.GetAdoAdapter().ToScalar(sql, parameters.ObjectToDictionary()));
 }
Example #15
0
        /// <summary>
        /// Handles the object event scan completed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="AwManaged.EventHandling.BotEngine.EventObjectScanCompletedEventArgs"/> instance containing the event data.</param>
        void HandleObjectEventScanCompleted(BotEngine sender, EventObjectScanCompletedEventArgs e)
        {
            _sw1.Stop();
            ConsoleHelpers.WriteLine(string.Format("Found {0} objects in {1} ms.", e.SceneNodes.Models.Count, _sw1.ElapsedMilliseconds));
            _sw1.Reset();
            // start receiving object events.
            sender.ObjectEventAdd    += HandleObjectEventAdd;
            sender.ObjectEventRemove += HandleObjectEventRemove;
            sender.ObjectEventClick  += HandleObjectEventClick;
            sender.ObjectEventChange += HandleObjectEventChange;
            // check how many zone's there are in the world
            ConsoleHelpers.WriteLine(string.Format("Found {0} zones.", e.SceneNodes.Zones.Count));
            ConsoleHelpers.WriteLine(string.Format("Found {0} cameras.", e.SceneNodes.Cameras.Count));
            ConsoleHelpers.WriteLine(string.Format("Found {0} movers.", e.SceneNodes.Movers.Count));
            ConsoleHelpers.WriteLine(string.Format("Found {0} particle emitters.", e.SceneNodes.Particles.Count));
            //string actionContains = "light";
            //ConsoleHelpers.WriteLine(string.Format("object query test, testing object actions which contain {0}",actionContains));
            //var b = from Model p in e.SceneNodes.Models where p.Action.Contains(actionContains) select p;
            //ConsoleHelpers.WriteLine(string.Format("found {0} objects which contain action {1}",b.Count(), actionContains));

            //sender.AddObject(new Model(){ModelName="bzmb0.rwx",Position=new Vector3(0,0,10000)});


#if OBJECT_ADD
            // remove all objects which are part of the unit test.
            foreach (var model in e.SceneNodes.Models.FindAll(p => p.Action.Contains("@key=unittest")))
            {
                sender.DeleteObject(model);
            }
            var transaction = new SimpleTransaction <Model>(sender);
            transaction.OnTransactionCompleted += transaction_OnTransactionCompleted;
            for (int h = 0; h < 1; h++)
            {
                for (int j = 0; j < 15; j++)
                {
                    for (int i = 0; i < 15; i++)
                    {
                        transaction.Add(new Model()
                        {
                            ModelName   = "bzmb0.rwx",
                            Action      = "@key=unittest",
                            Description = "Bot created object teet",
                            Position    = new Vector3((i * 120) + (-h * 1600), j * 120, 1000)
                        });
                    }
                }
            }
            sender.AddObjects(transaction);
#endif

#if BACKUP
            ConsoleHelpers.Write("Performing main backup...");
            _sw1.Start();
            var db = sender.Storage.Db;
            //var main_backup = from SceneNodes.SceneNodes p in db select p;
            //if (main_backup.Count() == 1)
            //    db.Delete(main_backup.Single());
            sender.Storage.Db.Store(e.SceneNodes);
            db.Commit();
            ConsoleHelpers.WriteLine("Done!" + _sw1.ElapsedMilliseconds + " ms.");
#endif

#if ACTION_INTERPRETER
            List <IEnumerable <IActionTrigger> > triggers = new List <IEnumerable <IActionTrigger> >();

            _sw1.Reset();
            _sw1.Start();
            foreach (var model in e.SceneNodes.Models)
            {
                var m = Interpret(model.Action);
                if (m != null)
                {
                    triggers.Add(Interpret(model.Action));
                }
            }
            ConsoleHelpers.WriteLine(string.Format("Interpreted {0} object actions in {1} ms.", triggers.Count, _sw1.ElapsedMilliseconds));
#endif
        }
 public static int Execute(this SimpleTransaction db, string sql, object parameters)
 {
     return(db.GetAdoAdapter().ExecuteNonQuery(sql, parameters.ObjectToDictionary()));
 }
 public static IEnumerable <IEnumerable <dynamic> > ToResultSets(this SimpleTransaction db, string sql,
                                                                 params KeyValuePair <string, object>[] parameters)
 {
     return(db.ToResultSets(sql, parameters.ToDictionary()));
 }
 public static int Execute(this SimpleTransaction db, string sql, params KeyValuePair <string, object>[] parameters)
 {
     return(db.GetAdoAdapter().ExecuteNonQuery(sql, parameters.ToDictionary()));
 }
 public static IEnumerable <IEnumerable <dynamic> > ToResultSets(this SimpleTransaction db, string sql, object parameters)
 {
     return(db.ToResultSets(sql, parameters.ObjectToDictionary()));
 }
Example #20
0
    public static void EnlistTransaction(Action prepare, Action commit, Action rollback, Action inDoubt)
    {
        var st = new SimpleTransaction(prepare, commit, rollback, inDoubt);

        Transaction.Current.EnlistVolatile(st, EnlistmentOptions.None);
    }
 public static object ToScalar(this SimpleTransaction db, string sql, params KeyValuePair <string, object>[] parameters)
 {
     return(db.GetAdoAdapter().ToScalar(sql, parameters.ToDictionary()));
 }
 public static dynamic ToRow(this SimpleTransaction db, string sql, object parameters)
 {
     return(db.ToRow(sql, parameters.ObjectToDictionary()));
 }
 public static dynamic ToRow(this SimpleTransaction db, string sql, params KeyValuePair <string, object>[] parameters)
 {
     return(db.ToRow(sql, parameters.ToDictionary()));
 }
 public static dynamic ToRow(this SimpleTransaction db, string sql, IDictionary <string, object> parameters)
 {
     return(db.GetAdoAdapter().ToRow(sql, parameters));
 }