Ejemplo n.º 1
0
        public void It_is_deleting_only_child_objects_marked_by_CascadeDelete_attribute()
        {
            OdbFactory.Delete(DbName);

            using (var odb = OdbFactory.Open(DbName))
            {
                var shouldBeDeleted = new Address("A", City.Cracow, 1);
                var shouldNotBeDeleted = new Address("B", City.Cracow, 1);
                odb.Store(new TestCascadeDeleteClass(shouldBeDeleted, shouldNotBeDeleted));
            }

            using (var odb = OdbFactory.Open(DbName))
            {
                var count = odb.QueryAndExecute<Address>().Count;
                Assert.That(count, Is.EqualTo(2));
            }

            using (var odb = OdbFactory.Open(DbName))
            {
                var first = odb.QueryAndExecute<TestCascadeDeleteClass>().GetFirst();
                odb.Delete(first);
            }

            using (var odb = OdbFactory.Open(DbName))
            {
                var count = odb.QueryAndExecute<TestCascadeDeleteClass>().Count;
                Assert.That(count, Is.EqualTo(0));

                count = odb.QueryAndExecute<Address>().Count;
                Assert.That(count, Is.EqualTo(1));

                var first = odb.QueryAndExecute<Address>().GetFirst();
                Assert.That(first.Street, Is.EqualTo("B"));
            }
        }
        public void It_should_be_possible_to_add_retrieved_object_after_disconnecting_it()
        {
            using (var odb = OdbFactory.Open(DbName))
            {
                var address = new Address("A", City.Cracow, 1);
                odb.Store(address);
            }

            using (var odb = OdbFactory.Open(DbName))
            {
                var address = odb.QueryAndExecute<Address>().GetFirst();
                odb.Store(address);
            }

            Address clonedAddress;
            using (var odb = OdbFactory.Open(DbName))
            {
                var count = odb.QueryAndExecute<Address>().Count;
                Assert.That(count, Is.EqualTo(1));
                clonedAddress = odb.QueryAndExecute<Address>().GetFirst();
            }

            using (var odb = OdbFactory.Open(DbName))
            {
                odb.Store(clonedAddress);
            }

            using (var odb = OdbFactory.Open(DbName))
            {
                var count = odb.QueryAndExecute<Address>().Count;
                Assert.That(count, Is.EqualTo(2));
            }
        }
Ejemplo n.º 3
0
 public TestCascadeDeleteClass(Address address1, Address address2)
 {
     _address1 = address1;
     _address2 = address2;
 }
Ejemplo n.º 4
0
 private static User FullUser(string name, int age, string street, City city, int number)
 {
     var address = new Address(street, city, number);
     return new User(name, age, address);
 }