Example #1
0
        /// <summary>
        /// Maps the <see cref="ReflectionWrappers.PropertyWrapper"/> to a <see cref="IRelationshipDef"/>.
        /// </summary>
        /// <returns></returns>
        public IRelationshipDef MapOneToOne()
        {
            if (!MustBeMapped())
            {
                return(null);
            }
            CheckReverseRelationshipValid();

            var relatedClassType            = PropertyWrapper.RelatedClassType.UnderlyingType;
            DeleteParentAction deleteAction = GetDeleteAction();

            var relDef = new SingleRelationshipDef(this.PropertyWrapper.Name, relatedClassType
                                                   , new RelKeyDef(), true, deleteAction)
            {
                OwningBOHasForeignKey   = this.OwningBoHasForeignKey,
                ReverseRelationshipName = this.ReverseRelationshipName
            };

            SetRelationshipType(relDef);
            relDef.SetAsOneToOne();
            IRelPropDef relPropDef = this.CreateRelPropDef();

            relDef.RelKeyDef.Add(relPropDef);
            return(relDef);
        }
/*//TODO brett 24 Jan 2011: Implement these tests for MultipRelDefTester
 *
 #region ShouldHavePropertyCorrectlyMapped
 *
 *      [Test]
 *      public void Test_ShouldHavePropertyMapped_WhenPropWithNoSetter_GetterNotCorrectlyMapped_ShouldAssertFalse()
 *      {
 *          BORegistry.DataAccessor = new DataAccessorInMemory();
 *          //---------------Set up test pack-------------------
 *          const string relName = "SingleRelNoSetterGetterIncorrect";
 *          CreateClassDefs<FakeBOWithNothing, FakeBoWithSingleRel>();
 *          var classDef = ClassDef.Get<FakeBoWithSingleRel>();
 *          var boTester = CreateTester<FakeBoWithSingleRel>();
 *          var singleRelDefTester = boTester.GetSingleRelationshipTester(rel => rel.SingleRelNoSetterGetterIncorrect);
 *          //---------------Assert Precondition----------------
 *          classDef.ShouldHaveMultipleRelationshipDef(relName);
 *          classDef.ShouldHavePropertyInfo(relName);
 *          //---------------Execute Test ----------------------
 *          try
 *          {
 *              singleRelDefTester.ShouldHavePropertyMapped();
 *              Assert.Fail("Expected to throw an AssertionException");
 *          }
 *              //---------------Test Result -----------------------
 *          catch (AssertionException ex)
 *          {
 *              string expected = string.Format("The Getter for the Property '{0}' for class '{1}'",
 *                                              relName, "FakeBoWithSingleRel");
 *              StringAssert.Contains(expected, ex.Message);
 *              StringAssert.Contains("is not mapped to the correct BOProp. Check the Property in your code", ex.Message);
 *          }
 *      }
 *      [Test]
 *      public void Test_ShouldHavePropertyMapped_WhenPropSetterMappedToInvalidName_ShouldAssertFalse()
 *      {
 *          BORegistry.DataAccessor = new DataAccessorInMemory();
 *          //---------------Set up test pack-------------------
 *          const string relName = "SingleRelSetterMappedToNonExistentRelDef";
 *          CreateClassDefs<FakeBOWithNothing, FakeBoWithSingleRel>();
 *          var classDef = ClassDef.Get<FakeBoWithSingleRel>();
 *          var boTester = CreateTester<FakeBoWithSingleRel>();
 *          var singleRelDefTester = boTester.GetSingleRelationshipTester(rel => rel.SingleRelSetterMappedToNonExistentRelDef);
 *          //---------------Assert Precondition----------------
 *          classDef.ShouldHaveMultipleRelationshipDef(relName);
 *          classDef.ShouldHavePropertyInfo(relName);
 *          //---------------Execute Test ----------------------
 *          try
 *          {
 *              singleRelDefTester.ShouldHavePropertyMapped();
 *              Assert.Fail("Expected to throw an AssertionException ");
 *          }
 *              //---------------Test Result -----------------------
 *          catch (AssertionException ex)
 *          {
 *              string expected = string.Format("The Setter for the Property '{0}' for class '{1}'",
 *                                              relName, "FakeBoWithSingleRel");
 *              StringAssert.Contains(expected, ex.Message);
 *              StringAssert.Contains("Setting the Property via reflection failed", ex.Message);
 *          }
 *      }
 *
 *      private static BOTester<T> CreateTester<T>() where T : class, IBusinessObject
 *      {
 *          return new BOTester<T>(); ;
 *      }
 *      protected static void CreateClassDefs<T1, T2>()
 *      {
 *          CustomTypeSource typeSource = new CustomTypeSource();
 *          typeSource.Add<T1>();
 *          typeSource.Add<T2>();
 *          AllClassesAutoMapper.ClassDefCol = ClassDef.ClassDefs;
 *          new AllClassesAutoMapper(typeSource).Map();
 *      }
 *
 #endregion
 *
 *
 #region RelationshipType
 *
 *      [Test]
 *      public void Test_ShouldHaveRelationshipType_Aggregation_WhenIs_ShouldAssertTrue()
 *      {
 *          //---------------Set up test pack-------------------
 *          var singleRelationshipDef = CreateMultipleRelationshipDef();
 *          singleRelationshipDef.RelationshipType = RelationshipType.Aggregation;
 *          MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
 *          //---------------Assert Precondition----------------
 *          Assert.AreEqual(RelationshipType.Aggregation, singleRelationshipDef.RelationshipType);
 *          //---------------Execute Test ----------------------
 *          tester.ShouldHaveRelationshipType(RelationshipType.Aggregation);
 *          //---------------Test Result -----------------------
 *          Assert.IsTrue(true, "If it has got here then passed");
 *      }
 *
 *      [Test]
 *      public void Test_ShouldHaveRelationshipType_Aggregation_WhenIsNot_ShouldAssertFalse()
 *      {
 *          //---------------Set up test pack-------------------
 *          var singleRelationshipDef = CreateMultipleRelationshipDef();
 *          singleRelationshipDef.RelationshipType = RelationshipType.Association;
 *          const RelationshipType expectedRelationshipType = RelationshipType.Aggregation;
 *          MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
 *          //---------------Assert Precondition----------------
 *          Assert.AreNotEqual(expectedRelationshipType, singleRelationshipDef.RelationshipType);
 *          //---------------Test Result -----------------------
 *          try
 *          {
 *              tester.ShouldHaveRelationshipType(expectedRelationshipType);
 *              Assert.Fail("Expected to throw an AssertionException");
 *          }
 *              //---------------Test Result -----------------------
 *          catch (AssertionException ex)
 *          {
 *              string expected = string.Format(
 *                  "should have a RelationshipType '{0}' but is '{1}'",
 *                  expectedRelationshipType, singleRelationshipDef.RelationshipType);
 *              StringAssert.Contains(expected, ex.Message);
 *          }
 *      }
 *
 *      [Test]
 *      public void Test_ShouldHaveRelationshipType_Association_WhenIsNot_ShouldAssertFalse()
 *      {
 *          //---------------Set up test pack-------------------
 *          var singleRelationshipDef = CreateMultipleRelationshipDef();
 *          singleRelationshipDef.RelationshipType = RelationshipType.Aggregation;
 *          const RelationshipType expectedRelationshipType = RelationshipType.Association;
 *          MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
 *          //---------------Assert Precondition----------------
 *          Assert.AreNotEqual(expectedRelationshipType, singleRelationshipDef.RelationshipType);
 *          //---------------Test Result -----------------------
 *          try
 *          {
 *              tester.ShouldHaveRelationshipType(expectedRelationshipType);
 *              Assert.Fail("Expected to throw an AssertionException");
 *          }
 *              //---------------Test Result -----------------------
 *          catch (AssertionException ex)
 *          {
 *              string expected = string.Format(
 *                  "should have a RelationshipType '{0}' but is '{1}'", expectedRelationshipType, singleRelationshipDef.RelationshipType);
 *              StringAssert.Contains(expected, ex.Message);
 *          }
 *      }
 *
 #endregion*/


