public void ShouldNotMapSameConstantIdentifierMultipleTimes() { // Arrange var nameAndTypeMappings = new NameAndTypeMappings(); // Act & Assert Assert.Throws <Exception>(() => { nameAndTypeMappings.MapIdentifierNameToConstant("Pi", Math.PI); nameAndTypeMappings.MapIdentifierNameToConstant("Pi", Math.PI); }); }
private static void NamedConstants() { Console.WriteLine("Named constants ..."); var nameMappings = new NameAndTypeMappings(); var serializer = new StringSerializer(nameAndTypeMappings: nameMappings); nameMappings.MapIdentifierNameToConstant("Pi", Math.PI); var output = serializer.Serialize(Math.PI); Console.WriteLine(output); Console.WriteLine(); }
public void ShouldSerializeConstant(object value, string identifier) { // Arrange var nameAndTypeMappings = new NameAndTypeMappings(); var serializer = new StringSerializer(nameAndTypeMappings: nameAndTypeMappings); // Act nameAndTypeMappings.MapIdentifierNameToConstant(identifier, value); var output = serializer.Serialize(value); // Assert Assert.True(StringComparer.InvariantCulture.Equals($"root: {identifier};", output)); }
public void ShouldDeserializeConstant(object value, string identifier) { // Arrange var nameAndTypeMappings = new NameAndTypeMappings(); var serializer = new StringSerializer(nameAndTypeMappings: nameAndTypeMappings); var input = $"root: {identifier};"; // Act nameAndTypeMappings.MapIdentifierNameToConstant(identifier, value); var output = serializer.Deserialize <object>(input); // Assert Assert.Equal(value, output); }