Skip to content

Commit

Permalink
Fixing bug #353
Browse files Browse the repository at this point in the history
  • Loading branch information
DarqueWarrior committed Sep 23, 2020
1 parent ace10a6 commit 5fd92ac
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Source/Classes/Provider/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,21 @@ public Build(PSObject obj, string projectName, IPowerShell powerShell) :
this.LastChangedBy = new User(obj.GetValue<PSObject>("lastChangedBy"));

this.Project = new Project(obj.GetValue<PSObject>("project"), powerShell);
this.Queue = new Queue(obj.GetValue<PSObject>("queue"), projectName, powerShell);

// When you try to use Get-VSTeamBuild on the build that is running sometimes
// the queue is not present yet
if (obj.HasValue("queue"))
{
this.Queue = new Queue(obj.GetValue<PSObject>("queue"), projectName, powerShell);
}

this.BuildDefinition = new BuildDefinition(obj.GetValue<PSObject>("definition"), projectName, powerShell);
}

[ExcludeFromCodeCoverage]
public Build(PSObject obj, string projectName) :
this(obj, projectName, new PowerShellWrapper(RunspaceMode.CurrentRunspace))
{
{
}
}
}
128 changes: 128 additions & 0 deletions Tests/SampleFiles/Get-VSTeamBuild-Id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"_links": {
"self": {
"href": "https://dev.azure.com/LoECDA/00000000-0000-0000-0000-000000000000/_apis/build/Builds/2272"
},
"web": {
"href": "https://dev.azure.com/LoECDA/00000000-0000-0000-0000-000000000000/_build/results?buildId=2272"
},
"sourceVersionDisplayUri": {
"href": "https://dev.azure.com/LoECDA/00000000-0000-0000-0000-000000000000/_apis/build/builds/2272/sources"
},
"timeline": {
"href": "https://dev.azure.com/LoECDA/00000000-0000-0000-0000-000000000000/_apis/build/builds/2272/Timeline"
},
"badge": {
"href": "https://dev.azure.com/LoECDA/00000000-0000-0000-0000-000000000000/_apis/build/status/65"
}
},
"properties": {},
"tags": [],
"validationResults": [],
"plans": [
{
"planId": "00000000-0000-0000-0000-000000000000"
}
],
"triggerInfo": {},
"id": 2272,
"buildNumber": "2272",
"status": "inProgress",
"queueTime": "2020-09-23T15:44:09.2919724Z",
"startTime": "2020-09-23T15:44:45.2487227Z",
"url": "https://dev.azure.com/LoECDA/00000000-0000-0000-0000-000000000000/_apis/build/Builds/2272",
"definition": {
"drafts": [],
"id": 65,
"name": "Team Module-CI (1)",
"url": "https://dev.azure.com/LoECDA/00000000-0000-0000-0000-000000000000/_apis/build/Definitions/65?revision=7",
"uri": "vstfs:///Build/Definition/65",
"path": "\\",
"type": "build",
"queueStatus": "enabled",
"revision": 7,
"project": {
"id": "00000000-0000-0000-0000-000000000000",
"name": "Team Module",
"description": "This is a PowerShell module named Team for using TFS and VSTS from PowerShell. The code is Open source in GitHub.",
"url": "https://dev.azure.com/LoECDA/_apis/projects/00000000-0000-0000-0000-000000000000",
"state": "wellFormed",
"revision": 357,
"visibility": "public",
"lastUpdateTime": "2019-06-18T13:57:23.407Z"
}
},
"project": {
"id": "00000000-0000-0000-0000-000000000000",
"name": "Team Module",
"description": "This is a PowerShell module named Team for using TFS and VSTS from PowerShell. The code is Open source in GitHub.",
"url": "https://dev.azure.com/LoECDA/_apis/projects/00000000-0000-0000-0000-000000000000",
"state": "wellFormed",
"revision": 357,
"visibility": "public",
"lastUpdateTime": "2019-06-18T13:57:23.407Z"
},
"uri": "vstfs:///Build/Build/2272",
"sourceBranch": "refs/heads/master",
"sourceVersion": "ace10a62d0f840e0c63ffc088983d3a20d4463d5",
"priority": "normal",
"reason": "manual",
"requestedFor": {
"displayName": "Donovan Brown",
"url": "https://spsprodcus1.vssps.visualstudio.com/00000000-0000-0000-0000-000000000000/_apis/Identities/00000000-0000-0000-0000-000000000000",
"_links": {
"avatar": {
"href": "https://dev.azure.com/LoECDA/_apis/GraphProfile/MemberAvatars/aad.redacted"
}
},
"id": "00000000-0000-0000-0000-000000000000",
"uniqueName": "[email protected]",
"imageUrl": "https://dev.azure.com/LoECDA/_apis/GraphProfile/MemberAvatars/aad.redacted",
"descriptor": "aad.redacted"
},
"requestedBy": {
"displayName": "Donovan Brown",
"url": "https://spsprodcus1.vssps.visualstudio.com/00000000-0000-0000-0000-000000000000/_apis/Identities/00000000-0000-0000-0000-000000000000",
"_links": {
"avatar": {
"href": "https://dev.azure.com/LoECDA/_apis/GraphProfile/MemberAvatars/aad.redacted"
}
},
"id": "00000000-0000-0000-0000-000000000000",
"uniqueName": "[email protected]",
"imageUrl": "https://dev.azure.com/LoECDA/_apis/GraphProfile/MemberAvatars/aad.redacted",
"descriptor": "aad.redacted"
},
"lastChangedDate": "2020-09-23T15:44:45.26Z",
"lastChangedBy": {
"displayName": "Microsoft.VisualStudio.Services.TFS",
"url": "https://spsprodcus1.vssps.visualstudio.com/00000000-0000-0000-0000-000000000000/_apis/Identities/00000000-0000-0000-0000-000000000000",
"_links": {
"avatar": {
"href": "https://dev.azure.com/LoECDA/_apis/GraphProfile/MemberAvatars/s2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA"
}
},
"id": "00000000-0000-0000-0000-000000000000",
"uniqueName": "00000000-0000-0000-0000-000000000000@00000000-0000-0000-0000-000000000000",
"imageUrl": "https://dev.azure.com/LoECDA/_apis/GraphProfile/MemberAvatars/s2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA",
"descriptor": "s2s.MDAwMDAwMDItMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDJjODk1OTA4LTA0ZTAtNDk1Mi04OWZkLTU0YjAwNDZkNjI4OA"
},
"parameters": "{\"system.debug\":\"false\"}",
"orchestrationPlan": {
"planId": "00000000-0000-0000-0000-000000000000"
},
"logs": {
"id": 0,
"type": "Container",
"url": "https://dev.azure.com/LoECDA/00000000-0000-0000-0000-000000000000/_apis/build/builds/2272/logs"
},
"repository": {
"id": "MethodsAndPractices/vsteam",
"type": "GitHub",
"clean": null,
"checkoutSubmodules": false
},
"keepForever": false,
"retainedByRelease": false,
"triggeredByBuild": null
}
47 changes: 47 additions & 0 deletions Tests/library/Provider/BuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,52 @@ public void Build_Constructor()
Assert.AreEqual("Donovan Brown", actual.RequestedFor.DisplayName, "RequestedFor.DisplayName");
Assert.AreEqual("Microsoft.VisualStudio.Services.ReleaseManagement", actual.LastChangedBy.ToString(), "LastChangedBy.ToString()");
}


