Example #1
0
 /// <summary>
 /// Handle property related stuff before type generation.
 /// </summary>
 /// <param name="typeMember">The type member.</param>
 /// <param name="builderData">The builder data.</param>
 /// <param name="propertyName">Name of the property.</param>
 protected virtual void ComputeCodeMemberProperty(
     CodeMemberMethod typeMember, IBuilderData builderData, string propertyName)
 {
     /*var propertyData = builderData as PropertyBuilderData;
      *
      * var variableDeclaration = new CodeVariableDeclarationStatement(
      *  "var",
      *  "expected",
      *  new CodePrimitiveExpression("Testing"));
      *
      * typeMember.Statements.Add(variableDeclaration);
      *
      * variableDeclaration = new ImplicitVariableDeclarationStatement(
      *  "actual", new CodePrimitiveExpression("Testing"));
      * typeMember.Statements.Add(variableDeclaration);
      *
      * // Creates a code expression for a CodeExpressionStatement to contain.
      * var invokeExpression = new CodeMethodInvokeExpression(
      *  new CodeTypeReferenceExpression("Assert"),
      *  "AreEqual",
      *  new CodeVariableReferenceExpression("expected"),
      *  new CodeVariableReferenceExpression("actual"));
      *
      * // Creates a statement using a code expression.
      * // var expressionStatement = new CodeExpressionStatement(invokeExpression);
      *
      * // A C# code generator produces the following source code for the preceeding example code:
      *
      * // Console.Write( "Example string" );
      * typeMember.Statements.Add(invokeExpression);*/
     BaseCSharpCodeGenerator.ReplaceTestInTestName(typeMember, "NormalBehavior");
 }
Example #2
0
 public void SetUp()
 {
     this.codeNamespace        = new System.CodeDom.CodeNamespace();
     this.testClassDeclaration = new System.CodeDom.CodeTypeDeclaration();
     this.typeMember           = new System.CodeDom.CodeTypeMember();
     this.buildData            = new NStub.CSharp.ObjectGeneration.BuildDataDictionary();
     this.mocks       = new MockRepository();
     this.builderData = this.mocks.StrictMock <IBuilderData>();
     this.buildData.AddDataItem("CAT", "TheKey", builderData);
     this.setUpTearDownContext = this.mocks.StrictMock <NStub.CSharp.BuildContext.ISetupAndTearDownContext>();
     this.testObject           = this.mocks.Stub <MemberBuildContextBase>(this.codeNamespace, this.testClassDeclaration, this.typeMember, this.buildData, this.setUpTearDownContext);
 }
Example #3
0
        /// <summary>
        /// Gets the value associated with the specified category and key.
        /// </summary>
        /// <param name="category">The requested category.</param>
        /// <param name="key">The key of the value to get.</param>
        /// <param name="value">When this method returns, contains the value associated with the specified
        /// key, if the key is found; otherwise, the default value for the type of the
        /// value parameter. This parameter is passed uninitialized.</param>
        /// <returns>
        ///   <c>true</c> if the this instance contains an
        /// element with the specified category and key; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException">key is <c>null</c>.</exception>
        public bool TryGetValue(string category, string key, out IBuilderData value)
        {
            IDictionary <string, IBuilderData> catLookup;
            var found = this.TryGetCategory(category, out catLookup);

            if (found)
            {
                return(catLookup.TryGetValue(key, out value));
            }

            value = null;
            return(false);
        }
Example #4
0
 public void SetUp()
 {
     logText            = string.Empty;
     this.mocks         = new MockRepository();
     this.buildData     = new BuildDataDictionary();
     this.buildDataItem = new BuilderData <string>("Whuut? ...Data?");
     this.buildData.AddDataItem("MyKey", this.buildDataItem);
     this.sbs = this.mocks.StrictMock <NStub.Core.IBuildSystem>();
     this.projectGenerator        = this.mocks.StrictMock <NStub.Core.IProjectGenerator>();
     this.createGeneratorCallback = this.mocks.StrictMock <Func <IBuildSystem, IBuildDataDictionary, ICodeGeneratorParameters, CodeNamespace, ICodeGenerator> >();
     this.logger = this.mocks.StrictMock <Action <string> >();
     // this.logger = text => { this.logText += text; };
     this.testObject = new CSharpTestProjectBuilder(this.sbs, this.buildData, this.projectGenerator, createGeneratorCallback, logger);
 }
