public void Can_Save_and_Load_Self_References()
        {
            var customer = new SelfCustomer
            {
                Name           = "Customer 1",
                PrimaryAddress = new SelfCustomerAddress
                {
                    AddressLine1 = "1 Humpty Street",
                    City         = "Humpty Doo",
                    State        = "Northern Territory",
                    Country      = "Australia"
                },
            };

            db.Save(new SelfCustomer {
                Name = "Dummy Incrementer"
            });

            db.Save(customer);

            Assert.That(customer.Id, Is.GreaterThan(0));
            Assert.That(customer.SelfCustomerAddressId, Is.Null);

            db.SaveReferences(customer, customer.PrimaryAddress);
            Assert.That(customer.SelfCustomerAddressId, Is.EqualTo(customer.PrimaryAddress.Id));

            var dbCustomer = db.LoadSingleById <SelfCustomer>(customer.Id);

            Assert.That(dbCustomer.PrimaryAddress, Is.Not.Null);

            customer = new SelfCustomer
            {
                Name           = "Customer 2",
                PrimaryAddress = new SelfCustomerAddress
                {
                    AddressLine1 = "2 Humpty Street",
                    City         = "Humpty Doo",
                    State        = "Northern Territory",
                    Country      = "Australia"
                },
            };

            db.Save(customer, references: true);
            Assert.That(customer.SelfCustomerAddressId, Is.EqualTo(customer.PrimaryAddress.Id));

            dbCustomer = db.LoadSingleById <SelfCustomer>(customer.Id);
            Assert.That(dbCustomer.PrimaryAddress, Is.Not.Null);
        }
        public void Can_save_and_load_self_references_with_null_references()
        {
            var customer = new SelfCustomer
            {
                Name           = "Customer 1",
                PrimaryAddress = null,
            };

            db.Save(customer, references: true);

            Assert.That(customer.Id, Is.GreaterThan(0));

            var dbCustomer = db.LoadSingleById <SelfCustomer>(customer.Id);

            Assert.That(dbCustomer.Name, Is.EqualTo("Customer 1"));

            var dbCustomers = db.LoadSelect <SelfCustomer>(q => q.Id == customer.Id);

            Assert.That(dbCustomers.Count, Is.EqualTo(1));
            Assert.That(dbCustomers[0].Name, Is.EqualTo("Customer 1"));
        }
        public void Can_Save_and_Load_Self_References()
        {
            var customer = new SelfCustomer
            {
                Name = "Customer 1",
                PrimaryAddress = new SelfCustomerAddress
                {
                    AddressLine1 = "1 Humpty Street",
                    City = "Humpty Doo",
                    State = "Northern Territory",
                    Country = "Australia"
                },
            };

            db.Save(new SelfCustomer { Name = "Dummy Incrementer" });

            db.Save(customer);

            Assert.That(customer.Id, Is.GreaterThan(0));
            Assert.That(customer.SelfCustomerAddressId, Is.Null);

            db.SaveReferences(customer, customer.PrimaryAddress);
            Assert.That(customer.SelfCustomerAddressId, Is.EqualTo(customer.PrimaryAddress.Id));

            var dbCustomer = db.LoadSingleById<SelfCustomer>(customer.Id);
            Assert.That(dbCustomer.PrimaryAddress, Is.Not.Null);

            customer = new SelfCustomer
            {
                Name = "Customer 2",
                PrimaryAddress = new SelfCustomerAddress
                {
                    AddressLine1 = "2 Humpty Street",
                    City = "Humpty Doo",
                    State = "Northern Territory",
                    Country = "Australia"
                },
            };

            db.Save(customer, references: true);
            Assert.That(customer.SelfCustomerAddressId, Is.EqualTo(customer.PrimaryAddress.Id));

            dbCustomer = db.LoadSingleById<SelfCustomer>(customer.Id);
            Assert.That(dbCustomer.PrimaryAddress, Is.Not.Null);
        }
        public void Can_save_and_load_self_references_with_null_references()
        {
            var customer = new SelfCustomer
            {
                Name = "Customer 1",
                PrimaryAddress = null,
            };

            db.Save(customer, references: true);

            Assert.That(customer.Id, Is.GreaterThan(0));

            var dbCustomer = db.LoadSingleById<SelfCustomer>(customer.Id);
            Assert.That(dbCustomer.Name, Is.EqualTo("Customer 1"));

            var dbCustomers = db.LoadSelect<SelfCustomer>(q => q.Id == customer.Id);
            Assert.That(dbCustomers.Count, Is.EqualTo(1));
            Assert.That(dbCustomers[0].Name, Is.EqualTo("Customer 1"));
        }