コード例 #1
0
        public void ConstraintsAreEqualWhenPropertiesAreEqual()
        {
            // arrange
            var first  = ExpectedConstraints.CreateForeignKey <Foo, Bar, int>(f => f.Bar, f => f.BarId, b => b.Id);
            var second = ExpectedConstraints.CreateForeignKey <Foo, Bar, int>(x => x.Bar, x => x.BarId, x => x.Id);

            // act and assert
            first.Should().Be(second);
            first.GetHashCode().Should().Be(second.GetHashCode());
        }
コード例 #2
0
        public void SetsDerivedPropertyToGeneratedProxyProperty()
        {
            // arrange
            var fixture = IntegrationTest.GetFixture(ExpectedConstraints.CreateForeignKey <Foo, Bar, int>(f => f.Bar, f => f.BarId, b => b.Id));
            var foo     = fixture.Create <Faz>();

            // act
            var bar = foo.Bar;

            // assert
            foo.BarId.Should().Be(bar.Id);
        }
コード例 #3
0
        public void SetsPropertyToNull()
        {
            // arrange
            var fixture = IntegrationTest.GetFixture(ExpectedConstraints.CreateForeignKey <Foo, Bar, int>(f => f.Bar, f => f.BarId, b => b.Id));
            var foo     = fixture.Create <Foo>();
            Bar bar     = null;

            // act
            foo.Bar = bar;

            // assert
            foo.BarId.Should().Be(0);
        }
コード例 #4
0
        public void ConstraintsShouldBeGenerated()
        {
            // arrange
            var expected = new IPropertyConstraint[]
            {
                ExpectedConstraints.CreateOneToMany <User, Post>(u => u.Posts, p => p.Poster),
                ExpectedConstraints.CreateManyToOne <Post, User>(p => p.Poster, u => u.Posts),
                ExpectedConstraints.CreateOneToOne <User, ContactDetails>(u => u.ContactDetails, c => c.User),
                ExpectedConstraints.CreateOneToOne <ContactDetails, User>(c => c.User, u => u.ContactDetails),
                ExpectedConstraints.CreateForeignKey <Post, User, int>(p => p.Poster, p => p.PosterId, u => u.Id),
                ExpectedConstraints.CreateForeignKey <ContactDetails, User, int>(c => c.User, c => c.UserId, u => u.Id)
            };

            // act
            var metadata = GetMetadata();

            // assert
            metadata.Constraints.Should().BeEquivalentTo(expected);
        }