Example #5
0
        /// <summary>
        /// Adds the specified data item to the specified category of this list.
        /// </summary>
        /// <param name="category">The category of the item.</param>
        /// <param name="key">The key of the item.</param>
        /// <param name="item">The data item to add.</param>
        /// <param name="replace">if set to <c>true</c> replaces the data if present.</param>
        /// <param name="skip">if set to <c>true</c> skip already present items.</param>
        /// <remarks>
        /// If <paramref name="replace"/> is <c>true</c>, <paramref name="skip"/> is <c>true</c>
        /// and the <paramref name="item"/> is already present, then the add operation is skipped.
        /// if <paramref name="skip"/> is <c>false</c> an exception is thrown.
        /// </remarks>
        public void AddDataItem(string category, string key, IBuilderData item, bool replace, bool skip)
        {
            IDictionary <string, IBuilderData> catLookup;
            var found = this.TryGetCategory(category, out catLookup);

            if (!found)
            {
                catLookup = new Dictionary <string, IBuilderData>();
                this.data.Add(category, catLookup);
                isDirty = true;
            }

            if (!replace)
            {
                // Todo: this changes the behavior .. already present items are skipped. reflect this in the unit test.
                if (skip && catLookup.ContainsKey(key))
                {
                    return;
                }
                catLookup.Add(key, item);
                isDirty = true;
            }
            else
            {
                if (catLookup.ContainsKey(key))
                {
                    if (catLookup[key] != item)
                    {
                        isDirty = true;
                    }
                    catLookup[key] = item;
                }
                else
                {
                    catLookup.Add(key, item);
                    isDirty = true;
                }
            }
        }
Example #6
0
        public void PropertyItemIndexerThrows()
        {
            // Moo.FirstOne -> item1; General.InGeneral -> item1; NotInGeneral.X-Key -> item2; General.ReallyCool -> item3
            // [1+G2] item1 = { Enabled = true };
            // [   3] item2 = { Id = new Guid("2764B5BE-6E56-4694-B1A1-5C105420CB7F") };
            // [  G4] item3 = { Enabled = true, Id = new Guid("0AE4E28A-9B78-43bf-ABD2-9F7CB5F3833B") };
            AddDefaultTestItems();

            IBuilderData expected = null;
            IBuilderData actual   = null;

            Assert.Throws <KeyNotFoundException>(() => actual = testObject["Moo"]["XXX-Tripple-XXX"]);
            Assert.AreEqual(expected, actual);

            Assert.Throws <KeyNotFoundException>(() => actual = testObject["General"]["XXInGeneralXX"]);
            Assert.AreEqual(expected, actual);

            Assert.Throws <NullReferenceException>(() => actual = testObject["XXXGeneral"]["X-Key"]);
            Assert.AreEqual(expected, actual);

            Assert.Throws <KeyNotFoundException>(() => actual = testObject.General["What.The..."]);
            Assert.AreEqual(expected, actual);
        }
Example #7
0
        /// <summary>
        /// Gets the value associated with the specified category and key.
        /// </summary>
        /// <param name="category">The requested category.</param>
        /// <param name="key">The key of the value to get.</param>
        /// <param name="value">When this method returns, contains the value associated with the specified
        /// key, if the key is found; otherwise, the default value for the type of the
        /// value parameter. This parameter is passed uninitialized.</param>
        /// <returns>
        ///   <c>true</c> if the this instance contains an
        /// element with the specified category and key; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException">key is <c>null</c>.</exception>
        public bool TryGetValue(string category, string key, out IBuilderData value)
        {
            IDictionary<string, IBuilderData> catLookup;
            var found = this.TryGetCategory(category, out catLookup);
            if (found)
            {
                return catLookup.TryGetValue(key, out value);
            }

            value = null;
            return false;
        }
Example #8
0
 /// <summary>
 /// Gets the value out of the general data set associated with the specified key.
 /// </summary>
 /// <param name="key">The key of the value to get.</param>
 /// <param name="value">When this method returns, contains the value associated with the specified
 /// key, if the key is found; otherwise, the default value for the type of the
 /// value parameter. This parameter is passed uninitialized.</param>
 /// <returns><c>true</c> if the this instance contains an
 /// element with the specified key; otherwise, <c>false</c>.</returns>
 /// <exception cref="ArgumentNullException">key is <c>null</c>.</exception>
 public bool TryGetValue(string key, out IBuilderData value)
 {
     return this.generalData.TryGetValue(key, out value);
 }
