Example #1
0
            public void ShouldNotAssignIdToInitialisedIdProperty()
            {
                var instance = new Person{Id = 9};

                instance = (Person)new IdGenerator().Identify(instance);

                Assert.Equal(9, instance.Id);
            }
Example #2
0
            public void AssignsAnIdToIdProperty()
            {
                var instance = new Person();

                instance = (Person)new IdGenerator().Identify(instance);

                Assert.Equal(1, instance.Id);
            }
Example #3
0
            public void CanMapForeignKey()
            {
                var db = new Db().WithForeignKeyInitializer()
                                 .MapForeignKey((Person c) => c.Address, c => c._AddressId);

                var p = new Person {Address = new Address()};

                db.Set<Person>().Add(p);
                Assert.NotNull(p._AddressId);
                Assert.Null(p.AddressId);
            }
Example #4
0
            public void InvokesIdGeneratorForAllObjectsInGraph()
            {
                var person = new Person();
                var address = new Address();
                person.Address = address;

                var fixture = new InMemorySetFixture();

                fixture.InMemorySet.Add(person);

                fixture.IdGenerator.Received(1).Identify(person);
                fixture.IdGenerator.Received(1).Identify(address);
            }
Example #5
0
            public void CanAddNestedObject()
            {
                var fixture = new InMemorySetFixture();

                var person = new Person();
                var address = new Address();
                person.Address = address;

                fixture.InMemorySet.Add(person);

                Assert.Equal(person, fixture.InMemorySet.Items.Single());
                Assert.Equal(address, fixture.Cache.For(typeof (Address)).Items.Single());
            }
Example #6
0
            public void InvokesMaterializationHook()
            {
                var address = new Address();
                var person = new Person
                    {
                        Address = address
                    };

                var fixture = new InMemorySetFixture();
                var hook = Substitute.For<IMaterializationHook>();

                fixture.MaterializationHooks.Add(hook);

                fixture.InMemorySet.Add(person);

                hook.Received(1).Execute(person);
                hook.Received(1).Execute(address);
            }