flat-mouse-20634
03/22/2020, 4:03 AMtall-librarian-49374
03/22/2020, 10:09 AMflat-mouse-20634
03/24/2020, 9:07 AMDeployment.TestAsync
to return all the resources without a need from me to do mocking so I ended up with having this little helper to return resources:
public static async Task<ImmutableArray<Resource>> TestAsync<TStack>(
TestOptions options = null)
where TStack : Stack, new()
{
var mock = new Mock<IMocks>();
mock.Setup(m => m.NewResourceAsync(It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<ImmutableDictionary<string, object>>(), It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync((string resource, string name, ImmutableDictionary<string, object> inputs, string provider,
string id) => (name + "-test", inputs));
var resources = await Deployment.TestAsync<MyStack>(mock.Object);
return resources;
}
The other one is to extract the value of Output
variables:
public static class OutputExtensions
{
public static T GetValue<T>(this Output<T> output)
{
T result=default;
output.Apply(x => result = x);
return result;
}
}
so to validate that a resource group has tags of product on it, my test looks like this
[Fact]
public async Task AllResourceGroups_Should_Have_ProductName_Tag()
{
var resources = await TestAsync<MyStack>();
var resourceGroups = resources.OfType<Pulumi.Azure.Core.ResourceGroup>();
resourceGroups.ShouldAllBe(rg =>rg.Tags.GetValue().ContainsKey("productname"));
}
tall-librarian-49374
03/24/2020, 9:25 AMflat-mouse-20634
03/24/2020, 9:30 AMTestStack
is inspired from the your TestProperty
that was part of the unit tests pull request so credit to you šPulumi.Tests
or something like that but then I check the PR and found that it is in the same package