Example #9
0
        /// <summary>
        /// Adds the specified data item to the specified category of this list.
        /// </summary>
        /// <param name="category">The category of the item.</param>
        /// <param name="key">The key of the item.</param>
        /// <param name="item">The data item to add.</param>
        /// <param name="replace">if set to <c>true</c> replaces the data if present.</param>
        /// <param name="skip">if set to <c>true</c> skip already present items.</param>
        /// <remarks>
        /// If <paramref name="replace"/> is <c>true</c>, <paramref name="skip"/> is <c>true</c> 
        /// and the <paramref name="item"/> is already present, then the add operation is skipped.
        /// if <paramref name="skip"/> is <c>false</c> an exception is thrown.
        /// </remarks>
        public void AddDataItem(string category, string key, IBuilderData item, bool replace, bool skip)
        {
            IDictionary<string, IBuilderData> catLookup;
            var found = this.TryGetCategory(category, out catLookup);
            if (!found)
            {
                catLookup = new Dictionary<string, IBuilderData>();
                this.data.Add(category, catLookup);
                isDirty = true;
            }

            if (!replace)
            {
                // Todo: this changes the behavior .. already present items are skipped. reflect this in the unit test.
                if (skip && catLookup.ContainsKey(key))
                    return;
                catLookup.Add(key, item);
                isDirty = true;
            }
            else
            {
                if (catLookup.ContainsKey(key))
                {
                    if (catLookup[key] != item)
                    {
                        isDirty = true;
                    }
                    catLookup[key] = item;
                }
                else
                {
                    catLookup.Add(key, item);
                    isDirty = true;
                }
            }
        }
Example #10
0
 /// <summary>
 /// Adds the specified data item to the specified category of this list.
 /// </summary>
 /// <param name="category">The category of the item.</param>
 /// <param name="key">The key of the item.</param>
 /// <param name="item">The data item to add.</param>
 /// <param name="replace">if set to <c>true</c> replaces the data if present.</param>
 /// <remarks>If the <paramref name="item"/> is already present, then the add operation throws an exception.</remarks>
 public void AddDataItem(string category, string key, IBuilderData item, bool replace)
 {
     AddDataItem(category, key, item, replace, false);
 }
Example #11
0
 /// <summary>
 /// Adds the specified data item to the specified category of this list.
 /// </summary>
 /// <param name="category">The category of the item.</param>
 /// <param name="key">The key of the item.</param>
 /// <param name="item">The data item to add.</param>
 public void AddDataItem(string category, string key, IBuilderData item)
 {
     this.AddDataItem(category, key, item, false);
 }
Example #12
0
        /// <summary>
        /// Handle property related stuff before type generation.
        /// </summary>
        /// <param name="typeMember">The type member.</param>
        /// <param name="builderData">The builder data.</param>
        /// <param name="propertyName">Name of the property.</param>
        protected virtual void ComputeCodeMemberProperty(
            CodeMemberMethod typeMember, IBuilderData builderData, string propertyName)
        {
            /*var propertyData = builderData as PropertyBuilderData;

            var variableDeclaration = new CodeVariableDeclarationStatement(
                "var",
                "expected",
                new CodePrimitiveExpression("Testing"));

            typeMember.Statements.Add(variableDeclaration);

            variableDeclaration = new ImplicitVariableDeclarationStatement(
                "actual", new CodePrimitiveExpression("Testing"));
            typeMember.Statements.Add(variableDeclaration);

            // Creates a code expression for a CodeExpressionStatement to contain.
            var invokeExpression = new CodeMethodInvokeExpression(
                new CodeTypeReferenceExpression("Assert"),
                "AreEqual",
                new CodeVariableReferenceExpression("expected"),
                new CodeVariableReferenceExpression("actual"));

            // Creates a statement using a code expression.
            // var expressionStatement = new CodeExpressionStatement(invokeExpression);

            // A C# code generator produces the following source code for the preceeding example code:

            // Console.Write( "Example string" );
            typeMember.Statements.Add(invokeExpression);*/
            BaseCSharpCodeGenerator.ReplaceTestInTestName(typeMember, "NormalBehavior");
        }
