Skip to content

Commit

Permalink
Add solution file and apply feedback from Fraser
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid-Ajaj committed Aug 17, 2022
1 parent c17b7fd commit f21879c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
28 changes: 28 additions & 0 deletions testing-unit-cs-top-level-program/PulumiUnitTesting.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infra", "infra\Infra.csproj", "{75741B98-9641-4FCA-B4EE-23896787E3C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "tests\Tests.csproj", "{0BBB322D-FEFF-493A-8BDC-13D5B0710C2D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{75741B98-9641-4FCA-B4EE-23896787E3C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75741B98-9641-4FCA-B4EE-23896787E3C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75741B98-9641-4FCA-B4EE-23896787E3C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75741B98-9641-4FCA-B4EE-23896787E3C2}.Release|Any CPU.Build.0 = Release|Any CPU
{0BBB322D-FEFF-493A-8BDC-13D5B0710C2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0BBB322D-FEFF-493A-8BDC-13D5B0710C2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BBB322D-FEFF-493A-8BDC-13D5B0710C2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BBB322D-FEFF-493A-8BDC-13D5B0710C2D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
12 changes: 3 additions & 9 deletions testing-unit-cs-top-level-program/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using Pulumi;

return await Deployment.RunAsync(Deploy.Infra);

class Deploy
public class Deploy
{
public static Dictionary<string, object?> Infra()
{
Expand All @@ -31,23 +31,17 @@ class Deploy
Here, the code that creates resources and returns outputs is inside the `Deploy.Infra` function which we can reference from the test project.

> The return type of `Deploy.Infra` could also have been any of the following
> - `void` when we are not returning outputs
> - `void` when we are not returning any outputs
> - `Task` when we want to `await` async code
> - `Task<Dictionary<string, object?>>` when we want to `await` async code _and_ return outputs
There is a catch before we can reference `Deploy.Infra` from the unit tests. Since we don't have an explicit namespace here, we need to add this property to the project file
```xml
<ItemGroup>
<InternalsVisibleTo Include="Tests"/>
</ItemGroup>
```
Now we are ready to write unit tests. From a test project called `Tests`, add a reference to the project that contains the Pulumi program:
```xml
<ItemGroup>
<ProjectReference Include="..\infra\Infra.csproj" />
</ItemGroup>
```
Now, only for the tests we can create a _test stack_ that uses `Deploy.Infra` as follows
Now, just for the tests we can create a _test stack_ that uses `Deploy.Infra` as follows
```csharp
class TestStack : Stack
{
Expand Down

0 comments on commit f21879c

Please sign in to comment.