/// <summary>
/// This sample file is one you would get if you called Get-VSTeamBuild
/// by ID on a agent for the build that is running. In this case the
/// Queue would not be set yet.
/// </summary>
[TestMethod]
public void Build_Constructor_ById()
{
// Arrange
var ps = BaseTests.PrepPowerShell();
var obj = BaseTests.LoadJson("Get-VSTeamBuild-Id.json", false);

// Act
var actual = new Build(obj[0], "Project Name", ps);

// Assert
Assert.IsNull(actual.Queue, "Queue");
Assert.AreEqual(null, actual.QueueId, "QueueId");
Assert.AreEqual(null, actual.QueueName, "QueueName");

Assert.AreEqual(null, actual.Result, "Result");
Assert.IsNotNull(actual.RequestedBy, "RequestedBy");
Assert.IsNotNull(actual.RequestedFor, "RequestedFor");
Assert.AreEqual("inProgress", actual.Status, "Status");
Assert.IsNotNull(actual.LastChangedBy, "LastChangedBy");
Assert.AreEqual("2272", actual.BuildNumber, "BuildNumber");
Assert.AreEqual("GitHub", actual.RepositoryType, "RepositoryType");
Assert.AreEqual("Team Module-CI (1)", actual.DefinitionName, "DefinitionName");
Assert.AreEqual("Donovan Brown", actual.RequestedByUser, "RequestedByUser");
Assert.AreEqual("Donovan Brown", actual.RequestedForUser, "RequestedForUser");
Assert.AreEqual("9/23/2020 3:44:45 PM", actual.StartTime.ToString(), "startTime");
Assert.AreEqual("Microsoft.VisualStudio.Services.TFS", actual.LastChangedByUser, "LastChangedByUser");

Assert.IsNotNull(actual.BuildDefinition, "BuildDefinition");
Assert.AreEqual(65, actual.BuildDefinition.Id, "BuildDefinition.Id");
Assert.AreEqual("Team Module-CI (1)", actual.BuildDefinition.Name, "BuildDefinition.Name");

Assert.IsNotNull(actual.Project, "Project");
Assert.AreEqual("Team Module", actual.Project.Name, "Project.Name");
Assert.AreEqual("00000000-0000-0000-0000-000000000000", actual.Project.Id, "Project.Id");

Assert.AreEqual("[email protected]", actual.RequestedBy.UniqueName, "RequestedBy.UniqueName");
Assert.AreEqual("Donovan Brown", actual.RequestedFor.DisplayName, "RequestedFor.DisplayName");
Assert.AreEqual("Microsoft.VisualStudio.Services.TFS", actual.LastChangedBy.ToString(), "LastChangedBy.ToString()");
}
}
}

0 comments on commit 5fd92ac

Please sign in to comment.