IEnumerable <ValidationResult> IValidatableDocument.Validate(SaveType saveType) { var parentPropertyName = EmbeddedDocumentUtility.GetParentPropertyName <T, TEmbeddedIn>((T)this); var validationContext = DocumentValidationContext <T> .Create((T)this, Parent, parentPropertyName, saveType); return(ValidationUtility.Validate(Validators, validationContext)); }
private void ExecuteCallbacks(CallbackType callbackType) { Callbacks.ExecuteCallbacks(callbackType, (T)this); foreach (IHasCallbacks embeddedDocument in EmbeddedDocumentUtility.GetEmbeddedDocuments(this)) { embeddedDocument.ExecuteCallbacks(callbackType); } }
public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) { object result = CustomBsonClassMapSerializer.Instance.Deserialize(bsonReader, nominalType, actualType, options); if (result != null) { EmbeddedDocumentUtility.UpdateParentReferences(result); } return(result); }
public void CanGetInverseOfRelationshipForCollectionProperties() { // Arrange. var comment = new Comment(); // Act. var result = EmbeddedDocumentUtility.GetParentPropertyName <Comment, BlogPost>(comment); // Assert. Assert.That(result, Is.EqualTo("Comments")); }
public void CanGetInverseOfRelationshipForNonCollectionProperties() { // Arrange. var address = new Address(); // Act. var result = EmbeddedDocumentUtility.GetParentPropertyName <Address, Person>(address); // Assert. Assert.That(result, Is.EqualTo("Address")); }
public void CanUpdateParentReferencesInProperty() { // Arrange. var person = new Person(); var address = new Address(); // Act. person.Address = address; EmbeddedDocumentUtility.UpdateParentReferences(person); // Assert. Assert.That(address.Parent, Is.EqualTo(person)); }
public void CanUpdateParentReferencesInCollection() { // Arrange. var blogPost = new BlogPost(); var comment = new Comment(); // Act. blogPost.Comments.Add(comment); EmbeddedDocumentUtility.UpdateParentReferences(blogPost); // Assert. Assert.That(comment.Parent, Is.EqualTo(blogPost)); }
IEnumerable <ValidationResult> IValidatableDocument.Validate(SaveType saveType) { Errors.AddRange(ValidationUtility.Validate(PropertyValidators, DocumentValidationContext <T> .Create((T)this, saveType))); foreach (IValidatableDocument embeddedDocument in EmbeddedDocumentUtility.GetEmbeddedDocuments(this)) { Errors.AddRange(embeddedDocument.Validate(saveType)); } foreach (var objectValidator in ObjectValidators) { Errors.AddRange(objectValidator((T)this)); } return(Errors); }
protected override IEnumerable <ValidationResult> ValidateInternal(object value, DocumentValidationContext <T> validationContext) { // Get all documents embeddded in the same collection in the parent document. var parentCollection = EmbeddedDocumentUtility.GetEmbeddedCollection( validationContext.ParentDocument, validationContext.ParentPropertyName); // Loop through those embedded documents, excluding this one. foreach (T item in parentCollection.Where(x => x != validationContext.Document)) { // Compare the specified property against this value. if (Equals(_propertyExpression(item), (TProperty)value)) { yield return(new ValidationResult(validationContext.DisplayName + " must be unique")); yield break; } } }
protected virtual void OnAfterFind() { EmbeddedDocumentUtility.UpdateParentReferences(this); ResetChanges(); ExecuteObservers(CallbackType.AfterFind, o => o.AfterFind((T)this)); }
protected virtual bool OnBeforeSave() { EmbeddedDocumentUtility.UpdateParentReferences(this); return(ExecuteCancellableObservers(CallbackType.BeforeSave, o => o.BeforeSave((T)this))); }
public void UpdateAssociations() { EmbeddedDocumentUtility.UpdateParentReferences(this); }