示例#1
0
        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));
        }
示例#2
0
 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);
        }
示例#4
0
        public void CanGetInverseOfRelationshipForCollectionProperties()
        {
            // Arrange.
            var comment = new Comment();

            // Act.
            var result = EmbeddedDocumentUtility.GetParentPropertyName <Comment, BlogPost>(comment);

            // Assert.
            Assert.That(result, Is.EqualTo("Comments"));
        }
示例#5
0
        public void CanGetInverseOfRelationshipForNonCollectionProperties()
        {
            // Arrange.
            var address = new Address();

            // Act.
            var result = EmbeddedDocumentUtility.GetParentPropertyName <Address, Person>(address);

            // Assert.
            Assert.That(result, Is.EqualTo("Address"));
        }
示例#6
0
        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));
        }
示例#7
0
        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));
        }
示例#8
0
 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;
                }
            }
        }
示例#10
0
 protected virtual void OnAfterFind()
 {
     EmbeddedDocumentUtility.UpdateParentReferences(this);
     ResetChanges();
     ExecuteObservers(CallbackType.AfterFind, o => o.AfterFind((T)this));
 }
示例#11
0
 protected virtual bool OnBeforeSave()
 {
     EmbeddedDocumentUtility.UpdateParentReferences(this);
     return(ExecuteCancellableObservers(CallbackType.BeforeSave, o => o.BeforeSave((T)this)));
 }
示例#12
0
 public void UpdateAssociations()
 {
     EmbeddedDocumentUtility.UpdateParentReferences(this);
 }