public virtual void ViewTests() { entityRepo.TruncateCollection(); // // Add test data // var entity1 = TestHelper.GetEntity1(); entity1.Id = "1"; entityRepo.InsertOne(entity1); var entity2 = TestHelper.GetEntity2(); entity2.Id = "2"; entityRepo.InsertOne(entity2); // Add the 3td et 4th entities to en secondary repo to ensure insert are visible throw all repositories var entity3 = TestHelper.GetEntity3(); entity3.Id = "3"; entityRepo.InsertOne(entity3); var entity4 = TestHelper.GetEntity4(); entity4.Id = "4"; entityRepo.InsertOne(entity4); // // Get data from an "Int" field // // Try on an other repo var res12 = entityRepo2.GetByField <int>(nameof(TestEntity.NumberOfChildenInt), 0).OrderBy(e => e.Id).ToList(); // Filter on 1 value var res1 = entityRepo.GetByField <int>(nameof(TestEntity.NumberOfChildenInt), 0).OrderBy(e => e.Id).ToList(); Assert.AreEqual(2, res1.Count); Assert.AreEqual("2", res1[0].Id); Assert.AreEqual("3", res1[1].Id); AssertHelper.AreJsonEqual(entity2, res1[0]); AssertHelper.AreJsonEqual(entity3, res1[1]); var res2 = entityRepo.GetByField <int>(nameof(TestEntity.NumberOfChildenInt), 0).OrderBy(e => e.Id).ToList(); Assert.AreEqual(2, res2.Count, "Check the an error not occured after a 2 call (the object entities are in memory)"); List <string> res3 = entityRepo.GetKeyByField <int>(nameof(TestEntity.NumberOfChildenInt), 0).OrderBy(e => e).ToList(); Assert.AreEqual("2", res3[0]); Assert.AreEqual("3", res3[1]); Exception expectedEx = null; try { entityRepo.GetByField <int>(nameof(TestEntity.NumberOfChildenLong), 0).OrderBy(e => e.Id).ToList(); } catch (Exception ex) { expectedEx = ex; } Assert.IsInstanceOfType(expectedEx, typeof(IndexNotFoundNoSQLException)); // Filter on a set of value var searchedValues = new List <int> { 0, 10 }; var res4 = entityRepo.GetByField <int>(nameof(TestEntity.NumberOfChildenInt), searchedValues).OrderBy(e => e.Id).ToList(); Assert.AreEqual(3, res4.Count); List <string> res5 = entityRepo.GetKeyByField <int>(nameof(TestEntity.NumberOfChildenInt), searchedValues).OrderBy(e => e).ToList(); Assert.AreEqual(3, res5.Count); // // Get data from a "List<string>" field // var res6 = entityRepo.GetByField <string>(nameof(TestEntity.Cities), "Grenoble").OrderBy(e => e.Id).ToList(); Assert.AreEqual(3, res6.Where(e => e.Cities.Contains("Grenoble")).Count()); var searchList = new List <string> { "Grenoble", "Andernos" }; var res7 = entityRepo.GetByField <string>(nameof(TestEntity.Cities), searchList).OrderBy(e => e.Id).ToList(); Assert.AreEqual(3, res7.Count, "Dupplicate entries should be removed"); Assert.AreEqual(3, res7.Where(e => e.Cities.Contains("Grenoble")).Count()); Assert.AreEqual(1, res7.Where(e => e.Cities.Contains("Andernos")).Count()); var res8 = entityRepo.GetByField <string>(nameof(TestEntity.Cities), "Grenoble").OrderBy(e => e.Id).ToList(); Assert.AreEqual(3, res8.Count); List <string> res9 = entityRepo.GetKeyByField <string>(nameof(TestEntity.Cities), searchList).OrderBy(e => e).ToList(); Assert.AreEqual(3, res9.Count, "Dupplicate entries should be removed"); var res10 = entityRepo.GetByField <string>(nameof(TestEntity.Cities), "GrEnObLe").OrderBy(e => e.Id).ToList(); Assert.AreEqual(0, res10.Count, "String comparison should be case sensitive"); var res11 = entityRepo.GetByField <string>(nameof(TestEntity.Cities), "Grenoblé").OrderBy(e => e.Id).ToList(); Assert.AreEqual(0, res11.Count, "String comparison should be accent sensitive"); }