This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from MihaMarkic/feature/async
Implements IAsyncParseNodeFactory interface
- Loading branch information
Showing
4 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Microsoft.Kiota.Serialization.Json.Tests/JsonAsyncParseNodeFactoryTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Microsoft.Kiota.Serialization.Json.Tests | ||
{ | ||
public class JsonAsyncParseNodeFactoryTests | ||
{ | ||
private readonly JsonParseNodeFactory _jsonParseNodeFactory; | ||
private const string TestJsonString = "{\"key\":\"value\"}"; | ||
|
||
public JsonAsyncParseNodeFactoryTests() | ||
{ | ||
_jsonParseNodeFactory = new JsonParseNodeFactory(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetsWriterForJsonContentType() | ||
{ | ||
using var jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(TestJsonString)); | ||
var jsonWriter = await _jsonParseNodeFactory.GetRootParseNodeAsync(_jsonParseNodeFactory.ValidContentType, jsonStream); | ||
|
||
// Assert | ||
Assert.NotNull(jsonWriter); | ||
Assert.IsAssignableFrom<JsonParseNode>(jsonWriter); | ||
} | ||
|
||
[Fact] | ||
public async Task ThrowsArgumentOutOfRangeExceptionForInvalidContentType() | ||
{ | ||
var streamContentType = "application/octet-stream"; | ||
using var jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(TestJsonString)); | ||
var exception = await Assert.ThrowsAsync<ArgumentOutOfRangeException>( | ||
async () => await _jsonParseNodeFactory.GetRootParseNodeAsync(streamContentType, jsonStream)); | ||
|
||
// Assert | ||
Assert.NotNull(exception); | ||
Assert.Equal($"expected a {_jsonParseNodeFactory.ValidContentType} content type", exception.ParamName); | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
public async Task ThrowsArgumentNullExceptionForNoContentType(string contentType) | ||
{ | ||
using var jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(TestJsonString)); | ||
var exception = await Assert.ThrowsAsync<ArgumentNullException>( | ||
async () => await _jsonParseNodeFactory.GetRootParseNodeAsync(contentType, jsonStream)); | ||
|
||
// Assert | ||
Assert.NotNull(exception); | ||
Assert.Equal("contentType", exception.ParamName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters