Exemple #1
0
        public void Comparing_reference_should_use_the_specified_property_comparisons()
        {
            spec.CheckReference(x => x.FirstKitten, cat.FirstKitten, x => x.Id).VerifyTheMappings();

            // Should fail because the names don't match.
            Assert.Throws <ApplicationException>(() => spec.CheckReference(x => x.FirstKitten, cat.FirstKitten, x => x.Id, x => x.Name)
                                                 .VerifyTheMappings());
        }
        public void Passed_Transaction_Should_Apply_For_Reference_Saving()
        {
            var transaction = MockRepository.GenerateMock<ITransaction>();
            transaction.Expect(x => x.IsActive).Return(true);

            var session = MockRepository.GenerateMock<ISession>();
            session.Expect(x => x.Transaction).Return(transaction).Repeat.Twice();

            session.Expect(x => x.BeginTransaction()).Repeat.Never();
            session.Expect(s => s.Get<Cat>(null)).IgnoreArguments().Return(
                new Cat
                {
                    Name = "Fluffy",
                    CatType = new CatType
                    {
                        Name = "Persian"
                    }
                });

            var spec = new PersistenceSpecification<Cat>(session, new NameEqualityComparer());
            spec.CheckProperty(x => x.Name, "Fluffy");
            spec.CheckReference(x => x.CatType, new CatType {Name = "Persian"});

            spec.VerifyTheMappings();

            session.VerifyAllExpectations();
        }
Exemple #3
0
        public void Passed_Transaction_Should_Apply_For_Reference_Saving()
        {
            var transaction = MockRepository.GenerateMock <ITransaction>();

            transaction.Expect(x => x.IsActive).Return(true);


            var session = MockRepository.GenerateMock <ISession>();

            session.Expect(x => x.Transaction).Return(transaction).Repeat.Twice();

            session.Expect(x => x.BeginTransaction()).Repeat.Never();
            session.Expect(s => s.Get <Cat>(null)).IgnoreArguments().Return(
                new Cat
            {
                Name    = "Fluffy",
                CatType = new CatType
                {
                    Name = "Persian"
                }
            });


            var spec = new PersistenceSpecification <Cat>(session, new NameEqualityComparer());

            spec.CheckProperty(x => x.Name, "Fluffy");
            spec.CheckReference(x => x.CatType, new CatType {
                Name = "Persian"
            });

            spec.VerifyTheMappings();

            session.VerifyAllExpectations();
        }
Exemple #4
0
        public void Passed_Transaction_Should_Apply_For_Reference_Saving()
        {
            var transaction = A.Fake <ITransaction>();

            A.CallTo(() => transaction.IsActive).Returns(true);

            var session = A.Fake <ISession>();

            A.CallTo(() => session.Transaction).Returns(transaction);
            A.CallTo(() => session.Get <Cat>(null)).WithAnyArguments()
            .Returns(
                new Cat
            {
                Name    = "Fluffy",
                CatType = new CatType
                {
                    Name = "Persian"
                }
            });


            var spec = new PersistenceSpecification <Cat>(session, new NameEqualityComparer());

            spec.CheckProperty(x => x.Name, "Fluffy");
            spec.CheckReference(x => x.CatType, new CatType {
                Name = "Persian"
            });

            spec.VerifyTheMappings();

            A.CallTo(() => session.Transaction).MustHaveHappened(Repeated.Exactly.Twice);
            A.CallTo(() => session.BeginTransaction()).MustNotHaveHappened();
        }
        public void Passed_Transaction_Should_Apply_For_Reference_Saving()
        {
            var transaction = A.Fake<ITransaction>();
            A.CallTo(() => transaction.IsActive).Returns(true);

            var session = A.Fake<ISession>();
            A.CallTo(() => session.Transaction).Returns(transaction);
            A.CallTo(() => session.Get<Cat>(null)).WithAnyArguments()
                .Returns(
                new Cat
                {
                    Name = "Fluffy",
                    CatType = new CatType
                    {
                        Name = "Persian"
                    }
                });


            var spec = new PersistenceSpecification<Cat>(session, new NameEqualityComparer());
            spec.CheckProperty(x => x.Name, "Fluffy");
            spec.CheckReference(x => x.CatType, new CatType { Name = "Persian" });

            spec.VerifyTheMappings();

            A.CallTo(() => session.Transaction).MustHaveHappened(Repeated.Exactly.Twice);
            A.CallTo(() => session.BeginTransaction()).MustNotHaveHappened();
        }
        protected override void TestMappings(PersistenceSpecification <Text> specification)
        {
            Assertion.NotNull(specification);

            var textsCategory = new TextsCategory("category.name");
            var person        = new Person("person.nameFirst", "person.nameLast");
            var translation   = new TextTranslation("ru", "translation.name", "translation.text");

            specification.TransactionalSave(textsCategory);
            specification.TransactionalSave(person);
            specification.TransactionalSave(translation);

            base.TestMappings(specification);
            specification.CheckReference(mapping => mapping.Category, textsCategory);
            specification.CheckReference(mapping => mapping.Person, person);
            specification.CheckBag(mapping => mapping.Translations, new[] { translation });
        }