/*
 *
 *
 *
 *
 *
 *
 *
 */

/* The ReadWriteRule needs to be implemented in some manner for SingleRelationships
 *
 *      [Test]
 *      public void Test_ShouldHaveReadWriteRule_ReadOnly_WhenIs_ShouldAssertTrue()
 *      {
 *          //---------------Set up test pack-------------------
 *          IRelationshipDef singleRelationshipDef = CreateMultipleRelationshipDef();
 *          singleRelationshipDef.ReadWriteRule = PropReadWriteRule.ReadOnly;
 *          MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
 *          //---------------Assert Precondition----------------
 *          Assert.AreEqual(PropReadWriteRule.ReadOnly, singleRelationshipDef.ReadWriteRule);
 *          //---------------Execute Test ----------------------
 *          tester.ShouldHaveReadWriteRule(PropReadWriteRule.ReadOnly);
 *          //---------------Test Result -----------------------
 *          Assert.IsTrue(true, "If it has got here then passed");
 *      }
 *
 *      [Test]
 *      public void Test_ShouldHaveReadWriteRule_ReadOnly_WhenIsNot_ShouldAssertFalse()
 *      {
 *          //---------------Set up test pack-------------------
 *          IRelationshipDef singleRelationshipDef = CreateMultipleRelationshipDef();
 *          singleRelationshipDef.ReadWriteRule = PropReadWriteRule.WriteNew;
 *          const PropReadWriteRule expectedReadWriteRule = PropReadWriteRule.ReadOnly;
 *          MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
 *          //---------------Assert Precondition----------------
 *          Assert.AreNotEqual(expectedReadWriteRule, singleRelationshipDef.ReadWriteRule);
 *          //---------------Test Result -----------------------
 *          try
 *          {
 *              tester.ShouldHaveReadWriteRule(expectedReadWriteRule);
 *              Assert.Fail("Expected to throw an AssertionException");
 *          }
 *              //---------------Test Result -----------------------
 *          catch (AssertionException ex)
 *          {
 *              string expected = string.Format(
 *                  "The Relationship '{0}' for class '{1}' should have a ReadWriteRule '{2}' but is '{3}'", singleRelationshipDef.RelationshipName,
 *                  singleRelationshipDef.ClassName, expectedReadWriteRule, singleRelationshipDef.ReadWriteRule);
 *              StringAssert.Contains(expected, ex.Message);
 *          }
 *      }
 *      [Test]
 *      public void Test_ShouldHaveReadWriteRule_ReadWrite_WhenIsNot_ShouldAssertFalse()
 *      {
 *          //---------------Set up test pack-------------------
 *          IRelationshipDef singleRelationshipDef = CreateMultipleRelationshipDef();
 *          singleRelationshipDef.ReadWriteRule = PropReadWriteRule.ReadOnly;
 *          const PropReadWriteRule expectedReadWriteRule = PropReadWriteRule.ReadWrite;
 *          MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
 *          //---------------Assert Precondition----------------
 *          Assert.AreNotEqual(expectedReadWriteRule, singleRelationshipDef.ReadWriteRule);
 *          //---------------Test Result -----------------------
 *          try
 *          {
 *              tester.ShouldHaveReadWriteRule(expectedReadWriteRule);
 *              Assert.Fail("Expected to throw an AssertionException");
 *          }
 *              //---------------Test Result -----------------------
 *          catch (AssertionException ex)
 *          {
 *              string expected = string.Format(
 *                  "The Relationship '{0}' for class '{1}' should have a ReadWriteRule '{2}' but is '{3}'", singleRelationshipDef.RelationshipName,
 *                  singleRelationshipDef.ClassName, expectedReadWriteRule, singleRelationshipDef.ReadWriteRule);
 *              StringAssert.Contains(expected, ex.Message);
 *          }
 *      }*/

/*
 *      private static IRelationshipDef GetMultipleRelationshipDef()
 *      {
 *          string className;
 *          return GetMultipleRelationshipDef(out className);
 *      }*/

/*        private static IRelationshipDef GetMultipleRelationshipDef(out string className)
 *      {
 *          var singleRelationshipDef = GetMockMultipleRelationshipDef();
 *          singleRelationshipDef.RelationshipName = GetRandomString();
 *          className = GetRandomString();
 *          singleRelationshipDef.Stub(def => def.ClassName).Return(className);
 *          return singleRelationshipDef;
 *      }*/


        private static IRelationshipDef CreateMultipleRelationshipDef(DeleteParentAction action)
        {
            var multipleRelationshipDef = MockRepository.GenerateStub <IRelationshipDef>();

            multipleRelationshipDef.Stub(def => def.DeleteParentAction).Return(action);
            return(multipleRelationshipDef);
        }
 // ReSharper disable DoNotCallOverridableMethodsInConstructor
 /// <summary>
 /// Constructor to create a new single relationship definition
 /// </summary>
 /// <param name="relationshipName">A name for the relationship</param>
 /// <param name="relatedObjectClassType">The class type of the related object</param>
 /// <param name="relKeyDef">The related key definition</param>
 /// <param name="keepReferenceToRelatedObject">Whether to keep a
 /// reference to the related object.  Could be false for memory-
 /// intensive applications.</param>
 /// <param name="deleteParentAction"></param>
 public SingleRelationshipDef
     (string relationshipName, Type relatedObjectClassType, RelKeyDef relKeyDef,
      bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction)
     : base(relationshipName, relatedObjectClassType, relKeyDef, keepReferenceToRelatedObject, deleteParentAction
         )
 {
     OwningBOHasForeignKey = true;
 }
 /// <summary>
 /// Asserts that the Delete Action (<see cref="DeleteParentAction"/> is set correctly for the relationship.
 /// </summary>
 /// <param name="expectedDeleteAction"></param>
 public void ShouldHaveDeleteParentAction(DeleteParentAction expectedDeleteAction)
 {
     var actualDeleteAction = this.MultipleRelationshipDef.DeleteParentAction;
     var errMessage = BaseMessage 
             + string.Format("should have a DeleteParentAction '{0}' but is '{1}'"
             , expectedDeleteAction, actualDeleteAction);
     Assert.AreEqual(expectedDeleteAction, actualDeleteAction, errMessage);
 }
