public void ExecutionProperties() { Engine engine = new Engine(); engine.BinPath = "TestBinPath"; ArrayList targetsToBuild = new ArrayList(); targetsToBuild.Add("targetName"); ProjectBuildState projectContext = new ProjectBuildState(new BuildRequest(-1, null, null, (BuildPropertyGroup)null, null, -1, false, false), targetsToBuild, new BuildEventContext(0, 1, 1, 1)); TaskExecutionContext context = new TaskExecutionContext(null, null, null, projectContext, 4, EngineCallback.inProcNode, new BuildEventContext(BuildEventContext.InvalidNodeId, BuildEventContext.InvalidTargetId, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidTaskId)); Assert.IsTrue(context.BuildContext.TargetNamesToBuild.Contains("targetName"), "Expected target list to contain targetName"); Assert.AreEqual(EngineCallback.inProcNode, context.NodeIndex); Assert.IsNull(context.ParentTarget, "Expected ParentTarget to be null"); context.SetTaskOutputs(false, null, 0); Assert.IsFalse(context.TaskExecutedSuccessfully); Assert.IsNull(context.ThrownException, "Expected ThrownException to be null"); context.SetTaskOutputs(true, new Exception(), 0); Assert.IsTrue(context.TaskExecutedSuccessfully); Assert.IsNotNull(context.ThrownException, "Expected ThrownException to not be null"); }
public void TaskExecutionContextCreation() { // Create some items to instantiate a task execution context and check to make sure those values are set properly Engine engine = new Engine(); engine.BinPath = "TestBinPath"; ArrayList targetsToBuild = new ArrayList(); targetsToBuild.Add("targetName"); ProjectBuildState projectContext = new ProjectBuildState(null, targetsToBuild, new BuildEventContext(0, 1, 1, 1)); TaskExecutionContext context = new TaskExecutionContext(null, null, null, projectContext, 4, EngineCallback.inProcNode, new BuildEventContext(BuildEventContext.InvalidNodeId, BuildEventContext.InvalidTargetId, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidTaskId)); Assert.IsTrue(context.BuildContext.TargetNamesToBuild.Contains("targetName"), "Expected target list to contain targetName"); Assert.IsNull(context.ParentTarget, "ParentTarget should be null"); Assert.IsNull(context.ThrownException, "ThrownException should be null"); Assert.AreEqual(4, context.HandleId, "Node ProxyId should be 4"); }
internal EngineProxy CreateEngineProxyWithDummyTaskEngine(Engine e, Project p) { // UNDONE need a real handle Id and a real TEM pointer XmlElement taskNode = new XmlDocument().CreateElement("MockTask"); BuildRequest request = new BuildRequest(EngineCallback.invalidEngineHandle, "mockproject", null, (BuildPropertyGroup)null, null, -1, false, false); ProjectBuildState context = new ProjectBuildState(request, new ArrayList(), new BuildEventContext(0, 0, 0, 0)); int handleId = e.EngineCallback.CreateTaskContext(p, null, context, taskNode, 0, new BuildEventContext(0, 0, 0, 0)); TaskEngine taskEngine = new TaskEngine ( taskNode, null, /* host object */ p.FullFileName, p.FullFileName, e.LoggingServices, handleId, e.NodeManager.TaskExecutionModule, new BuildEventContext(0, 0, 0, 0) ); e.Scheduler.Initialize(new INodeDescription[] { null }); return(new EngineProxy(e.NodeManager.TaskExecutionModule, handleId, p.FullFileName, p.FullFileName, e.LoggingServices, new BuildEventContext(0, 0, 0, 0))); }
public void TargetInProgressStateCustomSerialization() { Engine engine = new Engine(@"c:\"); Project project = ObjectModelHelpers.CreateInMemoryProject(@" <Project DefaultTargets=`t` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <PropertyGroup> <OutputPath>bin\Debug\</OutputPath> <AssemblyName>MyAssembly</AssemblyName> <OutputType>Exe</OutputType> <Configuration>Debug</Configuration> </PropertyGroup> <ItemGroup> <Compile Include=`Class1.cs` /> <EmbeddedResource Include=`Resource1.txt` /> <EmbeddedResource Include=`Resource2.resx` /> </ItemGroup> <Target Name='t' DependsOnTargets='Build'/> <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.Targets` /> </Project> "); EngineCallback engineCallback = new EngineCallback(engine); Target build = project.Targets["Build"]; List <ProjectBuildState> waitingBuildStates = null; int handleId = 1; string projectFileName = "ProjectFileName"; string[] targetNames = new string[] { "t" }; Dictionary <string, string> dictionary = null; int requestId = 1; BuildRequest request = new BuildRequest(handleId, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false); ArrayList targetNamesToBuild = new ArrayList(); targetNamesToBuild.Add("t"); ProjectBuildState initiatingRequest = new ProjectBuildState(request, targetNamesToBuild, new BuildEventContext(1, 2, 2, 2)); initiatingRequest.AddBlockingTarget("Build"); BuildRequest [] outstandingBuildRequests = null; string projectName = "SuperTestProject"; TargetInProgessState targetInProgress1 = new TargetInProgessState( engineCallback, build, waitingBuildStates, initiatingRequest, outstandingBuildRequests, projectName ); targetInProgress1.ParentTargetsForBuildRequests = null; Assertion.AssertNull(targetInProgress1.ParentTargetsForBuildRequests); Assertion.Assert(!targetInProgress1.RequestedByHost); build = project.Targets["t"]; request = new BuildRequest(handleId, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false); request.IsExternalRequest = true; targetNamesToBuild.Add("t"); initiatingRequest = new ProjectBuildState(request, targetNamesToBuild, new BuildEventContext(1, 2, 2, 2)); outstandingBuildRequests = new BuildRequest[] { new BuildRequest(1, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false), new BuildRequest(2, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false), new BuildRequest(3, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false), new BuildRequest(4, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false) }; TargetInProgessState.TargetIdWrapper originalWrapper = new TargetInProgessState.TargetIdWrapper(); originalWrapper.id = 1; originalWrapper.name = "Wrapper"; originalWrapper.nodeId = 4; originalWrapper.projectId = 6; waitingBuildStates = new List <ProjectBuildState>(); waitingBuildStates.Add(initiatingRequest); TargetInProgessState targetInProgress3 = new TargetInProgessState( engineCallback, build, waitingBuildStates, initiatingRequest, outstandingBuildRequests, projectName ); targetInProgress3.ParentTargetsForBuildRequests = new TargetInProgessState.TargetIdWrapper[] { originalWrapper }; // Stream, writer and reader where the events will be serialized and deserialized from MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); BinaryReader reader = new BinaryReader(stream); try { stream.Position = 0; // Serialize targetInProgress3.WriteToStream(writer); // Get position of stream after write so it can be compared to the position after read long streamWriteEndPosition = stream.Position; // Deserialize and Verify stream.Position = 0; TargetInProgessState newInProgressState = new TargetInProgessState(); newInProgressState.CreateFromStream(reader); long streamReadEndPosition = stream.Position; Assert.IsTrue(string.Compare(newInProgressState.ProjectName, projectName, StringComparison.OrdinalIgnoreCase) == 0); Assert.IsTrue(string.Compare(newInProgressState.TargetId.name, "t", StringComparison.OrdinalIgnoreCase) == 0); Assert.IsNotNull(newInProgressState.ParentTargets); Assert.IsTrue(newInProgressState.OutstandingBuildRequests.Length == 4); Assert.IsNotNull(newInProgressState.ParentBuildRequests); Assert.IsNotNull(newInProgressState.ParentTargetsForBuildRequests.Length == 1); stream.Position = 0; // Serialize targetInProgress1.WriteToStream(writer); // Get position of stream after write so it can be compared to the position after read streamWriteEndPosition = stream.Position; // Deserialize and Verify stream.Position = 0; newInProgressState = new TargetInProgessState(); newInProgressState.CreateFromStream(reader); streamReadEndPosition = stream.Position; Assert.IsTrue(string.Compare(newInProgressState.ProjectName, projectName, StringComparison.OrdinalIgnoreCase) == 0); Assert.IsTrue(string.Compare(newInProgressState.TargetId.name, "Build", StringComparison.OrdinalIgnoreCase) == 0); Assert.IsNotNull(newInProgressState.ParentTargets); Assert.IsNull(newInProgressState.OutstandingBuildRequests); Assert.IsNotNull(newInProgressState.ParentBuildRequests); TargetInProgessState targetInProgress2 = new TargetInProgessState(); stream.Position = 0; // Serialize targetInProgress2.WriteToStream(writer); // Get position of stream after write so it can be compared to the position after read streamWriteEndPosition = stream.Position; // Deserialize and Verify stream.Position = 0; newInProgressState = new TargetInProgessState(); newInProgressState.CreateFromStream(reader); streamReadEndPosition = stream.Position; Assert.IsNull(newInProgressState.ProjectName); Assert.IsNull(newInProgressState.TargetId); Assert.IsNull(newInProgressState.ParentTargets); Assert.IsNull(newInProgressState.OutstandingBuildRequests); Assert.IsNull(newInProgressState.ParentBuildRequests); } finally { // Close will close the writer/reader and the underlying stream writer.Close(); reader.Close(); reader = null; stream = null; writer = null; } }