Exemple #7
0
        protected override void TestMappings(PersistenceSpecification <WebLink> specification)
        {
            Assertion.NotNull(specification);

            var category = new WebLinksCategory("category.name");

            specification.TransactionalSave(category);

            base.TestMappings(specification);
            specification.CheckReference(mapping => mapping.Category, category);
            specification.CheckProperty(mapping => mapping.Url, "url");
        }
        protected override void TestMappings(PersistenceSpecification <Playcast> specification)
        {
            Assertion.NotNull(specification);

            var category = new PlaycastsCategory("category.name");

            specification.TransactionalSave(category);

            base.TestMappings(specification);
            specification.CheckProperty(mapping => mapping.Audio, "audio");
            specification.CheckReference(mapping => mapping.Category, category);
            specification.CheckProperty(mapping => mapping.Image, "image");
        }
        protected override void TestMappings(PersistenceSpecification <Article> specification)
        {
            Assertion.NotNull(specification);

            var category = new ArticlesCategory("category.name");

            specification.TransactionalSave(category);

            base.TestMappings(specification);
            specification.CheckProperty(mapping => mapping.Annotation, "annotation");
            specification.CheckReference(mapping => mapping.Category, category);
            specification.CheckProperty(mapping => mapping.Image, "image");
        }
        protected override void TestMappings(PersistenceSpecification <City> specification)
        {
            Assertion.NotNull(specification);

            var country = new Country("country.name", "ru");

            specification.TransactionalSave(country);

            specification.CheckProperty(mapping => mapping.Id, (long)1);
            specification.CheckProperty(mapping => mapping.Version, (long)1);
            specification.CheckReference(mapping => mapping.Country, country);
            specification.CheckProperty(mapping => mapping.Name, "name");
            specification.CheckProperty(mapping => mapping.Region, "region");
        }
Exemple #11
0
        protected override void TestMappings(PersistenceSpecification <Announcement> specification)
        {
            Assertion.NotNull(specification);

            var category = new AnnouncementsCategory("category.name");

            specification.TransactionalSave(category);

            base.TestMappings(specification);
            specification.CheckReference(mapping => mapping.Category, category);
            specification.CheckProperty(mapping => mapping.Currency, "rub");
            specification.CheckProperty(mapping => mapping.Image, "image");
            specification.CheckProperty(mapping => mapping.Price, (decimal)1);
        }
        protected override void TestMappings(PersistenceSpecification <Audio> specification)
        {
            Assertion.NotNull(specification);

            var category = new AudiosCategory("category.name");

            specification.TransactionalSave(category);

            specification.CheckProperty(mapping => mapping.Id, (long)1);
            specification.CheckProperty(mapping => mapping.Version, (long)1);
            specification.CheckProperty(mapping => mapping.Bitrate, (short)16);
            specification.CheckReference(mapping => mapping.Category, category);
            specification.CheckProperty(mapping => mapping.Duration, (long)10);
            specification.CheckProperty(mapping => mapping.File, "file");
        }
        protected override void TestMappings(PersistenceSpecification <Art> specification)
        {
            Assertion.NotNull(specification);

            //var album = new ArtsAlbum("album.name");
            var person = new Person("person.nameFirst", "person.nameLast");

            //specification.TransactionalSave(album);
            specification.TransactionalSave(person);

            base.TestMappings(specification);
            //specification.CheckReference(mapping => mapping.Album, album);
            specification.CheckProperty(mapping => mapping.Image, "image");
            specification.CheckProperty(mapping => mapping.Material, "material");
            specification.CheckReference(mapping => mapping.Person, person);
            specification.CheckProperty(mapping => mapping.Place, "place");
        }
        protected override void TestMappings(PersistenceSpecification <Location> specification)
        {
            Assertion.NotNull(specification);

            var country = new Country("city.country.name", "ru");
            var city    = new City("city.name", country);

            specification.TransactionalSave(country);
            specification.TransactionalSave(city);

            specification.CheckProperty(mapping => mapping.Id, (long)1);
            specification.CheckProperty(mapping => mapping.Version, (long)1);
            specification.CheckProperty(mapping => mapping.Address, "address");
            specification.CheckReference(mapping => mapping.City, city);
            specification.CheckProperty(mapping => mapping.Latitude, (decimal)90);
            specification.CheckProperty(mapping => mapping.Longitude, (decimal)180);
            specification.CheckProperty(mapping => mapping.PostalCode, "postalCode");
        }