Example #5
0
 /// <summary>
 /// Constructor to create a new relationship definition
 /// </summary>
 /// <param name="relationshipName">A name for the relationship</param>
 /// <param name="relatedObjectClassType">The class type of the related object</param>
 /// <param name="relKeyDef">The related key definition</param>
 /// <param name="keepReferenceToRelatedObject">Whether to keep a
 /// reference to the related object.  Could be false for memory-
 /// intensive applications.</param>
 /// <param name="deleteParentAction">The required action when the parent is deleted e.g. Dereference related, delete related, prevent delete</param>
 protected RelationshipDef(string relationshipName,
                           Type relatedObjectClassType,
                           IRelKeyDef relKeyDef,
                           bool keepReferenceToRelatedObject,
                           DeleteParentAction deleteParentAction)
     : this(relationshipName, relatedObjectClassType, null, null, relKeyDef, keepReferenceToRelatedObject, deleteParentAction, InsertParentAction.InsertRelationship, RelationshipType.Association)
 {
 }
 // ReSharper disable DoNotCallOverridableMethodsInConstructor
 /// <summary>
 /// Constructor to create a new single relationship definition
 /// </summary>
 /// <param name="relationshipName">A name for the relationship</param>
 /// <param name="relatedObjectClassType">The class type of the related object</param>
 /// <param name="relKeyDef">The related key definition</param>
 /// <param name="keepReferenceToRelatedObject">Whether to keep a
 /// reference to the related object.  Could be false for memory-
 /// intensive applications.</param>
 /// <param name="deleteParentAction"></param>
 public SingleRelationshipDef
     (string relationshipName, Type relatedObjectClassType, RelKeyDef relKeyDef,
     bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction)
     : base(relationshipName, relatedObjectClassType, relKeyDef, keepReferenceToRelatedObject, deleteParentAction
            )
 {
     OwningBOHasForeignKey = true;
 }
Example #7
0
        /// <summary>
        /// Constructor to create a new relationship definition
        /// </summary>
        /// <param name="relationshipName">A name for the relationship</param>
        /// <param name="relatedObjectClassType">The class type of the related object</param>
        /// <param name="relKeyDef">The related key definition</param>
        /// <param name="keepReferenceToRelatedObject">Whether to keep a
        /// reference to the related object.  Could be false for memory-
        /// intensive applications.</param>
		/// <param name="deleteParentAction">The required action when the parent is deleted e.g. Dereference related, delete related, prevent delete</param>
        protected RelationshipDef(string relationshipName,
							   Type relatedObjectClassType,
							   IRelKeyDef relKeyDef,
                               bool keepReferenceToRelatedObject,
                               DeleteParentAction deleteParentAction)
            : this(relationshipName, relatedObjectClassType, null, null, relKeyDef, keepReferenceToRelatedObject, deleteParentAction, InsertParentAction.InsertRelationship, RelationshipType.Association)
		{

		}
        // ReSharper restore DoNotCallOverridableMethodsInConstructor

        /// <summary>
        /// Constructor to create a new single relationship definition
        /// </summary>
        /// <param name="relationshipName">A name for the relationship</param>
        /// <param name="relatedObjectAssemblyName">The assembly name of the related object</param>
        /// <param name="relatedObjectClassName">The class name of the related object</param>
        /// <param name="relKeyDef">The related key definition</param>
        /// <param name="keepReferenceToRelatedObject">Whether to keep a
        /// reference to the related object.  Could be false for memory-
        /// intensive applications.</param>
        /// <param name="deleteParentAction"></param>
        public SingleRelationshipDef
            (string relationshipName, string relatedObjectAssemblyName, string relatedObjectClassName,
            IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction)
            : this(
                relationshipName, relatedObjectAssemblyName, relatedObjectClassName, relKeyDef,
                keepReferenceToRelatedObject, deleteParentAction, InsertParentAction.InsertRelationship,
                RelationshipType.Association)
        {
        }
        /// <summary>
        /// Asserts that the Delete Action (<see cref="DeleteParentAction"/> is set correctly for the relationship.
        /// </summary>
        /// <param name="expectedDeleteAction"></param>
        public void ShouldHaveDeleteParentAction(DeleteParentAction expectedDeleteAction)
        {
            var actualDeleteAction = this.MultipleRelationshipDef.DeleteParentAction;
            var errMessage         = BaseMessage
                                     + string.Format("should have a DeleteParentAction '{0}' but is '{1}'"
                                                     , expectedDeleteAction, actualDeleteAction);

            Assert.AreEqual(expectedDeleteAction, actualDeleteAction, errMessage);
        }
        // ReSharper restore DoNotCallOverridableMethodsInConstructor

        /// <summary>
        /// Constructor to create a new single relationship definition
        /// </summary>
        /// <param name="relationshipName">A name for the relationship</param>
        /// <param name="relatedObjectAssemblyName">The assembly name of the related object</param>
        /// <param name="relatedObjectClassName">The class name of the related object</param>
        /// <param name="relKeyDef">The related key definition</param>
        /// <param name="keepReferenceToRelatedObject">Whether to keep a
        /// reference to the related object.  Could be false for memory-
        /// intensive applications.</param>
        /// <param name="deleteParentAction"></param>
        public SingleRelationshipDef
            (string relationshipName, string relatedObjectAssemblyName, string relatedObjectClassName,
             IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction)
            : this(
                relationshipName, relatedObjectAssemblyName, relatedObjectClassName, relKeyDef,
                keepReferenceToRelatedObject, deleteParentAction, InsertParentAction.InsertRelationship,
                RelationshipType.Association)
        {
        }
