/// <summary> /// Writes the project info. /// </summary> /// <param name="xw">The xw.</param> /// <param name="forReadability">if set to <c>true</c> [for readability].</param> protected override void WriteProjectInfo(XmlWriter xw, bool forReadability) { string key; if (BuildProperties.TryGetValue("AssemblyOriginatorKeyFile", out key)) { KeyFile = key; } if (BuildProperties.TryGetValue("AssemblyKeyContainerName", out key)) { KeyContainer = key; } base.WriteProjectInfo(xw, forReadability); }
IEnumerable <string> GetParameters(string name, IEnumerable <string> furtherItems, string alternateValue) { Dictionary <string, string> used = new Dictionary <string, string>(); if (furtherItems != null) { foreach (string i in furtherItems) { if (!used.ContainsKey(i)) { used.Add(i, i); yield return(i); } } } string propertyValue; if (!BuildProperties.TryGetValue("TurtleMSBuild_" + name, out propertyValue)) { propertyValue = alternateValue; } if (propertyValue != null) { foreach (string i in propertyValue.Split(';')) { if (string.IsNullOrEmpty(i)) { continue; } if (!used.ContainsKey(i)) { used.Add(i, i); yield return(i); } } } }
public string GetProperty(string key) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (BuildProperties == null) { return(null); } string r; if (BuildProperties.TryGetValue(key, out r)) { return(r); } else { return(null); } }
/*/// <summary> * /// Compose additional items of the test setup method. * /// </summary> * /// <param name="setUpMethod">The test setup method.</param> * /// <param name="testObjectMemberField">The member field of the object under test.</param> * /// <param name="testObjectName">The name of the object under test.</param> * /// <returns> * /// The initialization expression of the object under test. * /// Is <c>null</c>, when none is created. * /// </returns> * protected override CodeObjectCreateExpression ComposeTestSetupMethod( * CodeMemberMethod setUpMethod, * CodeMemberField testObjectMemberField, * string testObjectName) * { * //var invokeExpression = new CodeMethodInvokeExpression( * // new CodeTypeReferenceExpression("Assert"), * // "AreEqual", * //new CodePrimitiveExpression("expected") * // new CodeFieldReferenceExpression(testObjectMemberField, "bla") * // , new CodeVariableReferenceExpression("actual")); * var fieldRef1 = * new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), testObjectMemberField.Name); * * var testObjectMemberFieldCreate = new CodeObjectCreateExpression(testObjectName, new CodeExpression[] { }); * var as1 = new CodeAssignStatement(fieldRef1, testObjectMemberFieldCreate); * * // Creates a statement using a code expression. * // var expressionStatement = new CodeExpressionStatement(fieldRef1); * setUpMethod.Statements.Add(as1); * return testObjectMemberFieldCreate; * }*/ /// <summary> /// Compose additional items of the test setup method. /// </summary> /// <param name="context">The setup context.</param> /// <param name="testObjectMemberField">The member field of the object under test.</param> /// <param name="testObjectName">The name of the object under test.</param> /// <returns> /// The list of assigned mock objects. /// </returns> protected virtual IEnumerable <CodeAssignStatement> ComposeTestSetupMockery( ISetupAndTearDownCreationContext context, CodeMemberField testObjectMemberField, string testObjectName) { CodeTypeDeclaration testClassDeclaration = context.TestClassDeclaration; CodeMemberMethod setUpMethod = context.SetUpMethod; // Todo: only the Type is necs, the CodeTypeDeclaration is too much knowledge. var testObjectClassType = (Type)testClassDeclaration.UserData[NStubConstants.UserDataClassTypeKey]; Type[] parameters = { /*typeof(int)*/ }; // Get the constructor that takes an integer as a parameter. var flags = BindingFlags.Instance; var noPrivate = true; switch (Configuration.MethodGeneratorLevelOfDetail) { case MemberVisibility.Public: flags |= BindingFlags.Public; break; case MemberVisibility.Internal: flags |= BindingFlags.Public | BindingFlags.NonPublic; break; case MemberVisibility.Private: flags |= BindingFlags.Public | BindingFlags.NonPublic; noPrivate = false; break; default: break; } var ctor = testObjectClassType.GetConstructor(flags, Type.DefaultBinder, parameters, null); if (ctor == null) { // outputBlock.Text += // "There is no public constructor of MyClass that takes an integer as a parameter.\n"; } // else // { // outputBlock.Text += // "The public constructor of MyClass that takes an integer as a parameter is:\n"; // outputBlock.Text += ctor.ToString() + "\n"; // } var testObjectConstructors = testObjectClassType.GetConstructors(flags); bool hasInterfaceInCtorParameters = false; var ctorParameterTypes = new List <ParameterInfo>(); foreach (var constructor in testObjectConstructors) { if (noPrivate && constructor.IsPrivate) { continue; } var ctorParameters = constructor.GetParameters(); foreach (var para in ctorParameters) { if (para.ParameterType.IsInterface /*&& !para.ParameterType.IsGenericType*/) { hasInterfaceInCtorParameters = true; ctorParameterTypes.Add(para); } } } if (!hasInterfaceInCtorParameters) { return(new CodeAssignStatement[0]); } var testObjectInitializerPosition = setUpMethod.Statements.Count - 1; var mockRepositoryMemberField = this.AddMockRepository( testClassDeclaration, setUpMethod, "mocks"); var mockAssignments = new List <CodeAssignStatement>(); foreach (var paraInfo in ctorParameterTypes) { IBuilderData data; ConstructorAssignment ctorassignment = null; if (paraInfo.ParameterType.IsGenericType) { var genericTypeDefinition = paraInfo.ParameterType.GetGenericTypeDefinition(); if (typeof(IEnumerable <>).IsAssignableFrom(genericTypeDefinition)) { // try to find the testobjcomposer assigned sub items for IEnumerable<T>'s. BuildProperties.TryGetValue( "CreateAssignments." + testObjectClassType.FullName + "." + paraInfo.Name, paraInfo.Name + "Item", out data); if (data != null) { ctorassignment = data.GetData() as ConstructorAssignment; } if (testObjectClassType.Name == "DefaultMemberBuilderFactory") { } if (ctorassignment != null) { this.CreateMocker( testClassDeclaration, setUpMethod, mockRepositoryMemberField, mockAssignments, ctorassignment.MemberType, paraInfo.Name, ctorassignment); } continue; } } BuildProperties.TryGetValue( "Assignments." + testObjectClassType.FullName, paraInfo.Name, out data); if (data != null) { ctorassignment = data.GetData() as ConstructorAssignment; } this.CreateMocker( testClassDeclaration, setUpMethod, mockRepositoryMemberField, mockAssignments, paraInfo.ParameterType, paraInfo.Name, ctorassignment); } // reorder the testObject initializer to the bottom of the SetUp method. // var removedTypedec = setUpMethod.Statements[testObjectInitializerPosition]; // setUpMethod.Statements.RemoveAt(testObjectInitializerPosition); // setUpMethod.Statements.Add(removedTypedec); return(mockAssignments); }
private SortedFileList <ExternalProject> CreateExternalProjectsList() { SortedFileList <ExternalProject> externalProjects = new SortedFileList <ExternalProject>(); using (StreamReader sr = File.OpenText(ProjectFile)) { string line; while (null != (line = sr.ReadLine())) { if (line.StartsWith("Project(")) { IList <string> words = Tokenizer.GetCommandlineWords(line); if (words.Count < 5 || words[1] != "=") { continue; } Guid projectType = new Guid(words[0].Substring(8).TrimEnd(')').Trim('\"')); string projectName = FilterWord(words[2]); string projectFile = QQnPath.Combine(ProjectPath, FilterWord(words[3])); Guid projectGuid = new Guid(FilterWord(words[4])); if (projectType != solutionItem && File.Exists(projectFile)) { if (QQnPath.ExtensionEquals(projectFile, ".vcproj")) { externalProjects.Add(projectFile, new VCBuildProject(projectGuid, projectFile, projectName, Parameters)); } } } } } if (BuildProperties == null) { Refresh(); } // The property CurrentSolutionConfigurationContents contains the 'real' configuration of external projects string configData; if (BuildProperties.TryGetValue("CurrentSolutionConfigurationContents", out configData)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(configData); foreach (ExternalProject ep in externalProjects) { XmlNode node = doc.SelectSingleNode("//ProjectConfiguration[@Project='" + ep.ProjectGuid.ToString("B").ToUpperInvariant() + "']"); if (node != null) { ep.AddBuildConfiguration(node.InnerText); } } } return(externalProjects); }