Skip to content

Commit 7f06092

Browse files
committed
Updated tests to use fluent assertions
1 parent 34cf8b6 commit 7f06092

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

test/Microsoft.OpenApi.Readers.Tests/BasicTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text;
99
using SharpYaml.Serialization;
1010
using Xunit;
11+
using FluentAssertions;
1112

1213
namespace Microsoft.OpenApi.Readers.Tests
1314
{
@@ -19,7 +20,7 @@ public void CheckOpenAPIVersion()
1920
var stream = GetType().Assembly.GetManifestResourceStream(typeof(BasicTests), "Samples.petstore30.yaml");
2021
var openApiDoc = new OpenApiStreamReader().Read(stream, out var context);
2122

22-
Assert.Equal("3.0.0", openApiDoc.SpecVersion.ToString());
23+
openApiDoc.SpecVersion.ToString().Should().Be("3.0.0");
2324
}
2425

2526
[Fact]
@@ -40,7 +41,7 @@ public void InlineExample()
4041
",
4142
out var parsingContext);
4243

43-
Assert.Equal("3.0.0", openApiDoc.SpecVersion.ToString());
44+
openApiDoc.SpecVersion.ToString().Should().Be("3.0.0");
4445
}
4546

4647
[Fact]
@@ -51,9 +52,8 @@ public void ParseBrokenSimplest()
5152

5253
var openApiDoc = new OpenApiStreamReader().Read(stream, out var context);
5354

54-
Assert.Equal(1, context.Errors.Count);
55-
Assert.NotNull(
56-
context.Errors.Where(s => s.ToString() == "title is a required property of #/info").FirstOrDefault());
55+
context.Errors.Should().HaveCount(1);
56+
context.Errors.Select(s => s.ToString()).Should().Contain("title is a required property of #/info");
5757
}
5858

5959
[Fact]
@@ -63,11 +63,11 @@ public void ParseSimplestOpenApiEver()
6363

6464
var openApiDoc = new OpenApiStreamReader().Read(stream, out var context);
6565

66-
Assert.Equal("1.0.0", openApiDoc.SpecVersion.ToString());
67-
Assert.Empty(openApiDoc.Paths);
68-
Assert.Equal("The Api", openApiDoc.Info.Title);
69-
Assert.Equal("0.9.1", openApiDoc.Info.Version.ToString());
70-
Assert.Empty(context.Errors);
66+
openApiDoc.SpecVersion.ToString().Should().Be("1.0.0");
67+
openApiDoc.Paths.Should().BeEmpty();
68+
openApiDoc.Info.Title.Should().Be("The Api");
69+
openApiDoc.Info.Version.ToString().Should().Be("0.9.1");
70+
context.Errors.Should().BeEmpty();
7171
}
7272

7373
[Fact]

test/Microsoft.OpenApi.Tests/ExampleTests.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Linq;
1313
using Newtonsoft.Json.Linq;
1414
using Newtonsoft.Json;
15+
using FluentAssertions;
1516

1617
namespace Microsoft.OpenApi.Tests
1718
{
@@ -46,17 +47,11 @@ public void WriteResponseExample()
4647

4748
var root = JObject.Load(new JsonTextReader(new StreamReader(stream)));
4849

49-
var example = root["paths"]["/test"]["get"]["responses"]["200"]["content"]["application/json"]["example"].Value<string>();
50+
var example = root["paths"]["/test"]["get"]["responses"]["200"]["content"]["application/json"]["example"].Value<string>();
5051

51-
Assert.Equal("xyz", example);
52-
}
53-
}
52+
example.Should().Be("xyz");
5453

55-
public static class YamlExtensions
56-
{
57-
public static YamlMappingNode AsMap(this YamlNode node)
58-
{
59-
return node as YamlMappingNode;
6054
}
6155
}
56+
6257
}

0 commit comments

Comments
 (0)