public void Transaction_Can_Commit()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            var tran = collection.BeginTransaction();

            tran.Commit();
        }
        public void Collection_Creates_Transaction()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            var tran = collection.BeginTransaction();

            Assert.NotNull(tran);
            Assert.NotNull(((IFoxTransactionSource<int>)collection).ActiveTransaction);
            Assert.Equal(TransactionState.Active, tran.State);
        }
Beispiel #3
0
    // Use this for initialization
    void Start()
    {
        foxesInStock = new FoxCollectionLog[3];
        foxNames     = new string[3];

        foxCollection = FindObjectOfType <FoxCollection>();
        GetNewStock();
        refreshTimer           = refreshTimerStart;
        sliderRefresh.maxValue = refreshTimerStart;
        //todo have a timer for refreshing the stock
    }
        public void Collection_As_Enumerable()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default) as IEnumerable;

            Assert.NotNull(collection);

            foreach (var v in collection)
            {
                //Assert that it's still enumerable
            }

        }
Beispiel #5
0
    // Use this for initialization
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);
    }
        public void Collection_In_Using_Block_Creates_Transaction()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);
            IFoxTransaction<int> tran;

            using (tran = collection.BeginTransaction())
            {
                Assert.NotNull(tran);
                Assert.NotNull(((IFoxTransactionSource<int>)collection).ActiveTransaction);
            }

            Assert.Null(((IFoxTransactionSource<int>)collection).ActiveTransaction);
            Assert.Equal(TransactionState.Aborted, tran.State);
        }
        public void Transaction_Dispose_Aborts_Uncommited()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);
            IFoxTransaction<int> tran;

            using (tran = collection.BeginTransaction())
            {
                Assert.NotNull(tran);
                Assert.NotNull(((IFoxTransactionSource<int>)collection).ActiveTransaction);
            }

            Assert.Null(((IFoxTransactionSource<int>)collection).ActiveTransaction);
            Assert.Equal(TransactionState.Aborted, tran.State);
        }
        public void Collection_Insert_Increases_Count()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            using (var tran = collection.BeginTransaction())
            {
                tran.Insert(1);

                tran.Commit();
            }

            Assert.Equal(1, collection.Count);
            Assert.Equal(1, collection.Keys.Count);
        }
        public void Transaction_Can_Update_Record_Multi_Transaction()
        {

            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);
            string itemKey;

            using (var tran = collection.BeginTransaction())
            {
                itemKey = tran.Insert(1);

                tran.Commit();
            }

            Assert.Equal(1, collection.Get(itemKey));

            using (var tran = collection.BeginTransaction())
            {
                tran.Update(itemKey, 2);

                tran.Commit();
            }

            Assert.Equal(2, collection.Get(itemKey));
        }
        public void Transaction_Cannot_Have_Nested_Transaction()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            collection.BeginTransaction();

            Assert.ThrowsAny<Exception>(() => collection.BeginTransaction());
        }
        public void Transaction_Insertion_On_Commit_Contains_Keys()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);
            var keys = new List<string>();

            using (var tran = collection.BeginTransaction())
            {
                keys.Add(tran.Insert(1));
                keys.Add(tran.Insert(2));
                keys.Add(tran.Insert(3));

                tran.Commit();
            }

            Assert.True(!keys.Except(collection.Keys).Any() && keys.Count == collection.Keys.Count);
        }
        public void Transaction_Commit_Changes_State()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            var tran = collection.BeginTransaction();

            tran.Commit();

            Assert.Equal(TransactionState.Committed, tran.State);
        }
        public void Transaction_In_Using_Block_Commits()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            IFoxTransaction<int> tran;

            using (tran = collection.BeginTransaction())
            {
                tran.Insert(1);
                tran.Commit();
            }

            Assert.Equal(TransactionState.Committed, tran.State);
        }