Example #11
0
 // ReSharper disable DoNotCallOverridableMethodsInConstructor
 ///<summary>
 /// Constructs a single Relationship
 ///</summary>
 ///<param name="relationshipName"></param>
 ///<param name="relatedObjectAssemblyName"></param>
 ///<param name="relatedObjectClassName"></param>
 ///<param name="relKeyDef"></param>
 ///<param name="keepReferenceToRelatedObject"></param>
 ///<param name="deleteParentAction"></param>
 ///<param name="insertParentAction"><see cref="InsertParentAction"/></param>
 ///<param name="relationshipType"></param>
 public SingleRelationshipDef(string relationshipName, string relatedObjectAssemblyName,
                              string relatedObjectClassName, IRelKeyDef relKeyDef,
                              bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction,
                              InsertParentAction insertParentAction, RelationshipType relationshipType)
     : base(
         relationshipName, relatedObjectAssemblyName, relatedObjectClassName, relKeyDef,
         keepReferenceToRelatedObject, deleteParentAction, insertParentAction, relationshipType)
 {
     OwningBOHasForeignKey = true;
 }
    	/// <summary>
    	/// Constructor to create a new single relationship definition
    	/// </summary>
    	/// <param name="relationshipName">A name for the relationship</param>
    	/// <param name="relatedObjectAssemblyName">The assembly name of the related object</param>
    	/// <param name="relatedObjectClassName">The class name of the related object</param>
    	/// <param name="relKeyDef">The related key definition</param>
    	/// <param name="keepReferenceToRelatedObject">Whether to keep a
        /// reference to the related object.  Could be false for memory-
        /// intensive applications.</param>
    	/// <param name="orderBy">The sql order-by clause</param>
    	/// <param name="deleteParentAction">Provides specific instructions 
    	/// with regards to deleting a parent object.  See the DeleteParentAction 
    	/// enumeration for more detail.</param>
    	public MultipleRelationshipDef(string relationshipName, string relatedObjectAssemblyName,
    	                               string relatedObjectClassName, IRelKeyDef relKeyDef,
    	                               bool keepReferenceToRelatedObject, string orderBy,
    	                               DeleteParentAction deleteParentAction)
            : base(relationshipName, relatedObjectAssemblyName, relatedObjectClassName, 
                    relKeyDef, keepReferenceToRelatedObject, deleteParentAction, 
                    InsertParentAction.InsertRelationship, RelationshipType.Association)
		{
            ArgumentValidationHelper.CheckArgumentNotNull(orderBy, "orderBy");
            OrderCriteriaString = orderBy; 
            OrderCriteria = Base.OrderCriteria.FromString(orderBy);
		}
 /// <summary>
 /// Constructor to create a new single relationship definition
 /// </summary>
 /// <param name="relationshipName">A name for the relationship</param>
 /// <param name="relatedObjectAssemblyName">The assembly name of the related object</param>
 /// <param name="relatedObjectClassName">The class name of the related object</param>
 /// <param name="relKeyDef">The related key definition</param>
 /// <param name="keepReferenceToRelatedObject">Whether to keep a
 /// reference to the related object.  Could be false for memory-
 /// intensive applications.</param>
 /// <param name="orderBy">The sql order-by clause</param>
 /// <param name="deleteParentAction">Provides specific instructions
 /// with regards to deleting a parent object.  See the DeleteParentAction
 /// enumeration for more detail.</param>
 public MultipleRelationshipDef(string relationshipName, string relatedObjectAssemblyName,
                                string relatedObjectClassName, IRelKeyDef relKeyDef,
                                bool keepReferenceToRelatedObject, string orderBy,
                                DeleteParentAction deleteParentAction)
     : base(relationshipName, relatedObjectAssemblyName, relatedObjectClassName,
            relKeyDef, keepReferenceToRelatedObject, deleteParentAction,
            InsertParentAction.InsertRelationship, RelationshipType.Association)
 {
     ArgumentValidationHelper.CheckArgumentNotNull(orderBy, "orderBy");
     OrderCriteriaString = orderBy;
     OrderCriteria       = Base.OrderCriteria.FromString(orderBy);
 }
        private void SetupDefaultValues()
        {
            _deleteAction     = DeleteParentAction.DoNothing;
            _insertAction     = InsertParentAction.InsertRelationship;
            _relationshipType = RelationshipType.Association;
            _keepReference    = true;
            _orderBy          = "";
            Type type = typeof(TRelatedType);

            _relatedObjectAssemblyName = type.Namespace;
            _relatedClassName          = type.Name;
            _relKeyDef = new RelKeyDef();
            _timeOut   = 0;
        }
Example #15
0
        /// <summary>
        /// Map the relationship including the Relationship props.
        /// </summary>
        /// <returns></returns>
        public IRelationshipDef MapOneToMany()
        {
            var propertyType = this.PropertyWrapper.PropertyType;

            if (!MustBeMapped())
            {
                return(null);
            }

            var singleReverseRelPropInfos = this.PropertyWrapper.GetSingleReverseRelPropInfos();

            if (singleReverseRelPropInfos.Count > 1)
            {
                throw new InvalidDefinitionException("The Relationship '" + this.PropertyWrapper.Name
                                                     + "' could not be automapped since there are multiple Single relationships on class '"
                                                     + this.PropertyWrapper.RelatedClassType + "' that reference the BusinessObject Class '"
                                                     + this.PropertyWrapper.DeclaringClassName + "'. Please map using ClassDef.XML or Attributes");
            }
            var relationshipAttribute = this.PropertyWrapper.GetAttribute <AutoMapOneToManyAttribute>();
            MultipleRelationshipDef relDef;

            if (propertyType.IsGenericType)
            {
                var relatedClassType = this.PropertyWrapper.RelatedClassType.UnderlyingType;
                relDef = new MultipleRelationshipDef(this.PropertyWrapper.Name, relatedClassType, new RelKeyDef(), true, "", DeleteParentAction.Prevent);
            }
            else
            {
                string className = StringUtilities.Singularize(this.PropertyWrapper.Name);
                relDef = new MultipleRelationshipDef(this.PropertyWrapper.Name, this.PropertyWrapper.AssemblyQualifiedName, className
                                                     , new RelKeyDef(), true, "", DeleteParentAction.Prevent);
            }
            if (relationshipAttribute != null)
            {
                relDef.RelationshipType = relationshipAttribute.RelationshipType;
                DeleteParentAction deleteParentAction = relationshipAttribute.DeleteParentAction;
                relDef.DeleteParentAction = deleteParentAction;
            }
            relDef.ReverseRelationshipName = GetReverseRelationshipName();

            var relPropDef = CreateRelPropDef();

            relDef.RelKeyDef.Add(relPropDef);
            return(relDef);
        }
        public void Test_ShouldHaveDeleteParentAction_DereferenceRelated_WhenIsNot_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            var singleRelationshipDef = CreateMultipleRelationshipDef(DeleteParentAction.DoNothing);

            const DeleteParentAction expectedDeleteParentAction = DeleteParentAction.DereferenceRelated;
            var tester = new MultipleRelDefTester(singleRelationshipDef);

            //---------------Assert Precondition----------------
            Assert.AreNotEqual(expectedDeleteParentAction, singleRelationshipDef.DeleteParentAction);
            //---------------Test Result -----------------------
            try
            {
                tester.ShouldHaveDeleteParentAction(expectedDeleteParentAction);
                Assert.Fail("Expected to throw an AssertionException");
            }
            //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                var expected = string.Format(
                    "should have a DeleteParentAction '{0}' but is '{1}'", expectedDeleteParentAction, singleRelationshipDef.DeleteParentAction);
                StringAssert.Contains(expected, ex.Message);
            }
        }
        /// <summary>
        /// Loads the relationship definition from the reader.  This method
        /// is called by LoadFromReader().
        /// </summary>
        protected void LoadRelationshipDef()
        {
            _relatedClassName = _reader.GetAttribute("relatedClass");
            _relatedAssemblyName = _reader.GetAttribute("relatedAssembly");
            _name = _reader.GetAttribute("name");
            _type = _reader.GetAttribute("type");
            _preventDeleteMessage = _reader.GetAttribute("preventDeleteMessage");

            string relationshipTypeString = _reader.GetAttribute("relationshipType");

            try
            {
                _relationshipType = (RelationshipType) Enum.Parse(typeof (RelationshipType), relationshipTypeString);
            }
            catch (Exception ex)
            {
                throw new InvalidXmlDefinitionException
                    (String.Format
                         ("In the definition for the relationship '{0}' on class '{1}' " + "the 'relationshipType' "
                          + "was set to an invalid value ('{2}'). The valid options are "
                          + "Association, Aggregation and Composition.", _name, _className, relationshipTypeString), ex);
            }

            if (_type == null || (_type != "single" && _type != "multiple"))
            {
                throw new InvalidXmlDefinitionException
                    ("In a 'relationship' " + "element, the 'type' attribute was not included or was given "
                     + "an invalid value.  The 'type' refers to the type of "
                     + "relationship and can be either 'single' or 'multiple'.");
            }

            _keepReferenceToRelatedObject = _reader.GetAttribute("keepReference") == "true";
            _owningBOHasForeignKey = _reader.GetAttribute("owningBOHasForeignKey") == "true";
            _reverseRelationshipName = _reader.GetAttribute("reverseRelationship");
            _typeParameter = _reader.GetAttribute("typeParameter");
            try
            {
                _timeout = Convert.ToInt32(_reader.GetAttribute("timeout"));
            }
            catch (Exception ex)
            {
                throw new InvalidXmlDefinitionException
                    ("In a 'relationship' element, " + "the 'timeout' attribute has been given "
                     + "an invalid integer value.", ex);
            }


            _orderBy = _reader.GetAttribute("orderBy");

            try
            {
                _deleteParentAction =
                    (DeleteParentAction) Enum.Parse(typeof (DeleteParentAction), _reader.GetAttribute("deleteAction"));
            }
            catch (Exception ex)
            {
                throw new InvalidXmlDefinitionException
                    ("In a 'relationship' " + "element, the 'deleteAction' attribute has been given "
                     + "an invalid value. The available options are " + "DeleteRelated, DereferenceRelated and "
                     + "Prevent.", ex);
            }
            if (_relationshipType == RelationshipType.Association)
            {
                try
                {
                    string attribute = _reader.GetAttribute("insertAction");
                    if (string.IsNullOrEmpty(attribute))
                    {
                        attribute = "InsertRelationship";
                    }
                    _insertParentAction =
                        (InsertParentAction)
                        Enum.Parse(typeof (InsertParentAction), attribute);
                }
                catch (Exception ex)
                {
                    throw new InvalidXmlDefinitionException
                        ("In a 'relationship' " + "element, the 'deleteAction' attribute has been given "
                         + "an invalid value. The available options are " + "DeleteRelated, DereferenceRelated and "
                         + "Prevent.", ex);
                }
            }
            else
            {
                _insertParentAction = InsertParentAction.InsertRelationship;
            }
        }
 /// <summary>
 /// </summary>
 public AutoMapOneToManyAttribute(string reverseRelationshipName)
     : base(reverseRelationshipName)
 {
     this.DeleteParentAction = DeleteParentAction.Prevent;
 }
