Exemple #1
0
        public void UpdateMany_Success()
        {
            var icarus     = IcarusClient.Instance;
            var collection = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection);

            var obj1 = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello1", Temp = "Anything1"
            };
            var obj2 = new SomeObject()
            {
                SomeInt = 2, SomeString = "Hello2", Temp = "Anything2"
            };

            var items = collection.InsertMany(new SomeObject[] { obj1, obj2 });

            Assert.AreEqual(1, items[0]._id);
            Assert.AreEqual(2, items[1]._id);

            obj1.SomeString = "Updated";
            obj2.SomeString = "Updated";
            items           = collection.UpdateMany(new SomeObject[] { obj1, obj2 });
            Assert.IsNotNull(items);

            Assert.AreEqual("Hello1", items[0].SomeString);
            Assert.AreEqual(1, items[0].SomeInt);
            Assert.AreEqual(1, items[0]._id);

            var item = collection.Find(1);

            Assert.IsNotNull(item);
            Assert.AreEqual("Updated", item.SomeString);
            Assert.AreEqual(1, item.SomeInt);
            Assert.AreEqual(1, item._id);
        }
Exemple #2
0
        public void RemoveMany_Success()
        {
            var icarus = IcarusClient.Instance;
            var obj1   = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello1", Temp = "Anything1"
            };
            var obj2 = new SomeObject()
            {
                SomeInt = 2, SomeString = "Hello2", Temp = "Anything2"
            };

            var items = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).InsertMany(new[] { obj1, obj2 });

            Assert.AreEqual(2, items.Count);
            Assert.AreEqual(1, items[0]._id);
            Assert.AreEqual(2, items[1]._id);

            var items2 = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).RemoveMany(new[] { 1L, 2L });

            Assert.IsNotNull(items2);
            Assert.AreEqual(2, items2.Count);
            Assert.AreEqual("Hello1", items2[0].SomeString);
            Assert.AreEqual(1, items2[0].SomeInt);
            Assert.AreEqual(1, items2[0]._id);

            var item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Find(1);

            Assert.IsNull(item);
        }
Exemple #3
0
        public void Find_JsonPath_Boolean_Success(bool value)
        {
            var icarus = IcarusClient.Instance;
            var obj1   = new SomeObject()
            {
                SomeInt = 1, SomeBool = true, Temp = "Anything1"
            };
            var obj2 = new SomeObject()
            {
                SomeInt = 1, SomeBool = false, Temp = "Anything2"
            };

            var collection = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection);

            var items = collection.InsertMany(new[] { obj1, obj2 });

            Assert.AreEqual(2, items.Count);
            Assert.AreEqual(1, items[0]._id);
            Assert.AreEqual(2, items[1]._id);

            var item = collection.Find("$[?(@.SomeBool == " + value.ToString().ToLower() + ")]");

            Assert.IsNotNull(item);
            Assert.AreEqual(1, item.SomeInt);
            Assert.AreEqual(value, item.SomeBool);
            Assert.AreEqual(value ? 1 : 2, item._id);
        }
Exemple #4
0
        public void FindMany_Filter_Success(object value, IcarusEqualityFilter filter, int expectedAmount, bool isNull)
        {
            var icarus = IcarusClient.Instance;
            var obj1   = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello1", Temp = "Anything1"
            };
            var obj2 = new SomeObject()
            {
                SomeInt = 2, SomeString = "Hello2", Temp = "Anything2"
            };

            var items = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).InsertMany(new[] { obj1, obj2 });

            Assert.AreEqual(2, items.Count);
            Assert.AreEqual(1, items[0]._id);
            Assert.AreEqual(2, items[1]._id);

            var items2 = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).FindMany("SomeInt", value, filter);

            if (isNull)
            {
                Assert.IsNull(items2);
            }
            else
            {
                Assert.IsNotNull(items2);
                Assert.AreEqual(expectedAmount, items2.Count);
            }
        }
Exemple #5
0
        //[TestCase(100, 60)]
        //[TestCase(1000, 600)]
        //[TestCase(10000, 6000)]
        //[TestCase(100000, 60000)]
        public void LargeDataSet(int amount, int toFind)
        {
            var icarus     = IcarusClient.Instance;
            var collection = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection);

            for (var i = 1; i <= amount; i++)
            {
                var _obj = new SomeObject()
                {
                    SomeInt = i, SomeString = "Hello" + i, Temp = "Anything" + i
                };
                var _item = collection.Insert(_obj, false);
                Assert.AreEqual(i, _item._id);
            }

            collection.Persist();
            collection.Refresh();

            var item = collection.Find(toFind);

            Assert.IsNotNull(item);
            Assert.AreEqual("Hello" + toFind, item.SomeString);
            Assert.AreEqual(toFind, item.SomeInt);
            Assert.AreEqual(toFind, item._id);
        }
