pulumi/sdk/dotnet/Pulumi.Tests/Serialization/ConverterTests.cs
2021-11-12 14:58:34 -08:00

46 lines
1.4 KiB
C#

// Copyright 2016-2019, Pulumi Corporation
using System;
using System.Threading.Tasks;
using Google.Protobuf.WellKnownTypes;
using Pulumi.Serialization;
namespace Pulumi.Tests.Serialization
{
public abstract class ConverterTests : PulumiTest
{
protected static readonly Value UnknownValue = new Value { StringValue = Constants.UnknownValue };
protected static Value CreateSecretValue(Value value)
=> new Value
{
StructValue = new Struct
{
Fields =
{
{ Constants.SpecialSigKey, new Value { StringValue = Constants.SpecialSecretSig } },
{ Constants.ValueName, value },
}
}
};
protected async Task<Value> SerializeToValueAsync(object? value, bool keepResources = true)
{
var serializer = new Serializer(excessiveDebugOutput: false);
return Serializer.CreateValue(
await serializer.SerializeAsync(ctx: "", value, keepResources).ConfigureAwait(false));
}
protected static T DeserializeValue<T>(Value value)
{
var v = Deserializer.Deserialize(value).Value;
return v == null ? default! : (T)v;
}
protected static void NoWarn(string error)
{
throw new Exception("Test did not expect warn to be called");
}
}
}