Switched C# mocked unit tests to AzureNative.
MODIFY
testing-unit-cs-mocks/Testing.cs
testing-unit-cs-mocks/Testing.cs
// Copyright 2016-2020, Pulumi Corporation
+using System.Collections.Generic;
using System.Collections.Immutable;
-using System.Linq;
using System.Threading.Tasks;
using Pulumi;
using Pulumi.Testing;
@@ -21,7 +21,7 @@ namespace UnitTesting
if (!args.Inputs.ContainsKey("name"))
outputs.Add("name", args.Name);
- if (args.Type == "azure:storage/blob:Blob")
+ if (args.Type == "azure-native:storage:Blob")
{
// Assets can't directly go through the engine.
// We don't need them in the test, so blank out the property for now.
@@ -29,11 +29,14 @@ namespace UnitTesting
}
// For a Storage Account...
- if (args.Type == "azure:storage/account:Account")
+ if (args.Type == "azure-native:storage:StorageAccount")
{
// ... set its web endpoint property.
// Normally this would be calculated by Azure, so we have to mock it.
- outputs.Add("primaryWebEndpoint", $"https://{args.Name}.web.core.windows.net");
+ outputs.Add("primaryEndpoints", new Dictionary<string, string>
+ {
+ { "web", $"https://{args.Name}.web.core.windows.net" },
+ }.ToImmutableDictionary());
}
// Default the resource ID to `{name}_id`.

MODIFY
testing-unit-cs-mocks/UnitTesting.csproj
testing-unit-cs-mocks/UnitTesting.csproj
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
- <PackageReference Include="Pulumi.Azure" Version="4.*" />
+ <PackageReference Include="Pulumi.AzureNative" Version="1.*" />
</ItemGroup>
<ItemGroup>

MODIFY
testing-unit-cs-mocks/WebsiteStack.cs
testing-unit-cs-mocks/WebsiteStack.cs
using System.IO;
using Pulumi;
-using Pulumi.Azure.Core;
-using Storage = Pulumi.Azure.Storage;
+using Pulumi.AzureNative.Resources;
+using Pulumi.AzureNative.Storage;
+using Pulumi.AzureNative.Storage.Inputs;
public class WebsiteStack : Stack
{
@@ -14,31 +15,39 @@ public class WebsiteStack : Stack
Tags = { { "Environment", "production" } }
});
- var storageAccount = new Storage.Account("wwwprodsa", new Storage.AccountArgs
+ var storageAccount = new StorageAccount("wwwprodsa", new StorageAccountArgs
{
ResourceGroupName = resourceGroup.Name,
- AccountTier = "Standard",
- AccountReplicationType = "LRS",
- StaticWebsite = new Storage.Inputs.AccountStaticWebsiteArgs
+ Sku = new SkuArgs
{
- IndexDocument = "index.html"
- }
+ Name = SkuName.Standard_LRS
+ },
+ Kind = Kind.BlobStorage
+ });
+
+ // Enable static website support
+ var staticWebsite = new StorageAccountStaticWebsite("staticWebsite", new StorageAccountStaticWebsiteArgs
+ {
+ AccountName = storageAccount.Name,
+ ResourceGroupName = resourceGroup.Name,
+ IndexDocument = "index.html",
});
var files = Directory.GetFiles("wwwroot");
foreach (var file in files)
{
- var blob = new Storage.Blob(file, new Storage.BlobArgs
+ var blob = new Blob(file, new BlobArgs
{
ContentType = "application/html",
Source = new FileAsset(file),
- StorageAccountName = storageAccount.Name,
- StorageContainerName = "$web",
- Type = "Block"
+ ResourceGroupName = resourceGroup.Name,
+ AccountName = storageAccount.Name,
+ ContainerName = staticWebsite.ContainerName,
});
}
- this.Endpoint = storageAccount.PrimaryWebEndpoint;
+ this.Endpoint = storageAccount.PrimaryEndpoints.Apply(
+ primaryEndpoints => primaryEndpoints.Web);
}
[Output] public Output<string> Endpoint { get; set; }

MODIFY
testing-unit-cs-mocks/WebsiteStackTests.cs
testing-unit-cs-mocks/WebsiteStackTests.cs
@@ -6,9 +6,9 @@ using System.Threading.Tasks;
using FluentAssertions;
using NUnit.Framework;
using Pulumi;
-using Pulumi.Azure.Core;
using Pulumi.Testing;
-using Storage = Pulumi.Azure.Storage;
+using Pulumi.AzureNative.Resources;
+using Pulumi.AzureNative.Storage;
namespace UnitTesting
{
@@ -16,11 +16,11 @@ namespace UnitTesting
/// Unit testing examples.
/// </summary>
[TestFixture]
- public class WebserverStackTests
+ public class WebsiteStackTests
{
- private static Task<ImmutableArray<Resource>> TestAsync()
+ private static Task<ImmutableArray<Pulumi.Resource>> TestAsync()
{
- return Deployment.TestAsync<WebsiteStack>(new Mocks(), new TestOptions {IsPreview = false});
+ return Pulumi.Deployment.TestAsync<WebsiteStack>(new Mocks(), new TestOptions {IsPreview = false});
}
[Test]
@@ -44,21 +44,19 @@ namespace UnitTesting
}
[Test]
- public async Task StorageAccountBelongsToResourceGroup()
+ public async Task StorageAccountExists()
{
var resources = await TestAsync();
- var storageAccount = resources.OfType<Storage.Account>().SingleOrDefault();
+ var storageAccounts = resources.OfType<StorageAccount>();
+ var storageAccount = storageAccounts.SingleOrDefault();
storageAccount.Should().NotBeNull("Storage account not found");
-
- var resourceGroupName = await storageAccount.ResourceGroupName.GetValueAsync();
- resourceGroupName.Should().Be("www-prod-rg");
}
[Test]
public async Task UploadsTwoFiles()
{
var resources = await TestAsync();
- var files = resources.OfType<Storage.Blob>().ToList();
+ var files = resources.OfType<Blob>().ToList();
files.Count.Should().Be(2, "Should have uploaded files from `wwwroot`");
}

Switched C# mocked unit tests to AzureNative. (#1035)

Co-authored-by: pierre khoury <pierrekhouryb@outlook.com>