Exemple #6
0
        public void Update_Success()
        {
            var icarus = IcarusClient.Instance;
            var obj1   = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello1", Temp = "Anything1"
            };

            var item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Insert(obj1);

            Assert.AreEqual(1, item._id);

            obj1.SomeString = "Updated";
            item            = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Update(obj1);
            Assert.IsNotNull(item);
            Assert.AreEqual("Hello1", item.SomeString);
            Assert.AreEqual(1, item.SomeInt);
            Assert.AreEqual(1, item._id);

            item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Find(1);
            Assert.IsNotNull(item);
            Assert.AreEqual("Updated", item.SomeString);
            Assert.AreEqual(1, item.SomeInt);
            Assert.AreEqual(1, item._id);
        }
Exemple #7
0
 public void InsertMany_Fail_NullReference()
 {
     var icarus = IcarusClient.Instance;
     var obj    = new SomeObject()
     {
         SomeInt = 1, SomeString = "Hello"
     };
     var items = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).InsertMany(new[] { obj });
 }
Exemple #8
0
        public void Insert_Success()
        {
            var icarus = IcarusClient.Instance;
            var obj    = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello", Temp = "Anything"
            };

            var item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Insert(obj);

            Assert.AreEqual(1, item._id);
        }
Exemple #9
0
        public void Find_Filter_SuccessOnDates(IcarusEqualityFilter filter, bool isNull)
        {
            var icarus = IcarusClient.Instance;
            var now    = DateTime.Now;

            var obj1 = new SomeObject()
            {
                SomeDate = now, Temp = "Anything1"
            };
            var obj2 = new SomeObject()
            {
                SomeDate = now.AddDays(1), Temp = "Anything2"
            };

            var items = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).InsertMany(new[] { obj1, obj2 });

            Assert.AreEqual(2, items.Count);
            Assert.AreEqual(1, items[0]._id);
            Assert.AreEqual(2, items[1]._id);

            var item = default(SomeObject);

            switch (filter)
            {
            case IcarusEqualityFilter.Equal:
                item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Find("SomeDate", now, filter);
                break;

            case IcarusEqualityFilter.NotEqual:
                item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Find("SomeDate", now.AddDays(-1), filter);
                break;

            case IcarusEqualityFilter.GreaterThan:
                item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Find("SomeDate", now.AddMinutes(5), filter);
                break;
            }

            if (isNull)
            {
                Assert.IsNull(item);
            }
            else
            {
                Assert.IsNotNull(item);
            }
        }
Exemple #10
0
        public void InsertMany_Success()
        {
            var icarus = IcarusClient.Instance;
            var obj1   = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello1", Temp = "Anything1"
            };
            var obj2 = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello2", Temp = "Anything2"
            };

            var items = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).InsertMany(new[] { obj1, obj2 });

            Assert.AreEqual(2, items.Count);
            Assert.AreEqual(1, items[0]._id);
            Assert.AreEqual(2, items[1]._id);
        }
Exemple #11
0
        public void TwoIcarusLocations_Insert_Success()
        {
            IcarusClient.Instance.Initialise(".\\Test", "test2");

            var icarus = IcarusClient.Instance;
            var obj    = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello", Temp = "Anything"
            };

            var item = icarus.GetDataStore("InnerTest", "test2").GetCollection <SomeObject>(_collection).Insert(obj);

            Assert.AreEqual(1, item._id);

            var path = Path.GetFullPath(".\\Test\\InnerTest\\" + _collection + ".json");

            Assert.IsTrue(File.Exists(path));
        }
Exemple #12
0
        public void FindMany_Ids_Success_Nothing()
        {
            var icarus = IcarusClient.Instance;
            var obj1   = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello1", Temp = "Anything1"
            };
            var item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Insert(obj1);

            var items = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).FindMany(new[] { 1L, 2L });

            Assert.IsNotNull(items);
            Assert.AreEqual(2, items.Count);

            Assert.AreEqual("Hello1", items[0].SomeString);
            Assert.AreEqual(1, items[0].SomeInt);
            Assert.AreEqual(1, items[0]._id);

            Assert.IsNull(items[1]);
        }
