Skip to content

Commit

Permalink
[DevCenter] Fix Dev Center Tests (#43303)
Browse files Browse the repository at this point in the history
* Update environment test to ensure environment is deleted

* Fix dev box action tests

* Update dev box tests

* Update recordings for new tests
  • Loading branch information
drielenr authored Apr 9, 2024
1 parent ac5dda1 commit 81d1b06
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 123 deletions.
2 changes: 1 addition & 1 deletion sdk/devcenter/Azure.Developer.DevCenter/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/devcenter/Azure.Developer.DevCenter",
"Tag": "net/devcenter/Azure.Developer.DevCenter_95190a8afc"
"Tag": "net/devcenter/Azure.Developer.DevCenter_6bd03c25ea"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.Json;
using System.Threading.Tasks;
using Azure.Core;
Expand Down Expand Up @@ -146,22 +144,21 @@ public async Task GetEnvironmentDefinitionsByCatalogSucceeds()
}

[Test]
public async Task CreateAndDeleteEnvironmentSucceeds()
public async Task CreateGetAndDeleteEnvironmentSucceeds()
{
await SetUpEnvironmentAsync();
await CreateEnvironmentAsync();
await GetEnvironmentAsync();
await GetEnvironmentsAsync();
await GetAllEnvironmentsAsync();
await DeleteEnvironmentAsync();
}

[Test]
public async Task GetEnvironmentSucceeds()
private async Task GetEnvironmentAsync()
{
DevCenterEnvironment environment = await GetEnvironmentAsync();

if (environment == default)
{
await SetUpEnvironmentAsync();
environment = await GetEnvironmentAsync();
}
DevCenterEnvironment environment = (await _environmentsClient.GetEnvironmentAsync(
TestEnvironment.ProjectName,
TestEnvironment.MeUserId,
EnvName)).Value;

string envName = environment.Name;
if (string.IsNullOrWhiteSpace(envName))
Expand All @@ -172,16 +169,11 @@ public async Task GetEnvironmentSucceeds()
Assert.IsTrue(EnvName.Equals(envName, StringComparison.OrdinalIgnoreCase));
}

[Test]
public async Task GetEnvironmentsSucceeds()
private async Task GetEnvironmentsAsync()
{
var environments = await GetEnvironmentsAsync();

if (!environments.Any())
{
await SetUpEnvironmentAsync();
environments = await GetEnvironmentsAsync();
}
List<DevCenterEnvironment> environments = await _environmentsClient.GetEnvironmentsAsync(
TestEnvironment.ProjectName,
TestEnvironment.MeUserId).ToEnumerableAsync();

Assert.AreEqual(1, environments.Count);

Expand All @@ -194,16 +186,10 @@ public async Task GetEnvironmentsSucceeds()
Assert.IsTrue(EnvName.Equals(envName, StringComparison.OrdinalIgnoreCase));
}

[Test]
public async Task GetAllEnvironmentsSucceeds()
private async Task GetAllEnvironmentsAsync()
{
var environments = await GetAllEnvironmentsAsync();

if (!environments.Any())
{
await SetUpEnvironmentAsync();
environments = await GetAllEnvironmentsAsync();
}
List<DevCenterEnvironment> environments = await _environmentsClient.GetAllEnvironmentsAsync(
TestEnvironment.ProjectName).ToEnumerableAsync();

Assert.AreEqual(1, environments.Count);

Expand All @@ -216,36 +202,7 @@ public async Task GetAllEnvironmentsSucceeds()
Assert.IsTrue(EnvName.Equals(envName, StringComparison.OrdinalIgnoreCase));
}

private async Task<DevCenterEnvironment> GetEnvironmentAsync()
{
try
{
return (await _environmentsClient.GetEnvironmentAsync(
TestEnvironment.ProjectName,
TestEnvironment.MeUserId,
EnvName)).Value;
}
// if environment doesn't exist Get Environment will throw an error
catch
{
return default;
}
}

private async Task<List<DevCenterEnvironment>> GetEnvironmentsAsync()
{
return await _environmentsClient.GetEnvironmentsAsync(
TestEnvironment.ProjectName,
TestEnvironment.MeUserId).ToEnumerableAsync();
}

private async Task<List<DevCenterEnvironment>> GetAllEnvironmentsAsync()
{
return await _environmentsClient.GetAllEnvironmentsAsync(
TestEnvironment.ProjectName).ToEnumerableAsync();
}

private async Task SetUpEnvironmentAsync()
private async Task CreateEnvironmentAsync()
{
var environment = new DevCenterEnvironment
(
Expand Down
Loading

0 comments on commit 81d1b06

Please sign in to comment.