public void FailsForInvalidData() { // Arrange. var validator = new EmbeddedDocumentUniquenessValidator <TestBook, TestAuthor, string>(x => x.Title); var testBook = new TestBook { Title = "Bar" }; var documentInstance = new TestAuthor { Books = new List <TestBook> { new TestBook { Title = "Foo" }, testBook } }; var context = DocumentValidationContext <TestBook> .Create(testBook, documentInstance, "Books", SaveType.Any); // Act. var results = validator.Validate("Foo", context).ToList(); // Assert. Assert.That(results.Count, Is.EqualTo(1)); }
private List <TestBook> GetLinkEntities() { var many1 = new ManyToMany(); var many2 = new ManyToMany(); var book1 = new TestBook(many1); var book2 = new TestBook(many2); var author1 = new TestAuthor { TestAuthorId = 1 }; many1.SetBookAuthor(book1, author1); many2.SetBookAuthor(book2, author1); author1.Many = new List <ManyToMany> { many1, many2 }; return(new List <TestBook> { book1, book2 }); }
public void SetBookAuthor(TestBook book, TestAuthor author) { BookLink = book; AuthorLink = author; }