-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathSetup.cs
45 lines (35 loc) · 1.41 KB
/
Setup.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
using System;
using System.Configuration;
using System.Linq;
using NUnit.Framework;
using Octopus.Client;
namespace Octoposh.Tests
{
[SetUpFixture]
public class Setup
{
[OneTimeSetUp]
public void SetApiKey()
{
SetApiKeyEnvVariable();
}
private static void SetApiKeyEnvVariable()
{
var octopusUrl = string.Concat("http://localhost:", ConfigurationManager.AppSettings["OctopusBindingPort"]);
var octopusAdmin = ConfigurationManager.AppSettings["OctopusAdmin"];
var octopusPassword = ConfigurationManager.AppSettings["OctopusPassword"];
var repository = new OctopusRepository(new OctopusServerEndpoint(octopusUrl));
repository.Users.SignIn(octopusAdmin, octopusPassword, true);
var user = repository.Users.GetCurrent();
var apiKeyPurpose = "API Key for Unit tests";
var existingAPIkey = repository.Users.GetApiKeys(user).FirstOrDefault(ak => ak.Purpose == apiKeyPurpose);
if (existingAPIkey != null)
{
repository.Users.RevokeApiKey(existingAPIkey);
}
var octopusApiKey = repository.Users.CreateApiKey(user, apiKeyPurpose).ApiKey;
Environment.SetEnvironmentVariable("OctopusURL", octopusUrl);
Environment.SetEnvironmentVariable("OctopusAPIKey", octopusApiKey);
}
}
}