Example #13
0
 /// <summary>
 /// Adds the specified data item to the "General" topic of this list.
 /// </summary>
 /// <param name="key">The key of the item.</param>
 /// <param name="item">The data item to add.</param>
 /// <param name="replace">if set to <c>true</c> replaces the data if present.</param>
 public void AddDataItem(string key, IBuilderData item, bool replace)
 {
     this.AddDataItem(GeneralCategory, key, item, replace);
 }
Example #14
0
 /// <summary>
 /// Gets the value out of the general data set associated with the specified key.
 /// </summary>
 /// <param name="key">The key of the value to get.</param>
 /// <param name="value">When this method returns, contains the value associated with the specified
 /// key, if the key is found; otherwise, the default value for the type of the
 /// value parameter. This parameter is passed uninitialized.</param>
 /// <returns><c>true</c> if the this instance contains an
 /// element with the specified key; otherwise, <c>false</c>.</returns>
 /// <exception cref="ArgumentNullException">key is <c>null</c>.</exception>
 public bool TryGetValue(string key, out IBuilderData value)
 {
     return(this.generalData.TryGetValue(key, out value));
 }
Example #15
0
 /// <summary>
 /// Adds the specified data item to the specified category of this list.
 /// </summary>
 /// <param name="category">The category of the item.</param>
 /// <param name="key">The key of the item.</param>
 /// <param name="item">The data item to add.</param>
 /// <param name="replace">if set to <c>true</c> replaces the data if present.</param>
 /// <remarks>If the <paramref name="item"/> is already present, then the add operation throws an exception.</remarks>
 public void AddDataItem(string category, string key, IBuilderData item, bool replace)
 {
     AddDataItem(category, key, item, replace, false);
 }
Example #16
0
 /// <summary>
 /// Adds the specified data item to the specified category of this list.
 /// </summary>
 /// <param name="category">The category of the item.</param>
 /// <param name="key">The key of the item.</param>
 /// <param name="item">The data item to add.</param>
 public void AddDataItem(string category, string key, IBuilderData item)
 {
     this.AddDataItem(category, key, item, false);
 }
 public void SetUp()
 {
     this.codeNamespace = new System.CodeDom.CodeNamespace();
     this.testClassDeclaration = new System.CodeDom.CodeTypeDeclaration();
     this.typeMember = new System.CodeDom.CodeTypeMember();
     this.buildData = new NStub.CSharp.ObjectGeneration.BuildDataDictionary();
     this.mocks = new MockRepository();
     this.builderData = this.mocks.StrictMock<IBuilderData>();
     this.buildData.AddDataItem("CAT", "TheKey", builderData);
     this.setUpTearDownContext = this.mocks.StrictMock<NStub.CSharp.BuildContext.ISetupAndTearDownContext>();
     this.testObject = this.mocks.Stub<MemberBuildContextBase>(this.codeNamespace, this.testClassDeclaration, this.typeMember, this.buildData, this.setUpTearDownContext);
 }
