Hey, I found an old Slack message with this same i...
# general
i
Hey, I found an old Slack message with this same issue but it had no responses. Wondering if anyone has since ran into this. Using C#, I'm trying to mock the output of a
StackReference
for unit testing where I'm using
RequireOutput
in the stack. I set up mocking to add a value to the output using
ImmutableDictionary.CreateBuilder<string, object>()
like in the docs. However, the
RequireOutput
throws this exception:
Copy code
System.NullReferenceException: Object reference not set to an instance of an object.
   at Output<object> Pulumi.StackReference.RequireOutput(Input<string> name)+(ValueTuple<string, string, ImmutableDictionary<string, object>> v) => { }
   at Output<ValueTuple> Pulumi.Output<T>.Apply(Func<T, Task> func)+(T t) => { }
   at async Task<OutputData<U>> Pulumi.Output<T>.ApplyHelperAsync<U>(Task<OutputData<T>> dataTask, Func<T, Output<U>> func)
   at async Task<OutputData<T>> Pulumi.Output<T>+<>c__DisplayClass12_0.<WithIsSecret>g__GetData|0(?)+GetData(?)
   at Pulumi.Deployment.TestAsync(IMocks mocks, Func`2 runAsync, TestOptions options)
   at Thread.Uniti.Azure.Environment.Tests.EnvironmentStackTests.InitializeAsync() in /Users/john.marian/Repos/uniti/backend/Infrastructure/Azure/Thread.Uniti.Azure.Environment/tests/EnvironmentStackTests.cs:line 22
   at Xunit.v3.XunitTestRunnerBase`2.CreateTestClassInstance(TContext ctxt) in /_/src/xunit.v3.core/Runners/XunitTestRunnerBase.cs:line 62
   at Xunit.v3.ExceptionAggregator.RunAsync[T](Func`1 code, T defaultValue) in /_/src/xunit.v3.core/Exceptions/ExceptionAggregator.cs:line 146
Here's how I'm mocking the output in `NewResourceAsync`:
Copy code
var outputs = ImmutableDictionary.CreateBuilder<string, object>();
            if (args.Type == "pulumi:pulumi:StackReference")
            {
                outputs.Add("VirtualNetworkId", "core-vnet-id");
            }
g
i
That might be exactly what I'm looking for, thank you!