Exemple #13
0
        public void Find_Filter_FailForMultiple(object value, IcarusEqualityFilter filter)
        {
            var icarus = IcarusClient.Instance;
            var obj1   = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello1", Temp = "Anything1"
            };
            var obj2 = new SomeObject()
            {
                SomeInt = 2, SomeString = "Hello2", Temp = "Anything2"
            };

            var items = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).InsertMany(new[] { obj1, obj2 });

            Assert.AreEqual(2, items.Count);
            Assert.AreEqual(1, items[0]._id);
            Assert.AreEqual(2, items[1]._id);

            var item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Find("SomeInt", value, filter);
        }
Exemple #14
0
        public void Find_JsonPath_FailForMultiple()
        {
            var icarus = IcarusClient.Instance;
            var obj1   = new SomeObject()
            {
                SomeInt = 2, SomeString = "Hello1", Temp = "Anything1"
            };
            var obj2 = new SomeObject()
            {
                SomeInt = 2, SomeString = "Hello2", Temp = "Anything2"
            };

            var items = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).InsertMany(new[] { obj1, obj2 });

            Assert.AreEqual(2, items.Count);
            Assert.AreEqual(1, items[0]._id);
            Assert.AreEqual(2, items[1]._id);

            var item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Find("$[?(@.SomeInt == 2)]");
        }
Exemple #15
0
        public void CheckIsNew_Success()
        {
            var icarus = IcarusClient.Instance;
            var obj    = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello", Temp = "Anything"
            };

            var expectedDataStore  = !Directory.Exists(".\\Test");
            var expectedCollection = !File.Exists(".\\Test\\" + _collection + ".json");

            var isNewDataStore  = true;
            var isNewCollection = true;

            var item = icarus.GetDataStore(_dataStore, out isNewDataStore).GetCollection <SomeObject>(_collection, out isNewCollection).Insert(obj);

            Assert.AreEqual(1, item._id);

            Assert.AreEqual(expectedDataStore, isNewDataStore, "Data store check incorrect");
            Assert.AreEqual(expectedCollection, isNewCollection, "Collection check incorrect");
        }
Exemple #16
0
        public void Toggle_Encryption_Success()
        {
            // insert data encrypted
            var icarus = IcarusClient.Instance;

            var obj = new SomeObject()
            {
                SomeInt = 1, SomeString = "Hello", Temp = "Anything"
            };

            var item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Insert(obj);

            Assert.AreEqual(1, item._id);

            // turn off encryption
            icarus.GetDataStore(_dataStore).Clear();
            icarus.Clear();
            icarus.IsEncryptionEnabled = false;

            item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection, false).Find(1);
            Assert.NotNull(item);
            Assert.AreEqual(1, item._id);

            icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Persist();

            // re-enable encryption
            icarus.GetDataStore(_dataStore).Clear();
            icarus.Clear();
            icarus.IsEncryptionEnabled = true;

            item = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection, true).Find(1);
            Assert.NotNull(item);
            Assert.AreEqual(1, item._id);

            icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection).Persist();
        }
Exemple #17
0
        public void Find_Filter_Boolean_Success(IcarusEqualityFilter filter, bool value)
        {
            var icarus = IcarusClient.Instance;
            var obj1   = new SomeObject()
            {
                SomeInt = 1, SomeBool = true, Temp = "Anything1"
            };
            var obj2 = new SomeObject()
            {
                SomeInt = 1, SomeBool = false, Temp = "Anything2"
            };

            var collection = icarus.GetDataStore(_dataStore).GetCollection <SomeObject>(_collection);

            var items = collection.InsertMany(new[] { obj1, obj2 });

            Assert.AreEqual(2, items.Count);
            Assert.AreEqual(1, items[0]._id);
            Assert.AreEqual(2, items[1]._id);

            var item = collection.Find("SomeBool", value, filter);

            Assert.IsNotNull(item);
            Assert.AreEqual(1, item.SomeInt);

            if (filter == IcarusEqualityFilter.Equal)
            {
                Assert.AreEqual(value, item.SomeBool);
                Assert.AreEqual(value ? 1 : 2, item._id);
            }
            else
            {
                Assert.AreEqual(!value, item.SomeBool);
                Assert.AreEqual(value ? 2 : 1, item._id);
            }
        }