Example #18
0
        /// <summary>
        /// Handle property related stuff before type generation.
        /// </summary>
        /// <param name="context">The context. Todo: remove it with specialized parameters after development.</param>
        /// <param name="typeMember">The type member.</param>
        /// <param name="builderData">The builder data.</param>
        /// <param name="testObjectName">Name of the test object member field.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <exception cref="NotImplementedException">The context of the builder does not supply a valid 
        /// <see cref="ISetupAndTearDownCreationContext"/>.</exception>
        /// <exception cref="NotImplementedException">The context of the builder does not supply a valid 
        /// <see cref="TestObjectComposer"/>.</exception>
        protected virtual void ComputeCodeMemberProperty(
            IMemberBuildContext context,
            CodeMemberMethod typeMember,
            IBuilderData builderData,
            string testObjectName,
            string propertyName)
        {
            var propertyData = builderData as PropertyBuilderData;

            if (propertyData == null)
            {
                return;
            }

            var setAccessor = propertyData.SetAccessor;
            var getAccessor = propertyData.GetAccessor;

            if (getAccessor == null)
            {
                return;
            }

            if (setAccessor == null)
            {
                // create the actual and expected var's here.
                // actualRef
                // expectedRef
            }

            var propName = propertyData.PropertyName;

            // devel: how to create a string initializer from possible constructor setups of the 'SetUp' method.
            var co = context.SetUpTearDownContext as ISetupAndTearDownCreationContext;
            if (co == null)
            {
                throw new NotImplementedException("The context of the builder does not supply a valid ISetupAndTearDownCreationContext.");
            }

            // Todo: put these used methods into the interfaces of TestObjectComposer and maybe modify
            // ISetupAndTearDownContext that it provides the co.TestObjectCreator. ... or fix all this in the
            // pre-build?!!
            var creator = co.TestObjectCreator as TestObjectComposer;
            if (creator == null)
            {
                throw new NotImplementedException("The context of the builder does not supply a valid TestObjectBuilder.");
            }

            ConstructorAssignment ctorAssignment;
            var found = creator.TryFindConstructorAssignment(propName, out ctorAssignment, false);

            CodeExpression ctorAssignmentRight = CodeMethodComposer.CreateExpressionByType(getAccessor.ReturnType, propertyData.PropertyName);
            // CodeExpression ctorAssignmentRight = new CodePrimitiveExpression("Insert expected object here");
            var assertionKind = "AreEqual";
            if (found)
            {
                // use the value of the ctor initializer.
                //ctorAssignmentRight = ctorAssignment.AssignStatement.Right;
                // use the field reference itself.
                ctorAssignmentRight = ctorAssignment.AssignStatement.Left;
                assertionKind = "AreSame";
            }

            typeMember.Statements.Add(new CodeSnippetStatement(string.Empty));
            typeMember.Statements.Add(new CodeCommentStatement("Test read access of '" + propName + "' Property."));

            var expectedAsign = new CodeVariableDeclarationStatement(
                "var",
                "expected",
                ctorAssignmentRight);
            typeMember.Statements.Add(expectedAsign);

            var testObjRef = new CodeTypeReferenceExpression(testObjectName);
            var testPropRef = new CodePropertyReferenceExpression(testObjRef, propName);
            var actualAsign = new CodeVariableDeclarationStatement("var", "actual", testPropRef);
            typeMember.Statements.Add(actualAsign);

            var assertExpr = new CodeMethodInvokeExpression(
                new CodeTypeReferenceExpression("Assert"),
                assertionKind,
                new CodeVariableReferenceExpression("expected"),
                new CodeVariableReferenceExpression("actual"));
            typeMember.Statements.Add(assertExpr);
        }
 public void SetUp()
 {
     logText = string.Empty;
     this.mocks = new MockRepository();
     this.buildData = new BuildDataDictionary();
     this.buildDataItem = new BuilderData<string>("Whuut? ...Data?");
     this.buildData.AddDataItem("MyKey", this.buildDataItem);
     this.sbs = this.mocks.StrictMock<NStub.Core.IBuildSystem>();
     this.projectGenerator = this.mocks.StrictMock<NStub.Core.IProjectGenerator>();
     this.createGeneratorCallback = this.mocks.StrictMock<Func<IBuildSystem, IBuildDataDictionary, ICodeGeneratorParameters, CodeNamespace, ICodeGenerator>>();
     this.logger = this.mocks.StrictMock<Action<string>>();
     // this.logger = text => { this.logText += text; };
     this.testObject = new CSharpTestProjectBuilder(this.sbs, this.buildData, this.projectGenerator, createGeneratorCallback, logger);
 }
Example #20
0
        /*/// <summary>
         * /// Gets the number of parameters with standard arguments. ( Currently all but interfaces ).
         * /// </summary>
         * public int CountOfStandardTypes
         * {
         *  get
         *  {
         *      return this.parameters.Count(e => !e.ParameterType.IsInterface);
         *  }
         * }*/

        /*/// <summary>
         * /// Gets a value indicating whether this instance has parameters of a interface type stored.
         * /// </summary>
         * /// <value>
         * /// <c>true</c> if this instance has interfaces in the parameter types; otherwise, <c>false</c>.
         * /// </value>
         * public bool HasInterfaces { get; private set; }*/

        /*/// <summary>
         * /// Gets the parameters where the parameter-type isn't an interface.
         * /// </summary>
         * public IEnumerable<ParameterInfo> StandardTypes
         * {
         *  get
         *  {
         *      return this.parameters.Where(e => !e.ParameterType.IsInterface);
         *  }
         * }*/

        /// <summary>
        /// Adds the specified data item to the "General" topic of this list.
        /// </summary>
        /// <param name="key">The key of the item.</param>
        /// <param name="item">The data item to add.</param>
        public void AddDataItem(string key, IBuilderData item)
        {
            this.generalData.Add(key, item);
            isDirty = true;
        }