Example #19
0
 private void SetDeleteRelatedAction(IRelationship relationship, DeleteParentAction deleteParentAction)
 {
     ((RelationshipDef)relationship.RelationshipDef).DeleteParentAction = deleteParentAction;
 }
Example #20
0
 /// <summary>
 /// Constructor to create a new relationship definition
 /// </summary>
 /// <param name="relationshipName">A name for the relationship</param>
 /// <param name="relatedObjectAssemblyName">The assembly that the related object is in</param>
 /// <param name="relatedObjectClassName">The class type of the related object</param>
 /// <param name="relKeyDef">The related key definition</param>
 ///<param name="keepReferenceToRelatedObject">Whether to keep a
 /// reference to the related object.  Could be false for memory-
 /// intensive applications.</param>
 ///<param name="deleteParentAction">The required action when the parent is deleted e.g. Dereference related, delete related, prevent delete</param>
 /// <param name="insertParentAction"><see cref="InsertParentAction"/></param>
 /// <param name="relationshipType"></param>
 protected RelationshipDef(string relationshipName, string relatedObjectAssemblyName, string relatedObjectClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType)
     : this(relationshipName, null, relatedObjectAssemblyName, relatedObjectClassName, relKeyDef, keepReferenceToRelatedObject, deleteParentAction, insertParentAction, relationshipType)
 {
 }
Example #21
0
        // ReSharper disable DoNotCallOverridableMethodsInConstructor
        private RelationshipDef(string relationshipName, Type relatedObjectClassType, string relatedObjectAssemblyName, string relatedObjectClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType)
        {
            ArgumentValidationHelper.CheckArgumentNotNull(relKeyDef, "relKeyDef");
            ArgumentValidationHelper.CheckStringArgumentNotEmpty(relationshipName, "relationshipName");

            if (relatedObjectClassType != null)
            {
                MyRelatedObjectClassType = relatedObjectClassType;
            }
            else
            {
                _relatedObjectAssemblyName = relatedObjectAssemblyName;
                _relatedObjectClassName    = relatedObjectClassName;
                _relatedObjectClassType    = null;
            }
            RelKeyDef                    = relKeyDef;
            RelationshipName             = relationshipName;
            KeepReferenceToRelatedObject = keepReferenceToRelatedObject;
            this.DeleteParentAction      = deleteParentAction;
            this.InsertParentAction      = insertParentAction;
            RelationshipType             = relationshipType;
        }
Example #22
0
 public void SetDeleteParentAction(DeleteParentAction deleteParentAction)
 {
     DeleteParentAction = deleteParentAction;
 }
Example #23
0
        /// <summary>
        /// Constructor to create a new relationship definition
        /// </summary>
        /// <param name="relationshipName">A name for the relationship</param>
        /// <param name="relatedObjectAssemblyName">The assembly that the related object is in</param>
        /// <param name="relatedObjectClassName">The class type of the related object</param>
        /// <param name="relKeyDef">The related key definition</param>
        ///<param name="keepReferenceToRelatedObject">Whether to keep a
        /// reference to the related object.  Could be false for memory-
        /// intensive applications.</param>
        ///<param name="deleteParentAction">The required action when the parent is deleted e.g. Dereference related, delete related, prevent delete</param>
        /// <param name="insertParentAction"><see cref="InsertParentAction"/></param>
        /// <param name="relationshipType"></param>
        protected RelationshipDef(string relationshipName, string relatedObjectAssemblyName, string relatedObjectClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType)
            : this(relationshipName, null, relatedObjectAssemblyName, relatedObjectClassName, relKeyDef, keepReferenceToRelatedObject, deleteParentAction, insertParentAction, relationshipType)
		{
		}
