コード例 #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);
     }
 }
コード例 #3
0
        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);
 }
コード例 #9
0
        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);
 }