-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathSetOctopusReleaseStatusTests.cs
145 lines (131 loc) · 5.38 KB
/
SetOctopusReleaseStatusTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using NUnit.Framework;
using Octoposh.Cmdlets;
using Octoposh.Model;
using Octopus.Client;
using Octopus.Client.Model;
namespace Octoposh.Tests
{
[TestFixture]
public class SetOctopusReleaseStatusTests
{
//If sure this mess of initialization variables can be much simpler. But its 10pm and it works :). We accept PRs!
private static readonly string CmdletName = "Set-OctopusReleaseStatus";
private static readonly Type CmdletType = typeof(SetOctopusReleaseStatus);
private static readonly string ProjectName = "ReleaseTests_Project1";
private static readonly ProjectResource Project = TestUtilities.Repository.Projects.FindByName(ProjectName);
private static readonly string ReleaseVersion = "1.0.0";
private static readonly ReleaseResource Release = TestUtilities.Repository.Projects.GetReleaseByVersion(Project, ReleaseVersion);
private static readonly string Blocked = "Blocked";
private static readonly string Unblocked = "Unblocked";
private static readonly string Description = $"Raising defect from unit tests on [{DateTime.Now}]";
private const string ByReleaseResource = "ByReleaseResource";
private const string ByProjectAndVersion = "ByProjectAndVersion";
[Test]
public void BlockAndUnblockReleaseByProjectNameAndVersion()
{
var latestDefect = TestUtilities.Repository.Defects.GetDefects(Release).Items.LastOrDefault();
//If the release doesn't have any defects or the last one has the status "Resolved" (meaning its not blocked) => Block first and unblock later.
if (latestDefect == null || latestDefect.Status.ToString() == "Resolved")
{
Assert.IsTrue(InvokeCmdlet(Release, Blocked, ByProjectAndVersion));
Assert.IsTrue(InvokeCmdlet(Release, Unblocked, ByProjectAndVersion));
}
//else Unblock first, and block later.
else
{
Assert.IsTrue(InvokeCmdlet(Release, Unblocked, ByProjectAndVersion));
Assert.IsTrue(InvokeCmdlet(Release, Blocked, ByProjectAndVersion));
}
}
[Test]
public void BlockAndUnblockReleaseByReleaseResource()
{
var latestDefect = TestUtilities.Repository.Defects.GetDefects(Release).Items.LastOrDefault();
//If the release doesn't have any defects or the last one has the status "Resolved" (meaning its not blocked) => Block first and unblock later.
if (latestDefect == null || latestDefect.Status.ToString() == "Resolved")
{
Assert.IsTrue(InvokeCmdlet(Release, Blocked, ByReleaseResource));
Assert.IsTrue(InvokeCmdlet(Release, Unblocked, ByReleaseResource));
}
//else Unblock first, and block later.
else
{
Assert.IsTrue(InvokeCmdlet(Release, Unblocked, ByReleaseResource));
Assert.IsTrue(InvokeCmdlet(Release, Blocked, ByReleaseResource));
}
}
private bool InvokeCmdlet(ReleaseResource release,string status,string parameterSet)
{
List<CmdletParameter> parameters;
if (parameterSet == ByProjectAndVersion)
{
parameters = new List<CmdletParameter>
{
new CmdletParameter()
{
Name = "ProjectName",
SingleValue = ProjectName
},
new CmdletParameter()
{
Name = "ReleaseVersion",
SingleValue = ReleaseVersion
},
new CmdletParameter()
{
Name = "Status",
SingleValue = status
}
,
new CmdletParameter()
{
Name = "Description",
SingleValue = Description
}
};
}
else
{
parameters = new List<CmdletParameter>
{
new CmdletParameter()
{
Name = "Resource",
Resource = Release
},
new CmdletParameter()
{
Name = "Status",
SingleValue = status
}
,
new CmdletParameter()
{
Name = "Description",
SingleValue = Description
}
};
}
var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters);
try
{
powershell.Invoke<List<OutputOctopusTeam>>();
}
catch (Exception e)
{
Console.WriteLine(e);
return false;
}
return true;
}
}
}