Example #24
0
 ///<summary>
 ///</summary>
 ///<param name="relationshipName"></param>
 ///<param name="relatedAssemblyName"></param>
 ///<param name="relatedClassName"></param>
 ///<param name="relKeyDef"></param>
 ///<param name="keepReferenceToRelatedObject"></param>
 ///<param name="orderBy"></param>
 ///<param name="deleteParentAction"></param>
 ///<param name="insertParentAction"><see cref="InsertParentAction"/></param>
 ///<param name="relationshipType"></param>
 ///<param name="timeout">The timout in milliseconds. The collection will not be automatically refreshed from the DB if the timeout has not expired</param>
 ///<returns></returns>
 public IRelationshipDef CreateMultipleRelationshipDef
     (string relationshipName, string relatedAssemblyName, string relatedClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, string orderBy, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType, int timeout)
 {
     return
         (new MultipleRelationshipDef(relationshipName, relatedAssemblyName, relatedClassName, relKeyDef,
                                      keepReferenceToRelatedObject, orderBy,
                                      deleteParentAction, insertParentAction, relationshipType, timeout));
 }
Example #25
0
        // ReSharper disable DoNotCallOverridableMethodsInConstructor
        private RelationshipDef(string relationshipName, Type relatedObjectClassType, string relatedObjectAssemblyName, string relatedObjectClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType)
		{
            ArgumentValidationHelper.CheckArgumentNotNull(relKeyDef, "relKeyDef");
            ArgumentValidationHelper.CheckStringArgumentNotEmpty(relationshipName, "relationshipName");

			if (relatedObjectClassType != null) 
				MyRelatedObjectClassType = relatedObjectClassType;
			else
			{
				_relatedObjectAssemblyName = relatedObjectAssemblyName;
				_relatedObjectClassName = relatedObjectClassName;
				_relatedObjectClassType = null;
			}
			RelKeyDef = relKeyDef;
            RelationshipName = relationshipName;
            KeepReferenceToRelatedObject = keepReferenceToRelatedObject;
            this.DeleteParentAction = deleteParentAction;
    	    this.InsertParentAction = insertParentAction;
    	    RelationshipType = relationshipType;
		}
Example #26
0
		///<summary>
		///</summary>
		///<param name="relationshipName"></param>
		///<param name="relatedAssemblyName"></param>
		///<param name="relatedClassName"></param>
		///<param name="relKeyDef"></param>
		///<param name="keepReferenceToRelatedObject"></param>
		///<param name="orderBy"></param>
		///<param name="deleteParentAction"></param>
		///<param name="insertParentAction"><see cref="InsertParentAction"/></param>
		///<param name="relationshipType"></param>
		///<param name="timeout">The timout in milliseconds. The collection will not be automatically refreshed from the DB if the timeout has not expired</param>
		///<returns></returns>
		public IRelationshipDef CreateMultipleRelationshipDef
			(string relationshipName, string relatedAssemblyName, string relatedClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, string orderBy, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType, int timeout)
		{
			return
				new MultipleRelationshipDef(relationshipName, relatedAssemblyName, relatedClassName, relKeyDef,
											keepReferenceToRelatedObject, orderBy,
											deleteParentAction, insertParentAction, relationshipType, timeout);
		}
/*//TODO brett 24 Jan 2011: Implement these tests for MultipRelDefTester
        
        #region ShouldHavePropertyCorrectlyMapped

        [Test]
        public void Test_ShouldHavePropertyMapped_WhenPropWithNoSetter_GetterNotCorrectlyMapped_ShouldAssertFalse()
        {
            BORegistry.DataAccessor = new DataAccessorInMemory();
            //---------------Set up test pack-------------------
            const string relName = "SingleRelNoSetterGetterIncorrect";
            CreateClassDefs<FakeBOWithNothing, FakeBoWithSingleRel>();
            var classDef = ClassDef.Get<FakeBoWithSingleRel>();
            var boTester = CreateTester<FakeBoWithSingleRel>();
            var singleRelDefTester = boTester.GetSingleRelationshipTester(rel => rel.SingleRelNoSetterGetterIncorrect);
            //---------------Assert Precondition----------------
            classDef.ShouldHaveMultipleRelationshipDef(relName);
            classDef.ShouldHavePropertyInfo(relName);
            //---------------Execute Test ----------------------
            try
            {
                singleRelDefTester.ShouldHavePropertyMapped();
                Assert.Fail("Expected to throw an AssertionException");
            }
                //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                string expected = string.Format("The Getter for the Property '{0}' for class '{1}'",
                                                relName, "FakeBoWithSingleRel");
                StringAssert.Contains(expected, ex.Message);
                StringAssert.Contains("is not mapped to the correct BOProp. Check the Property in your code", ex.Message);
            }
        }
        [Test]
        public void Test_ShouldHavePropertyMapped_WhenPropSetterMappedToInvalidName_ShouldAssertFalse()
        {
            BORegistry.DataAccessor = new DataAccessorInMemory();
            //---------------Set up test pack-------------------
            const string relName = "SingleRelSetterMappedToNonExistentRelDef";
            CreateClassDefs<FakeBOWithNothing, FakeBoWithSingleRel>();
            var classDef = ClassDef.Get<FakeBoWithSingleRel>();
            var boTester = CreateTester<FakeBoWithSingleRel>();
            var singleRelDefTester = boTester.GetSingleRelationshipTester(rel => rel.SingleRelSetterMappedToNonExistentRelDef);
            //---------------Assert Precondition----------------
            classDef.ShouldHaveMultipleRelationshipDef(relName);
            classDef.ShouldHavePropertyInfo(relName);
            //---------------Execute Test ----------------------
            try
            {
                singleRelDefTester.ShouldHavePropertyMapped();
                Assert.Fail("Expected to throw an AssertionException ");
            }
                //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                string expected = string.Format("The Setter for the Property '{0}' for class '{1}'",
                                                relName, "FakeBoWithSingleRel");
                StringAssert.Contains(expected, ex.Message);
                StringAssert.Contains("Setting the Property via reflection failed", ex.Message);
            }
        }

        private static BOTester<T> CreateTester<T>() where T : class, IBusinessObject
        {
            return new BOTester<T>(); ;
        }
        protected static void CreateClassDefs<T1, T2>()
        {
            CustomTypeSource typeSource = new CustomTypeSource();
            typeSource.Add<T1>();
            typeSource.Add<T2>();
            AllClassesAutoMapper.ClassDefCol = ClassDef.ClassDefs;
            new AllClassesAutoMapper(typeSource).Map();
        }

        #endregion


        #region RelationshipType

        [Test]
        public void Test_ShouldHaveRelationshipType_Aggregation_WhenIs_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            var singleRelationshipDef = CreateMultipleRelationshipDef();
            singleRelationshipDef.RelationshipType = RelationshipType.Aggregation;
            MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
            //---------------Assert Precondition----------------
            Assert.AreEqual(RelationshipType.Aggregation, singleRelationshipDef.RelationshipType);
            //---------------Execute Test ----------------------
            tester.ShouldHaveRelationshipType(RelationshipType.Aggregation);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }

        [Test]
        public void Test_ShouldHaveRelationshipType_Aggregation_WhenIsNot_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            var singleRelationshipDef = CreateMultipleRelationshipDef();
            singleRelationshipDef.RelationshipType = RelationshipType.Association;
            const RelationshipType expectedRelationshipType = RelationshipType.Aggregation;
            MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
            //---------------Assert Precondition----------------
            Assert.AreNotEqual(expectedRelationshipType, singleRelationshipDef.RelationshipType);
            //---------------Test Result -----------------------
            try
            {
                tester.ShouldHaveRelationshipType(expectedRelationshipType);
                Assert.Fail("Expected to throw an AssertionException");
            }
                //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                string expected = string.Format(
                    "should have a RelationshipType '{0}' but is '{1}'", 
                    expectedRelationshipType, singleRelationshipDef.RelationshipType);
                StringAssert.Contains(expected, ex.Message);
            }
        }

        [Test]
        public void Test_ShouldHaveRelationshipType_Association_WhenIsNot_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            var singleRelationshipDef = CreateMultipleRelationshipDef();
            singleRelationshipDef.RelationshipType = RelationshipType.Aggregation;
            const RelationshipType expectedRelationshipType = RelationshipType.Association;
            MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
            //---------------Assert Precondition----------------
            Assert.AreNotEqual(expectedRelationshipType, singleRelationshipDef.RelationshipType);
            //---------------Test Result -----------------------
            try
            {
                tester.ShouldHaveRelationshipType(expectedRelationshipType);
                Assert.Fail("Expected to throw an AssertionException");
            }
                //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                string expected = string.Format(
                    "should have a RelationshipType '{0}' but is '{1}'", expectedRelationshipType, singleRelationshipDef.RelationshipType);
                StringAssert.Contains(expected, ex.Message);
            }
        }

        #endregion*/


