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 10
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 #137 from MihaMarkic/feature/async
Implements IAsyncParseNodeFactory interface
- Loading branch information
Showing
4 changed files
with
67 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
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
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,45 @@ | ||
using System.Text; | ||
|
||
namespace Microsoft.Kiota.Serialization.Form.Tests; | ||
|
||
public class FormAsyncParseNodeFactoryTests | ||
{ | ||
private readonly FormParseNodeFactory _formParseNodeFactory = new(); | ||
private const string TestJsonString = "key=value"; | ||
[Fact] | ||
public async Task GetsWriterForFormContentType() | ||
{ | ||
using var formStream = new MemoryStream(Encoding.UTF8.GetBytes(TestJsonString)); | ||
var formParseNode = await _formParseNodeFactory.GetRootParseNodeAsync(_formParseNodeFactory.ValidContentType, formStream); | ||
|
||
// Assert | ||
Assert.NotNull(formParseNode); | ||
Assert.IsAssignableFrom<FormParseNode>(formParseNode); | ||
} | ||
[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 _formParseNodeFactory.GetRootParseNodeAsync(streamContentType, jsonStream)); | ||
|
||
// Assert | ||
Assert.NotNull(exception); | ||
Assert.Equal($"expected a {_formParseNodeFactory.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 _formParseNodeFactory.GetRootParseNodeAsync(contentType!, jsonStream)); | ||
|
||
// Assert | ||
Assert.NotNull(exception); | ||
Assert.Equal("contentType", exception.ParamName); | ||
} | ||
} |