Пример #1
0
        private TestConcurrentDbContext BuildTestDb()
        {
            var mongo = new TestConcurrentDbContext("test_mongoctx");

            mongo.Clear <Lion>();
            mongo.Clear <Owner>();

            // Add some pets:
            var p = new Lion();

            p.Age  = 5;
            p.Name = "Fluffy";
            p.Type = "Cat";

            mongo.Save(p);

            p      = new Lion();
            p.Age  = 4;
            p.Name = "Spot";
            p.Type = "Dog";

            mongo.Save(p);

            // Add some owners:
            var o = new Owner();

            o.Name         = "Ralph";
            o.NumberOfPets = 50;

            mongo.Save(o);

            return(mongo);
        }
Пример #2
0
        public void db_update_rolled_back_on_edit_test()
        {
            TestConcurrentDbContext mongo = BuildTestDb();

            Owner o = mongo.Owners.First();

            // Simulate other user updating db.
            Owner o2 = mongo.Owners.First();

            o2.NumberOfPets = 10;
            mongo.Save(o2);

            o.NumberOfPets = 1000;

            try
            {
                mongo.Save(o);
            }
            catch
            {
            }

            Owner dbOwner = mongo.Owners.First();

            Assert.AreEqual(o2.NumberOfPets, dbOwner.NumberOfPets);
        }
Пример #3
0
        public void db_update_fails_on_edit_test()
        {
            TestConcurrentDbContext mongo = BuildTestDb();

            Owner o = mongo.Owners.First();

            // Simulate other user updating db.
            Owner o2 = mongo.Owners.First();

            o2.NumberOfPets++;
            mongo.Save(o2);

            mongo.Save(o);
        }
Пример #4
0
        public void db_update_entity_without_interface_is_failure_test()
        {
            TestConcurrentDbContext mongo = BuildTestDb();

            Pet p = mongo.Pets.First();

            mongo.Save(p);
        }
Пример #5
0
        public void db_save_entity_without_interface_is_error_test()
        {
            TestConcurrentDbContext mongo = BuildTestDb();

            var p = new Pet();

            mongo.Save(p);
        }
Пример #6
0
        public void db_update_applied_on_overwrite_test()
        {
            TestConcurrentDbContext mongo = BuildTestDb();

            Owner o = mongo.Owners.First();

            // Simulate other user updating db.
            Owner o2 = mongo.Owners.First();

            o2.NumberOfPets = 10;
            mongo.Save(o2);

            o.NumberOfPets = 1000;

            mongo.Save(o, ConcurrentSaveOptions.OverwriteServerChanges);

            Owner dbOwner = mongo.Owners.First();

            Assert.AreEqual(o.NumberOfPets, dbOwner.NumberOfPets);
        }
Пример #7
0
        public void db_delete_entity_interface_required_test()
        {
            TestConcurrentDbContext mongo = BuildTestDb();

            Owner o = mongo.Owners.First();

            Owner o2 = mongo.Owners.First();

            mongo.Save(o2);

            mongo.Delete(o);
        }
Пример #8
0
        public void db_update_entity_without_interface_required_test()
        {
            TestConcurrentDbContext mongo = BuildTestDb();

            Lion p = mongo.Lions.First();

            string name = p.Name;

            p.Name = "Tiger";

            mongo.Save(p);

            Lion p2 = mongo.Lions.Single(c => c._id == p._id);

            Assert.AreNotEqual(name, p.Name);
            Assert.AreEqual(p.Name, p2.Name);
        }
Пример #9
0
        public void db_update_entity_with_interface_required_test()
        {
            TestConcurrentDbContext mongo = BuildTestDb();

            Owner o = mongo.Owners.First();

            int count = o.NumberOfPets;

            o.NumberOfPets++;

            mongo.Save(o);

            Owner o2 = mongo.Owners.Single(ow => ow._id == o._id);

            Assert.AreNotEqual(count, o.NumberOfPets);
            Assert.AreEqual(o.NumberOfPets, o2.NumberOfPets);
        }
Пример #10
0
        public void db_update_entity_changes_accessId_test()
        {
            TestConcurrentDbContext mongo = BuildTestDb();

            Owner o = mongo.Owners.First();

            o.NumberOfPets++;
            string accessId = o._accessId;

            mongo.Save(o);

            Owner o2 = mongo.Owners.Single(ow => ow._id == o._id);

            // AccessID changes on save
            Assert.AreNotEqual(accessId, o._accessId);

            // Is persisted to DB.
            Assert.AreEqual(o2._accessId, o._accessId);
        }