Skip to content

Commit 0b7c92b

Browse files
authored
Create SimpleConfigurationParser implementation. (#45)
1 parent 4bee63b commit 0b7c92b

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Winton. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENCE in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using System.IO;
6+
7+
namespace Winton.Extensions.Configuration.Consul.Parsers.Simple
8+
{
9+
/// <inheritdoc />
10+
/// <summary>
11+
/// Implemenation of <see cref="IConfigurationParser" /> for parsing simple values
12+
/// </summary>
13+
public sealed class SimpleConfigurationParser : IConfigurationParser
14+
{
15+
/// <inheritdoc />
16+
public IDictionary<string, string> Parse(Stream stream)
17+
{
18+
using (var streamReader = new StreamReader(stream))
19+
{
20+
return new Dictionary<string, string> { { string.Empty, streamReader.ReadToEnd() } };
21+
}
22+
}
23+
}
24+
}

test/Winton.Extensions.Configuration.Consul.Test/Parsers/Json/JsonConfigurationParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public sealed class Parse : JsonConfigurationParserTests
2020
[Theory]
2121
[InlineData("{\"Key\": \"Value\"}", "Key", "Value")]
2222
[InlineData("{\"parent\": {\"child\": \"Value\"} }", "parent:child", "Value")]
23-
public void ShouldParseSimpleJsonFromStream(string json, string key, string expectedValue)
23+
private void ShouldParseSimpleJsonFromStream(string json, string key, string expectedValue)
2424
{
2525
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
2626
{
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Text;
4+
using FluentAssertions;
5+
using Xunit;
6+
7+
namespace Winton.Extensions.Configuration.Consul.Parsers.Simple
8+
{
9+
public class SimpleConfigurationParserTests
10+
{
11+
private readonly SimpleConfigurationParser _parser;
12+
13+
public SimpleConfigurationParserTests()
14+
{
15+
_parser = new SimpleConfigurationParser();
16+
}
17+
18+
public sealed class Parse : SimpleConfigurationParserTests
19+
{
20+
[Fact]
21+
private void ShouldParseSimpleValueFromStream()
22+
{
23+
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes("value")))
24+
{
25+
IDictionary<string, string> result = _parser.Parse(stream);
26+
27+
result.Should().BeEquivalentTo(new Dictionary<string, string> { { string.Empty, "value" } });
28+
}
29+
}
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)