Exemplo n.º 1
0
        public void SucceedsForValidDataWithReference()
        {
            // Arrange.
            var validator = new DocumentUniquenessValidator <TestEntityWithReference, string>(x => x.Title)
            {
                Scope = new Expression <Func <TestEntityWithReference, object> >[] { x => x.Site }
            };

            TestEntityWithReference.Create(new TestEntityWithReference
            {
                Site = Site.Create(new Site {
                    Title = "Baz"
                }),
                Title = "Foo"
            });
            var documentInstance = new TestEntityWithReference
            {
                Site = Site.Create(new Site {
                    Title = "Bar"
                }),
                Title = "Foo"
            };
            var context = DocumentValidationContext <TestEntityWithReference> .Create(documentInstance, SaveType.Any);

            // Act.
            var results = validator.Validate("Foo", context).ToList();

            // Assert.
            Assert.That(results, Is.Empty);
        }
Exemplo n.º 2
0
        public void FailsForInvalidData()
        {
            // Arrange.
            var validator = new DocumentUniquenessValidator <TestEntity, string>(x => x.Title)
            {
                Scope = new Expression <Func <TestEntity, object> >[] { x => x.SiteID }
            };

            TestEntity.Create(new TestEntity {
                SiteID = 1, Title = "Foo"
            });
            var documentInstance = new TestEntity {
                SiteID = 1, Title = "Foo"
            };
            var context = DocumentValidationContext <TestEntity> .Create(documentInstance, SaveType.Any);

            // Act.
            var results = validator.Validate("Foo", context).ToList();

            // Assert.
            Assert.That(results, Has.Count.EqualTo(1));
        }