/*
       
        

        

        

        */

/* The ReadWriteRule needs to be implemented in some manner for SingleRelationships

        [Test]
        public void Test_ShouldHaveReadWriteRule_ReadOnly_WhenIs_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            IRelationshipDef singleRelationshipDef = CreateMultipleRelationshipDef();
            singleRelationshipDef.ReadWriteRule = PropReadWriteRule.ReadOnly;
            MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
            //---------------Assert Precondition----------------
            Assert.AreEqual(PropReadWriteRule.ReadOnly, singleRelationshipDef.ReadWriteRule);
            //---------------Execute Test ----------------------
            tester.ShouldHaveReadWriteRule(PropReadWriteRule.ReadOnly);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }

        [Test]
        public void Test_ShouldHaveReadWriteRule_ReadOnly_WhenIsNot_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            IRelationshipDef singleRelationshipDef = CreateMultipleRelationshipDef();
            singleRelationshipDef.ReadWriteRule = PropReadWriteRule.WriteNew;
            const PropReadWriteRule expectedReadWriteRule = PropReadWriteRule.ReadOnly;
            MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
            //---------------Assert Precondition----------------
            Assert.AreNotEqual(expectedReadWriteRule, singleRelationshipDef.ReadWriteRule);
            //---------------Test Result -----------------------
            try
            {
                tester.ShouldHaveReadWriteRule(expectedReadWriteRule);
                Assert.Fail("Expected to throw an AssertionException");
            }
                //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                string expected = string.Format(
                    "The Relationship '{0}' for class '{1}' should have a ReadWriteRule '{2}' but is '{3}'", singleRelationshipDef.RelationshipName,
                    singleRelationshipDef.ClassName, expectedReadWriteRule, singleRelationshipDef.ReadWriteRule);
                StringAssert.Contains(expected, ex.Message);
            }
        }
        [Test]
        public void Test_ShouldHaveReadWriteRule_ReadWrite_WhenIsNot_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            IRelationshipDef singleRelationshipDef = CreateMultipleRelationshipDef();
            singleRelationshipDef.ReadWriteRule = PropReadWriteRule.ReadOnly;
            const PropReadWriteRule expectedReadWriteRule = PropReadWriteRule.ReadWrite;
            MultipleRelDefTester tester = new MultipleRelDefTester(singleRelationshipDef);
            //---------------Assert Precondition----------------
            Assert.AreNotEqual(expectedReadWriteRule, singleRelationshipDef.ReadWriteRule);
            //---------------Test Result -----------------------
            try
            {
                tester.ShouldHaveReadWriteRule(expectedReadWriteRule);
                Assert.Fail("Expected to throw an AssertionException");
            }
                //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                string expected = string.Format(
                    "The Relationship '{0}' for class '{1}' should have a ReadWriteRule '{2}' but is '{3}'", singleRelationshipDef.RelationshipName,
                    singleRelationshipDef.ClassName, expectedReadWriteRule, singleRelationshipDef.ReadWriteRule);
                StringAssert.Contains(expected, ex.Message);
            }
        }*/

/*
        private static IRelationshipDef GetMultipleRelationshipDef()
        {
            string className;
            return GetMultipleRelationshipDef(out className);
        }*/

/*        private static IRelationshipDef GetMultipleRelationshipDef(out string className)
        {
            var singleRelationshipDef = GetMockMultipleRelationshipDef();
            singleRelationshipDef.RelationshipName = GetRandomString();
            className = GetRandomString();
            singleRelationshipDef.Stub(def => def.ClassName).Return(className);
            return singleRelationshipDef;
        }*/


        private static IRelationshipDef CreateMultipleRelationshipDef(DeleteParentAction action)
        {
            var multipleRelationshipDef = MockRepository.GenerateStub<IRelationshipDef>();
            multipleRelationshipDef.Stub(def => def.DeleteParentAction).Return(action);
            return multipleRelationshipDef;
        }
Example #28
0
 private void SetDeleteRelatedAction(IRelationship relationship, DeleteParentAction deleteParentAction)
 {
     ((RelationshipDef)relationship.RelationshipDef).DeleteParentAction = deleteParentAction;
 }
 /// <summary>
 /// </summary>
 public AutoMapOneToManyAttribute(string reverseRelationshipName, RelationshipType relationshipType, DeleteParentAction deleteParentAction) : base(reverseRelationshipName, relationshipType)
 {
     this.DeleteParentAction = deleteParentAction;
 }
Example #30
0
 /// <summary>
 /// </summary>
 public AutoMapOneToManyAttribute(string reverseRelationshipName)
     : base(reverseRelationshipName)
 {
     this.DeleteParentAction = DeleteParentAction.Prevent;
 }
