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); }
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); }
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); }
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); } }
//[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); }
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); }
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 }); }
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); }
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); } }
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); }
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)); }
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]); }
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); }
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)]"); }
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"); }
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(); }
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); } }