예제 #1
0
        public virtual async Task Polymorphism()
        {
            await entityRepo.TruncateCollection();

            await collectionEntityRepo.TruncateCollection();

            TestExtraEltEntity entity2 = TestHelper.GetEntity2();
            await entityRepo.InsertOne(entity2);

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

            var entity2_repo = await 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

            await collectionEntityRepo.InsertOne(collectionTest);

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

            AssertHelper.AreJsonEqual(collectionTest, collectionTest_fromRepo, ErrorMsg: "Check if collection elements has the good type");
        }
예제 #2
0
        public virtual async Task InsertExtraEltEntity()
        {
            await entityExtraEltRepo.TruncateCollection();

            var entity = TestHelper.GetEntity2();
            await entityExtraEltRepo.InsertOne(entity);

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

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

            //entity_repo.LookLikeEachOther(entity);

            AssertHelper.AreJsonEqual(entity, entity_repo);
            //Assert.AreEqual<TestEntity>(entity1, entity1_repo);
        }
예제 #3
0
        public virtual async Task InsertEntity()
        {
            await entityRepo.TruncateCollection();

            var entity1 = TestHelper.GetEntity1();
            await entityRepo.InsertOne(entity1);

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

            var t1 = new DateTime(2016, 01, 01, 0, 0, 0, DateTimeKind.Utc);
            var t2 = new DateTime(2017, 01, 01, 0, 0, 0, DateTimeKind.Utc);

            NoSQLRepoHelper.DateTimeUtcNow = (() => t1); // Set the current time to t1

            Exception e = null;

            try
            {
                await entityRepo.InsertOne(entity1);
            }
            catch (Exception ex)
            {
                e = ex;
            }

            Assert.IsInstanceOfType(e, typeof(DupplicateKeyNoSQLException), "InsertOne should raise DupplicateKeyException if id already exists");

            var insertResult = await entityRepo.InsertOne(entity1, InsertMode.do_nothing_if_key_exists); // Do Nothing

            Assert.AreEqual(InsertResult.not_affected, insertResult, "Expecting not_affected result");

            var entity1_repo = await entityRepo.GetById(entity1.Id);

            Assert.IsNotNull(entity1_repo);
            AssertHelper.AreJsonEqual(entity1, entity1_repo);
            Assert.AreEqual(t1, entity1.SystemCreationDate, "SystemCreationDate should be defined during insert");
            Assert.AreEqual(t1, entity1.SystemLastUpdateDate, "SystemLastUpdateDate should be defined during insert");

            // Replace first version
            {
                NoSQLRepoHelper.DateTimeUtcNow = (() => t2); // Set the current time to t2

                var entity1V2 = TestHelper.GetEntity1();
                entity1V2.Id = entity1.Id;

                entity1V2.Name = "Balan2";
                await entityRepo.InsertOne(entity1V2, InsertMode.erase_existing); // Erase

                var entity1V2_fromRepo = await entityRepo.GetById(entity1.Id);

                Assert.AreEqual(entity1V2_fromRepo.Name, "Balan2", "The insert with erase_existing mode should erase the previous version of the entity");
                Assert.AreEqual(t1, entity1V2.SystemCreationDate, "SystemCreationDate should be the date of the erased entity version");
                Assert.AreEqual(t2, entity1V2.SystemLastUpdateDate, "SystemLastUpdateDate should the date of the update of the entity version");

                AssertHelper.AreJsonEqual(entity1V2, entity1V2_fromRepo);
            }

            // Erase while doc not exists
            {
                var entity2 = TestHelper.GetEntity2();
                await entityRepo.InsertOne(entity2, InsertMode.erase_existing); // Insert

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

                AssertHelper.AreJsonEqual(entity2, entity2_repo);

                // ABN: why this modification of unit test ?!
                // Clone in order to get a new objet of type TestEntity because a cast is not suffisant
                //var entity2Casted = entity2.CloneToTestEntity();
                //AssertHelper.AreJsonEqual(entity2Casted, entity2_repo);
            }
        }