Beispiel #14
0
        public void Collection_Is_Not_ReadOnly()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            Assert.False(collection.IsReadOnly);
        }
        public void Transaction_Can_Delete_Record_Multi_Tran()
        {

            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);
            string itemKey;

            using (var tran = collection.BeginTransaction())
            {
                itemKey = tran.Insert(1);

                tran.Commit();
            }

            Assert.Equal(1, collection.Get(itemKey));
            Assert.True(collection.Keys.Contains(itemKey));

            using (var tran = collection.BeginTransaction())
            {
                tran.Delete(itemKey);

                tran.Commit();
            }

            Assert.Equal(default(int), collection.Get(itemKey));
            Assert.False(collection.Keys.Contains(itemKey));
        }
        public void Transaction_Delete_Non_Existent_Item_Throws()
        {

            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            var tran = collection.BeginTransaction();

            tran.Delete("NON EXISTENT KEY");

            Assert.ThrowsAny<Exception>(() => tran.Commit());

        }
        public void Transaction_Failed_Commit_Sets_State_To_Aborted()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            var tran = collection.BeginTransaction();
            try
            {
                tran.Update("NON EXISTENT KEY", 1);

                tran.Commit();
            }
            catch
            {
                //ignored
            }

            Assert.Equal(TransactionState.Aborted, tran.State);
        }
        public void Transaction_Rollback_Can_Rollback()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            var tran = collection.BeginTransaction();

            tran.Rollback();
            tran.Rollback();

            Assert.Equal(TransactionState.Aborted, tran.State);
            Assert.Null(((IFoxTransactionSource<int>)collection).ActiveTransaction);
        }
        public void Transaction_Insertion_On_Commit()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            using (var tran = collection.BeginTransaction())
            {
                tran.Insert(1);
                tran.Insert(2);
                tran.Insert(3);

                Assert.DoesNotContain(1, collection);
                Assert.DoesNotContain(2, collection);
                Assert.DoesNotContain(3, collection);

                tran.Commit();
            }

            Assert.Contains(1, collection);
            Assert.Contains(2, collection);
            Assert.Contains(3, collection);
        }
        public void Transaction_With_Operations_Can_Commit()
        {
            var collection = new FoxCollection<int>(NullSerializationStrategy.Default);

            var tran = collection.BeginTransaction();

            tran.Insert(1);

            tran.Commit();

            Assert.Equal(TransactionState.Committed, tran.State);
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            var sw = new Stopwatch();

            var store = new FoxCollection<object>(new JsonSerializationStrategy(new FileSystemStore("hello"))); //jit
            var store2 = new FoxCollection<object>(new JsonSerializationStrategy(new CompressedDataStore(new FileSystemStore("hello2")))); //jit


            sw.Restart();

            //for (int i = 0; i < 1000; i++)
            store = new FoxCollection<object>(new JsonSerializationStrategy(new FileSystemStore("hello")));

            sw.Stop();

            Console.WriteLine("Uncompressed Load: {0}", (double)sw.ElapsedMilliseconds);

            sw.Restart();

            //for (int i = 0; i < 1000; i++)
            store2 = new FoxCollection<object>(new JsonSerializationStrategy(new CompressedDataStore(new FileSystemStore("hello2"))));

            sw.Stop();

            Console.WriteLine("Compressed Load: {0}", (double)sw.ElapsedMilliseconds);

            sw.Restart();
            using (var trans = store.BeginTransaction())
            {
                for (int i = 0; i < 10000; i++)
                {
                    trans.Insert(new Test1());
                    trans.Insert(new Test2());
                }

            }

            sw.Stop();

            Console.WriteLine("One Tran: {0}", (double)sw.ElapsedMilliseconds);



            //sw.Restart();
            //for (int i = 0; i < 10000; i++)
            //{
            //    var tran = store2.BeginTransaction();
            //    try
            //    {

            //        tran.Insert(new Test1());
            //        tran.Insert(new Test2());
            //        //tran.Update(Guid.NewGuid().ToString(), new Test1());


            //        tran.Commit();
            //    }
            //    catch
            //    {
            //        tran.Rollback();
            //    }
            //}

            //sw.Stop();

            //Console.WriteLine("Multi Tran: {0}", (double)sw.ElapsedMilliseconds);

            store.Save(); //jit

            sw.Restart();
            store.Save(); //jit
            //for (int i = 0; i < 1000; i++)
            //    store.Save();
            sw.Stop();

            Console.WriteLine("Uncompressed Save: {0}", (double)sw.ElapsedMilliseconds);

            store2.Save(); //jit

            sw.Restart();
            store2.Save(); //jit
            //for (int i = 0; i < 1000; i++)
            //    store2.Save();
            sw.Stop();

            Console.WriteLine("Compressed Save: {0}", (double)sw.ElapsedMilliseconds);

            Console.ReadKey(true);
        }