Example #21
0
        /// <summary>
        /// Handle property related stuff before type generation.
        /// </summary>
        /// <param name="typeMember">The type member.</param>
        /// <param name="builderData">The builder data.</param>
        /// <param name="testObjectName">Name of the test object member field.</param>
        /// <param name="propertyName">Name of the property.</param>
        protected virtual void ComputeCodeMemberProperty(
            CodeMemberMethod typeMember,
            IBuilderData builderData,
            string testObjectName,
            string propertyName)
        {
            var propertyData = builderData as PropertyBuilderData;

            if (propertyData == null)
            {
                return;
            }

            var setAccessor = propertyData.SetAccessor;
            var getAccessor = propertyData.GetAccessor;

            if (setAccessor == null)
            {
                return;
            }

            if (getAccessor == null)
            {
                // create the actual and expected var's here.
                // actualRef
                // expectedRef
            }

            if (setAccessor.Name.Contains("set_OutputDirectory"))
            {
                // create the actual and expected var's here.
                // actualRef
                // expectedRef
            }

            var propName = setAccessor.Name.Replace("set_", string.Empty);

            typeMember.Statements.Add(new CodeSnippetStatement(string.Empty));
            typeMember.Statements.Add(new CodeCommentStatement("Test write access of '" + propName + "' Property."));

            var expectedRef   = new CodeVariableReferenceExpression("expected");
            var expectedAsign = new CodeAssignStatement(
                expectedRef,
                new CodePrimitiveExpression("Insert setter object here"));

            typeMember.Statements.Add(expectedAsign);

            var actualRef     = new CodeVariableReferenceExpression("actual");
            var testObjRef    = new CodeTypeReferenceExpression(testObjectName);
            var testPropRef   = new CodePropertyReferenceExpression(testObjRef, propName);
            var invokeSetProp = new CodeAssignStatement(testPropRef, expectedRef);

            typeMember.Statements.Add(invokeSetProp);

            var invoke = new CodeAssignStatement(actualRef, testPropRef);

            typeMember.Statements.Add(invoke);

            var assertionKind = "AreEqual";
            var parameters    = setAccessor.GetParameters();

            if (parameters.Length > 0)
            {
                if (parameters[0].ParameterType.IsPrimitive)
                {
                }
                else if (parameters[0].ParameterType == typeof(string))
                {
                }
                else if (typeof(ValueType).IsAssignableFrom(parameters[0].ParameterType))
                {
                }
                else
                {
                    assertionKind = "AreSame";
                }
            }

            var assertExpr = new CodeMethodInvokeExpression(
                new CodeTypeReferenceExpression("Assert"),
                assertionKind,
                new CodeVariableReferenceExpression("expected"),
                new CodeVariableReferenceExpression("actual"));

            typeMember.Statements.Add(assertExpr);
        }
Example #22
0
 /*/// <summary>
 /// Gets the number of parameters with standard arguments. ( Currently all but interfaces ).
 /// </summary>
 public int CountOfStandardTypes
 {
     get
     {
         return this.parameters.Count(e => !e.ParameterType.IsInterface);
     }
 }*/
 /*/// <summary>
 /// Gets a value indicating whether this instance has parameters of a interface type stored.
 /// </summary>
 /// <value>
 /// <c>true</c> if this instance has interfaces in the parameter types; otherwise, <c>false</c>.
 /// </value>
 public bool HasInterfaces { get; private set; }*/
 /*/// <summary>
 /// Gets the parameters where the parameter-type isn't an interface.
 /// </summary>
 public IEnumerable<ParameterInfo> StandardTypes
 {
     get
     {
         return this.parameters.Where(e => !e.ParameterType.IsInterface);
     }
 }*/
 /// <summary>
 /// Adds the specified data item to the "General" topic of this list.
 /// </summary>
 /// <param name="key">The key of the item.</param>
 /// <param name="item">The data item to add.</param>
 public void AddDataItem(string key, IBuilderData item)
 {
     this.generalData.Add(key, item);
     isDirty = true;
 }
