public virtual void Polymorphism()
        {
            entityRepo.TruncateCollection();
            collectionEntityRepo.TruncateCollection();

            TestExtraEltEntity entity2 = TestHelper.GetEntity2();

            entityRepo.InsertOne(entity2);
            Assert.IsFalse(string.IsNullOrEmpty(entity2.Id));

            var entity2_repo = entityRepo.GetById(entity2.Id);

            //entity_repo.LookLikeEachOther(entity);

            AssertHelper.AreJsonEqual(entity2, entity2_repo, ErrorMsg: "Get of a TestExtraEltEntity instance from a TestEntity repo should return TestExtraEltEntity");
            //Assert.AreEqual<TestEntity>(entity1, entity1_repo);

            var collectionTest = new CollectionTest();

            collectionTest.PolymorphCollection.Add(entity2);                 // TestExtraEltEntity instance
            collectionTest.PolymorphCollection.Add(TestHelper.GetEntity1()); // TestEntity instance

            collectionEntityRepo.InsertOne(collectionTest);
            var collectionTest_fromRepo = collectionEntityRepo.GetById(collectionTest.Id);

            AssertHelper.AreJsonEqual(collectionTest, collectionTest_fromRepo, ErrorMsg: "Check if collection elements has the good type");
        }
        private void InsertEntities(int nbEntities, int firstId, INoSQLRepository <TestEntity> repo)
        {
            for (int i = 1; i <= nbEntities; i++)
            {
                Console.WriteLine(i);
                TestEntity e = new TestEntity
                {
                    Id                 = (firstId + i).ToString(),
                    PoidsDouble        = Faker.RandomNumber.Next(),
                    NumberOfChildenInt = Faker.RandomNumber.Next(),
                    Name               = Faker.Name.FullName()
                };

                repo.InsertOne(e);
            }
        }
        public virtual void InsertExtraEltEntity()
        {
            entityExtraEltRepo.TruncateCollection();

            var entity = TestHelper.GetEntity2();

            entityExtraEltRepo.InsertOne(entity);
            Assert.IsFalse(string.IsNullOrEmpty(entity.Id));

            var entity_repo = entityExtraEltRepo.GetById(entity.Id);

            //entity_repo.LookLikeEachOther(entity);

            AssertHelper.AreJsonEqual(entity, entity_repo);
            //Assert.AreEqual<TestEntity>(entity1, entity1_repo);
        }
Esempio n. 4
0
        public string AddLog <T>(T contentLog, string message, string longMessage, LogLevel level) where T : class
        {
            var log = new Log()
            {
                Message     = message,
                LongMessage = longMessage,
                ContentLog  = contentLog,
                Level       = level
            };
            var resultInsert = repository.InsertOne(log);

            if (resultInsert == InsertResult.inserted)
            {
                if (daysBeforeExpiration.HasValue)
                {
                    repository.ExpireAt(log.Id, DateTime.Now.AddDays(daysBeforeExpiration.Value));
                }
                return(log.Id);
            }
            else
            {
                return(string.Empty); // Generate exception with contracts
            }
        }
        public virtual void ExpireAt()
        {
            entityRepo.TruncateCollection();

            var entity1 = TestHelper.GetEntity1();

            entityRepo.InsertOne(entity1);
            Assert.IsFalse(string.IsNullOrEmpty(entity1.Id), "DocId has not been set during insert");

            var itemsInDatabase = entityRepo.GetAll();

            // We try to delete the item :
            entityRepo.ExpireAt(entity1.Id, DateTime.Now.AddSeconds(2));

            var itemsInDatabase2 = entityRepo.GetAll();

            Assert.IsTrue(itemsInDatabase.Count() == itemsInDatabase2.Count(), "entityRepo has not been physically deleted after compact");

            Thread.Sleep(4000);

            // We compact the database :
            entityRepo.CompactDatabase();

            var itemsInDatabaseAfterCompact = entityRepo.GetAll();

            Assert.IsTrue(itemsInDatabaseAfterCompact.Count() == itemsInDatabase.Count() - 1, "entityRepo has not been physically deleted after compact");
        }