Example #31
0
		///<summary>
		///</summary>
		///<param name="relationshipName"></param>
		///<param name="relatedAssemblyName"></param>
		///<param name="relatedClassName"></param>
		///<param name="relKeyDef"></param>
		///<param name="keepReferenceToRelatedObject"></param>
		///<param name="deleteParentAction"></param>
		///<param name="insertParentAction"><see cref="InsertParentAction"/></param>
		///<param name="relationshipType"></param>
		///<returns></returns>
		public IRelationshipDef CreateSingleRelationshipDef
			(string relationshipName, string relatedAssemblyName, string relatedClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType)
		{
			return
				new SingleRelationshipDef(relationshipName, relatedAssemblyName, relatedClassName, relKeyDef,
										  keepReferenceToRelatedObject, deleteParentAction, insertParentAction, relationshipType);
		}
 // ReSharper disable DoNotCallOverridableMethodsInConstructor
 ///<summary>
 /// Constructs a single Relationship
 ///</summary>
 ///<param name="relationshipName"></param>
 ///<param name="relatedObjectAssemblyName"></param>
 ///<param name="relatedObjectClassName"></param>
 ///<param name="relKeyDef"></param>
 ///<param name="keepReferenceToRelatedObject"></param>
 ///<param name="deleteParentAction"></param>
 ///<param name="insertParentAction"><see cref="InsertParentAction"/></param>
 ///<param name="relationshipType"></param>
 public SingleRelationshipDef(string relationshipName, string relatedObjectAssemblyName,
                              string relatedObjectClassName, IRelKeyDef relKeyDef,
                              bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction,
                              InsertParentAction insertParentAction, RelationshipType relationshipType)
     : base(
         relationshipName, relatedObjectAssemblyName, relatedObjectClassName, relKeyDef,
         keepReferenceToRelatedObject, deleteParentAction, insertParentAction, relationshipType)
 {
     OwningBOHasForeignKey = true;
 }
Example #33
0
 /// <summary>
 /// </summary>
 public AutoMapOneToManyAttribute(RelationshipType relationshipType) : base(relationshipType)
 {
     this.DeleteParentAction = DeleteParentAction.Prevent;
 }
 /// <summary>
 /// </summary>
 public AutoMapOneToManyAttribute(RelationshipType relationshipType) : base(relationshipType)
 {
     this.DeleteParentAction = DeleteParentAction.Prevent;
 }
Example #35
0
 /// <summary>
 /// </summary>
 public AutoMapOneToManyAttribute(string reverseRelationshipName, RelationshipType relationshipType, DeleteParentAction deleteParentAction) : base(reverseRelationshipName, relationshipType)
 {
     this.DeleteParentAction = deleteParentAction;
 }
 public void SetDeleteParentAction(DeleteParentAction deleteParentAction)
 {
     DeleteParentAction = deleteParentAction;
 }
Example #37
0
        /// <summary>
        /// Loads the relationship definition from the reader.  This method
        /// is called by LoadFromReader().
        /// </summary>
        protected void LoadRelationshipDef()
        {
            _relatedClassName    = _reader.GetAttribute("relatedClass");
            _relatedAssemblyName = _reader.GetAttribute("relatedAssembly");
            _name = _reader.GetAttribute("name");
            _type = _reader.GetAttribute("type");
            _preventDeleteMessage = _reader.GetAttribute("preventDeleteMessage");

            string relationshipTypeString = _reader.GetAttribute("relationshipType");

            try
            {
                _relationshipType = (RelationshipType)Enum.Parse(typeof(RelationshipType), relationshipTypeString);
            }
            catch (Exception ex)
            {
                throw new InvalidXmlDefinitionException
                          (String.Format
                              ("In the definition for the relationship '{0}' on class '{1}' " + "the 'relationshipType' "
                              + "was set to an invalid value ('{2}'). The valid options are "
                              + "Association, Aggregation and Composition.", _name, _className, relationshipTypeString), ex);
            }

            if (_type == null || (_type != "single" && _type != "multiple"))
            {
                throw new InvalidXmlDefinitionException
                          ("In a 'relationship' " + "element, the 'type' attribute was not included or was given "
                          + "an invalid value.  The 'type' refers to the type of "
                          + "relationship and can be either 'single' or 'multiple'.");
            }

            _keepReferenceToRelatedObject = _reader.GetAttribute("keepReference") == "true";
            _owningBOHasForeignKey        = _reader.GetAttribute("owningBOHasForeignKey") == "true";
            _reverseRelationshipName      = _reader.GetAttribute("reverseRelationship");
            _typeParameter = _reader.GetAttribute("typeParameter");
            try
            {
                _timeout = Convert.ToInt32(_reader.GetAttribute("timeout"));
            }
            catch (Exception ex)
            {
                throw new InvalidXmlDefinitionException
                          ("In a 'relationship' element, " + "the 'timeout' attribute has been given "
                          + "an invalid integer value.", ex);
            }


            _orderBy = _reader.GetAttribute("orderBy");

            try
            {
                _deleteParentAction =
                    (DeleteParentAction)Enum.Parse(typeof(DeleteParentAction), _reader.GetAttribute("deleteAction"));
            }
            catch (Exception ex)
            {
                throw new InvalidXmlDefinitionException
                          ("In a 'relationship' " + "element, the 'deleteAction' attribute has been given "
                          + "an invalid value. The available options are " + "DeleteRelated, DereferenceRelated and "
                          + "Prevent.", ex);
            }
            if (_relationshipType == RelationshipType.Association)
            {
                try
                {
                    string attribute = _reader.GetAttribute("insertAction");
                    if (string.IsNullOrEmpty(attribute))
                    {
                        attribute = "InsertRelationship";
                    }
                    _insertParentAction =
                        (InsertParentAction)
                        Enum.Parse(typeof(InsertParentAction), attribute);
                }
                catch (Exception ex)
                {
                    throw new InvalidXmlDefinitionException
                              ("In a 'relationship' " + "element, the 'deleteAction' attribute has been given "
                              + "an invalid value. The available options are " + "DeleteRelated, DereferenceRelated and "
                              + "Prevent.", ex);
                }
            }
            else
            {
                _insertParentAction = InsertParentAction.InsertRelationship;
            }
        }
 public MultipleRelationshipDefBuilder <T, TRelatedType> WithDeleteParentAction(DeleteParentAction deleteParentAction)
 {
     _deleteAction = deleteParentAction;
     return(this);
 }
Example #39
0
 ///<summary>
 ///</summary>
 ///<param name="relationshipName"></param>
 ///<param name="relatedAssemblyName"></param>
 ///<param name="relatedClassName"></param>
 ///<param name="relKeyDef"></param>
 ///<param name="keepReferenceToRelatedObject"></param>
 ///<param name="deleteParentAction"></param>
 ///<param name="insertParentAction"><see cref="InsertParentAction"/></param>
 ///<param name="relationshipType"></param>
 ///<returns></returns>
 public IRelationshipDef CreateSingleRelationshipDef
     (string relationshipName, string relatedAssemblyName, string relatedClassName, IRelKeyDef relKeyDef, bool keepReferenceToRelatedObject, DeleteParentAction deleteParentAction, InsertParentAction insertParentAction, RelationshipType relationshipType)
 {
     return
         (new SingleRelationshipDef(relationshipName, relatedAssemblyName, relatedClassName, relKeyDef,
                                    keepReferenceToRelatedObject, deleteParentAction, insertParentAction, relationshipType));
 }