Example #23
0
        /// <summary>
        /// Handle property related stuff before type generation.
        /// </summary>
        /// <param name="context">The context. Todo: remove it with specialized parameters after development.</param>
        /// <param name="typeMember">The type member.</param>
        /// <param name="builderData">The builder data.</param>
        /// <param name="testObjectName">Name of the test object member field.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <exception cref="NotImplementedException">The context of the builder does not supply a valid
        /// <see cref="ISetupAndTearDownCreationContext"/>.</exception>
        /// <exception cref="NotImplementedException">The context of the builder does not supply a valid
        /// <see cref="TestObjectComposer"/>.</exception>
        protected virtual void ComputeCodeMemberProperty(
            IMemberBuildContext context,
            CodeMemberMethod typeMember,
            IBuilderData builderData,
            string testObjectName,
            string propertyName)
        {
            var propertyData = builderData as PropertyBuilderData;

            if (propertyData == null)
            {
                return;
            }

            var setAccessor = propertyData.SetAccessor;
            var getAccessor = propertyData.GetAccessor;

            if (getAccessor == null)
            {
                return;
            }

            if (setAccessor == null)
            {
                // create the actual and expected var's here.
                // actualRef
                // expectedRef
            }

            var propName = propertyData.PropertyName;

            // devel: how to create a string initializer from possible constructor setups of the 'SetUp' method.
            var co = context.SetUpTearDownContext as ISetupAndTearDownCreationContext;

            if (co == null)
            {
                throw new NotImplementedException("The context of the builder does not supply a valid ISetupAndTearDownCreationContext.");
            }

            // Todo: put these used methods into the interfaces of TestObjectComposer and maybe modify
            // ISetupAndTearDownContext that it provides the co.TestObjectCreator. ... or fix all this in the
            // pre-build?!!
            var creator = co.TestObjectCreator as TestObjectComposer;

            if (creator == null)
            {
                throw new NotImplementedException("The context of the builder does not supply a valid TestObjectBuilder.");
            }

            ConstructorAssignment ctorAssignment;
            var found = creator.TryFindConstructorAssignment(propName, out ctorAssignment, false);


            CodeExpression ctorAssignmentRight = CodeMethodComposer.CreateExpressionByType(getAccessor.ReturnType, propertyData.PropertyName);
            // CodeExpression ctorAssignmentRight = new CodePrimitiveExpression("Insert expected object here");
            var assertionKind = "AreEqual";

            if (found)
            {
                // use the value of the ctor initializer.
                //ctorAssignmentRight = ctorAssignment.AssignStatement.Right;
                // use the field reference itself.
                ctorAssignmentRight = ctorAssignment.AssignStatement.Left;
                assertionKind       = "AreSame";
            }

            typeMember.Statements.Add(new CodeSnippetStatement(string.Empty));
            typeMember.Statements.Add(new CodeCommentStatement("Test read access of '" + propName + "' Property."));

            var expectedAsign = new CodeVariableDeclarationStatement(
                "var",
                "expected",
                ctorAssignmentRight);

            typeMember.Statements.Add(expectedAsign);

            var testObjRef  = new CodeTypeReferenceExpression(testObjectName);
            var testPropRef = new CodePropertyReferenceExpression(testObjRef, propName);
            var actualAsign = new CodeVariableDeclarationStatement("var", "actual", testPropRef);

            typeMember.Statements.Add(actualAsign);

            var assertExpr = new CodeMethodInvokeExpression(
                new CodeTypeReferenceExpression("Assert"),
                assertionKind,
                new CodeVariableReferenceExpression("expected"),
                new CodeVariableReferenceExpression("actual"));

            typeMember.Statements.Add(assertExpr);
        }
Example #24
0
 /// <summary>
 /// Adds the specified data item to the "General" topic of this list.
 /// </summary>
 /// <param name="key">The key of the item.</param>
 /// <param name="item">The data item to add.</param>
 /// <param name="replace">if set to <c>true</c> replaces the data if present.</param>
 public void AddDataItem(string key, IBuilderData item, bool replace)
 {
     this.AddDataItem(GeneralCategory, key, item, replace);
 }