public void Render_NullFormatter_ThrowsNullArgumentException() { var value = new KeyValuePair <ScalarToken, IPropertyToken>(new ScalarToken("Foo"), new ScalarToken("Bar")); var dictionary = new DictionaryToken(new[] { value }); Assert.Throws <ArgumentNullException>(() => dictionary.Render(null)); }
public void Render_EmptyDictionaryToken_IsFormattedAsEmptyArray() { var output = new StringWriter(); var formater = new JsonPropertyFormatter(output); var token = new DictionaryToken(null); token.Render(formater); Assert.Equal("[]", output.ToString()); }
public void Render_SomeFormatter_FormatterIsCalled() { var formatterMock = new Mock <IPropertyFormatter>(); var formatter = formatterMock.Object; var value = new KeyValuePair <ScalarToken, IPropertyToken>(new ScalarToken("Foo"), new ScalarToken("Bar")); var dictionary = new DictionaryToken(new[] { value }); dictionary.Render(formatter); formatterMock.Verify(m => m.Format(dictionary), Times.Once); }
public void Render_NonEmptyDictionaryToken_IsFormattedAsArrayOfKeyValuePairs() { var output = new StringWriter(); var formater = new JsonPropertyFormatter(output); var token = new DictionaryToken(new[] { new KeyValuePair <ScalarToken, IPropertyToken>( new ScalarToken("foo"), new ScalarToken(1)), new KeyValuePair <ScalarToken, IPropertyToken>( new ScalarToken("bar"), new SequenceToken(new[] { new ScalarToken(1.2) })) }); token.Render(formater); Assert.Equal("[{\"key\": \"foo\", \"value\": 1}, {\"key\": \"bar\", \"value\": [1.2]}]", output.ToString()); }