diff --git a/test/Microsoft.OpenApi.Readers.Tests/DefaultSettingsFixture.cs b/test/Microsoft.OpenApi.Readers.Tests/DefaultSettingsFixture.cs
deleted file mode 100644
index ed8072ba6..000000000
--- a/test/Microsoft.OpenApi.Readers.Tests/DefaultSettingsFixture.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT license.
-
-using FluentAssertions;
-
-namespace Microsoft.OpenApi.Readers.Tests
-{
- ///
- /// Fixture containing default settings for external libraries.
- ///
- public class DefaultSettingsFixture
- {
- ///
- /// Initializes an instance of .
- ///
- public DefaultSettingsFixture()
- {
- // We need RespectingRuntimeTypes() to ensure equivalence test works property,
- // given that there are multiple types that can be used for the declared type OpenApiAny.
- // Without this option, properties specific to those types would not be compared.
- AssertionOptions.AssertEquivalencyUsing(
- o => o
- .AllowingInfiniteRecursion()
- .RespectingRuntimeTypes()
- .WithStrictOrdering());
- }
- }
-}
diff --git a/test/Microsoft.OpenApi.Readers.Tests/DefaultSettingsFixtureCollection.cs b/test/Microsoft.OpenApi.Readers.Tests/DefaultSettingsFixtureCollection.cs
deleted file mode 100644
index d17520848..000000000
--- a/test/Microsoft.OpenApi.Readers.Tests/DefaultSettingsFixtureCollection.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT license.
-
-using Xunit;
-
-namespace Microsoft.OpenApi.Readers.Tests
-{
- ///
- /// Collection dummy class for .
- ///
- ///
- /// This class is needed in xUnit framework to define collection name
- /// to be used in unit test classes.
- ///
- [CollectionDefinition("DefaultSettings")]
- public class DefaultSettingsFixtureCollection : ICollectionFixture
- {
- }
-}
diff --git a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj
index dcbb3cebd..36463ff44 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj
+++ b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj
@@ -18,7 +18,6 @@
-
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/ComparisonTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/ComparisonTests.cs
index 7016965a3..db63cbe9c 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/ComparisonTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/ComparisonTests.cs
@@ -3,8 +3,8 @@
using System.IO;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
+using Microsoft.OpenApi.Tests;
using Xunit;
namespace Microsoft.OpenApi.Readers.Tests.V2Tests
@@ -27,8 +27,7 @@ public async Task EquivalentV2AndV3DocumentsShouldProduceEquivalentObjects(strin
var result1 = await OpenApiDocument.LoadAsync(Path.Join(SampleFolderPath, $"{fileName}.v2.yaml"), SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
var result2 = await OpenApiDocument.LoadAsync(Path.Join(SampleFolderPath, $"{fileName}.v3.yaml"), SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
- result2.Document.Should().BeEquivalentTo(result1.Document,
- options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri));
+ OpenApiTestAssert.Equivalent(result1.Document, result2.Document, nameof(OpenApiDocument.Workspace), nameof(OpenApiDocument.BaseUri));
Assert.Equivalent(result2.Diagnostic.Errors, result1.Diagnostic.Errors);
}
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs
index 85b556017..9a85d6898 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs
@@ -7,8 +7,8 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
+using Microsoft.OpenApi.Tests;
using Xunit;
namespace Microsoft.OpenApi.Readers.Tests.V2Tests
@@ -119,7 +119,7 @@ public async Task ShouldParseProducesInAnyOrder()
Schema = new OpenApiSchemaReference("Error", result.Document)
};
- result.Document.Should().BeEquivalentTo(new OpenApiDocument
+ OpenApiTestAssert.Equivalent(new OpenApiDocument
{
Info = new()
{
@@ -220,7 +220,7 @@ public async Task ShouldParseProducesInAnyOrder()
["Error"] = errorSchema
}
}
- }, options => options.Excluding(x => x.BaseUri));
+ }, result.Document, nameof(OpenApiDocument.BaseUri));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs
index 789047939..965ea9c7e 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs
@@ -3,10 +3,9 @@
using System.Text.Json.Nodes;
using System.IO;
-using FluentAssertions;
-using FluentAssertions.Equivalency;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Reader.V2;
+using Microsoft.OpenApi.Tests;
using Xunit;
namespace Microsoft.OpenApi.Readers.Tests.V2Tests
@@ -30,7 +29,7 @@ public void ParseHeaderWithDefaultShouldSucceed()
var header = OpenApiV2Deserializer.LoadHeader(node, new(), new ParsingContext(new()));
// Assert
- header.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiHeader
{
Schema = new OpenApiSchema()
@@ -40,9 +39,8 @@ public void ParseHeaderWithDefaultShouldSucceed()
Default = new JsonNodeExtension(5).Node
}
},
- options => options
- .IgnoringCyclicReferences()
- .Excluding(x => x.Schema.Default.Parent));
+ header,
+ nameof(JsonNode.Parent));
}
[Fact]
@@ -59,7 +57,7 @@ public void ParseHeaderWithEnumShouldSucceed()
var header = OpenApiV2Deserializer.LoadHeader(node, new(), new ParsingContext(new()));
// Assert
- header.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiHeader
{
Schema = new OpenApiSchema()
@@ -73,9 +71,7 @@ public void ParseHeaderWithEnumShouldSucceed()
new JsonNodeExtension(9).Node
]
}
- }, options => options.IgnoringCyclicReferences()
- .Excluding((IMemberInfo memberInfo) =>
- memberInfo.Path.EndsWith("Parent")));
+ }, header, nameof(JsonNode.Parent));
}
}
}
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs
index 3d47bd419..81ddafd0c 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs
@@ -7,7 +7,6 @@
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Reader.V2;
using Microsoft.OpenApi.Reader.V3;
@@ -165,7 +164,7 @@ public void ParseOperationWithBodyShouldSucceed()
var operation = OpenApiV2Deserializer.LoadOperation(node, new(), new ParsingContext(new()));
// Assert
- operation.Should().BeEquivalentTo(_operationWithBody, options => options.IgnoringCyclicReferences());
+ OpenApiTestAssert.Equivalent(_operationWithBody, operation);
}
[Fact]
@@ -183,7 +182,7 @@ public async Task ParseOperationWithBodyTwiceShouldYieldSameObject()
var operation = OpenApiV2Deserializer.LoadOperation(node, new(), new ParsingContext(new()));
// Assert
- operation.Should().BeEquivalentTo(_operationWithBody, options => options.IgnoringCyclicReferences());
+ OpenApiTestAssert.Equivalent(_operationWithBody, operation);
}
[Fact]
@@ -200,7 +199,7 @@ public void ParseOperationWithResponseExamplesShouldSucceed()
var operation = OpenApiV2Deserializer.LoadOperation(node, new(), new ParsingContext(new()));
// Assert
- operation.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiOperation()
{
Responses = new OpenApiResponses()
@@ -243,13 +242,7 @@ public void ParseOperationWithResponseExamplesShouldSucceed()
}
}}
}
- }, options => options.IgnoringCyclicReferences()
- .Excluding(o => o.Responses["200"].Content["application/json"].Example[0].Parent)
- .Excluding(o => o.Responses["200"].Content["application/json"].Example[0].Root)
- .Excluding(o => o.Responses["200"].Content["application/json"].Example[1].Parent)
- .Excluding(o => o.Responses["200"].Content["application/json"].Example[1].Root)
- .Excluding(o => o.Responses["200"].Content["application/json"].Example[2].Parent)
- .Excluding(o => o.Responses["200"].Content["application/json"].Example[2].Root));
+ }, operation, nameof(JsonNode.Parent), nameof(JsonNode.Root));
}
[Fact]
@@ -300,7 +293,7 @@ public void ParseOperationWithBodyAndEmptyConsumesSetsRequestBodySchemaIfExists(
var operation = OpenApiV2Deserializer.LoadOperation(node, new(), new ParsingContext(new()));
// Assert
- operation.Should().BeEquivalentTo(_operationWithBody, options => options.IgnoringCyclicReferences());
+ OpenApiTestAssert.Equivalent(_operationWithBody, operation);
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs
index c4b8f81bf..7e7f15405 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs
@@ -3,8 +3,6 @@
// Licensed under the MIT license.
using System.IO;
-using FluentAssertions;
-using FluentAssertions.Equivalency;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Reader.V2;
using Microsoft.OpenApi.Tests;
@@ -226,7 +224,7 @@ public void ParseParameterWithDefaultShouldSucceed()
var parameter = OpenApiV2Deserializer.LoadParameter(node, new(), new ParsingContext(new()));
// Assert
- parameter.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiParameter
{
In = ParameterLocation.Path,
@@ -239,7 +237,7 @@ public void ParseParameterWithDefaultShouldSucceed()
Format = "float",
Default = new JsonNodeExtension(5).Node
}
- }, options => options.IgnoringCyclicReferences().Excluding(x => x.Schema.Default.Parent));
+ }, parameter, nameof(JsonNode.Parent));
}
[Fact]
@@ -274,10 +272,7 @@ public void ParseParameterWithEnumShouldSucceed()
};
// Assert
- parameter.Should().BeEquivalentTo(expected, options => options
- .IgnoringCyclicReferences()
- .Excluding((IMemberInfo memberInfo) =>
- memberInfo.Path.EndsWith("Parent")));
+ OpenApiTestAssert.Equivalent(expected, parameter, nameof(JsonNode.Parent));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs
index ee5e4a25f..cbbde4b70 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs
@@ -5,8 +5,6 @@
using System.IO;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using FluentAssertions;
-using FluentAssertions.Equivalency;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Reader.V2;
using Microsoft.OpenApi.Tests;
@@ -35,12 +33,12 @@ public void ParseSchemaWithDefaultShouldSucceed()
var schema = OpenApiV2Deserializer.LoadSchema(node, new(), new ParsingContext(new()));
// Assert
- schema.Should().BeEquivalentTo(new OpenApiSchema
+ OpenApiTestAssert.Equivalent(new OpenApiSchema
{
Type = JsonSchemaType.Number,
Format = "float",
Default = 5
- }, options => options.IgnoringCyclicReferences().Excluding(x => x.Default.Parent));
+ }, schema, nameof(JsonNode.Parent));
}
[Fact]
@@ -57,13 +55,13 @@ public void ParseSchemaWithExampleShouldSucceed()
var schema = OpenApiV2Deserializer.LoadSchema(node, new(), new ParsingContext(new()));
// Assert
- schema.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiSchema
{
Type = JsonSchemaType.Number,
Format = "float",
Example = 5
- }, options => options.IgnoringCyclicReferences().Excluding(x => x.Example.Parent));
+ }, schema, nameof(JsonNode.Parent));
}
[Fact]
@@ -92,10 +90,7 @@ public void ParseSchemaWithEnumShouldSucceed()
]
};
- schema.Should().BeEquivalentTo(expected, options =>
- options.IgnoringCyclicReferences()
- .Excluding((IMemberInfo memberInfo) =>
- memberInfo.Path.EndsWith("Parent")));
+ OpenApiTestAssert.Equivalent(expected, schema, nameof(JsonNode.Parent));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs
index cedd134d8..412037d52 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs
@@ -2,7 +2,6 @@
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Tests;
using Xunit;
@@ -244,7 +243,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed()
// Assert
Assert.Equivalent(new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_1, Format = OpenApiConstants.Yaml }, actual.Diagnostic);
- actual.Document.Should().BeEquivalentTo(expected, options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri));
+ OpenApiTestAssert.Equivalent(expected, actual.Document, nameof(OpenApiDocument.Workspace), nameof(OpenApiDocument.BaseUri));
}
[Fact]
@@ -446,9 +445,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
};
// Assert
- actual.Document.Should().BeEquivalentTo(expected, options => options
- .Excluding(x => x.Workspace)
- .Excluding(y => y.BaseUri));
+ OpenApiTestAssert.Equivalent(expected, actual.Document, nameof(OpenApiDocument.Workspace), nameof(OpenApiDocument.BaseUri));
Assert.Equivalent(
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_1, Format = OpenApiConstants.Yaml }, actual.Diagnostic);
}
@@ -613,7 +610,7 @@ public async Task ParseDocumentWithEmptyTagsWorks()
var path = Path.Join(SampleFolderPath, "documentWithEmptyTags.json");
var doc = (await OpenApiDocument.LoadAsync(path, SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken)).Document;
- doc.Paths["/groups"].Operations[HttpMethod.Get].Tags.Should().BeNull("Empty tags are ignored, so we should not have any tags");
+ Assert.Null(doc.Paths["/groups"].Operations[HttpMethod.Get].Tags);
}
[Fact]
public async Task DocumentWithSchemaResultsInWarning()
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiHeaderTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiHeaderTests.cs
index 0478a3acf..41d65f610 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiHeaderTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiHeaderTests.cs
@@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
using Xunit;
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiMediaTypeTests.cs
index 5f14143a8..096627e08 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiMediaTypeTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiMediaTypeTests.cs
@@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Reader.V31;
using Microsoft.OpenApi.Tests;
@@ -25,7 +24,7 @@ public async Task ParseMediaTypeWithExampleShouldSucceed()
var mediaType = await OpenApiModelFactory.LoadAsync(Path.Join(SampleFolderPath, "mediaTypeWithExample.yaml"), OpenApiSpecVersion.OpenApi3_1, new(), SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
// Assert
- mediaType.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiMediaType
{
Example = 5,
@@ -34,9 +33,7 @@ public async Task ParseMediaTypeWithExampleShouldSucceed()
Type = JsonSchemaType.Number,
Format = "float"
}
- }, options => options.IgnoringCyclicReferences()
- .Excluding(m => m.Example.Parent)
- );
+ }, mediaType, nameof(JsonNode.Parent));
}
[Fact]
@@ -46,7 +43,7 @@ public async Task ParseMediaTypeWithExamplesShouldSucceed()
var mediaType = await OpenApiModelFactory.LoadAsync(Path.Join(SampleFolderPath, "mediaTypeWithExamples.yaml"), OpenApiSpecVersion.OpenApi3_1, new(), SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
// Assert
- mediaType.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiMediaType
{
Examples = new Dictionary
@@ -65,9 +62,7 @@ public async Task ParseMediaTypeWithExamplesShouldSucceed()
Type = JsonSchemaType.Number,
Format = "float"
}
- }, options => options.IgnoringCyclicReferences()
- .Excluding(m => m.Examples["example1"].Value.Parent)
- .Excluding(m => m.Examples["example2"].Value.Parent));
+ }, mediaType, nameof(JsonNode.Parent));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs
index 8f86d8297..caffb3e3e 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs
@@ -8,8 +8,6 @@
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using FluentAssertions;
-using FluentAssertions.Equivalency;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Tests;
using Xunit;
@@ -292,10 +290,7 @@ public async Task ParseAdvancedV31SchemaShouldSucceed()
};
// Assert
- schema.Should().BeEquivalentTo(expectedSchema, options => options
- .IgnoringCyclicReferences()
- .Excluding((IMemberInfo memberInfo) =>
- memberInfo.Path.EndsWith("Parent")));
+ OpenApiTestAssert.Equivalent(expectedSchema, schema, nameof(JsonNode.Parent));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiDocumentTests.cs
index 9f9c9b774..28e213466 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiDocumentTests.cs
@@ -2,7 +2,6 @@
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Tests;
using Xunit;
@@ -244,7 +243,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed()
// Assert
Assert.Equivalent(new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_2, Format = OpenApiConstants.Yaml }, actual.Diagnostic);
- actual.Document.Should().BeEquivalentTo(expected, options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri));
+ OpenApiTestAssert.Equivalent(expected, actual.Document, nameof(OpenApiDocument.Workspace), nameof(OpenApiDocument.BaseUri));
}
[Fact]
@@ -446,9 +445,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
};
// Assert
- actual.Document.Should().BeEquivalentTo(expected, options => options
- .Excluding(x => x.Workspace)
- .Excluding(y => y.BaseUri));
+ OpenApiTestAssert.Equivalent(expected, actual.Document, nameof(OpenApiDocument.Workspace), nameof(OpenApiDocument.BaseUri));
Assert.Equivalent(
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_2, Format = OpenApiConstants.Yaml }, actual.Diagnostic);
}
@@ -613,7 +610,7 @@ public async Task ParseDocumentWithEmptyTagsWorks()
var path = Path.Join(SampleFolderPath, "documentWithEmptyTags.json");
var doc = (await OpenApiDocument.LoadAsync(path, SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken)).Document;
- doc.Paths["/groups"].Operations[HttpMethod.Get].Tags.Should().BeNull("Empty tags are ignored, so we should not have any tags");
+ Assert.Null(doc.Paths["/groups"].Operations[HttpMethod.Get].Tags);
}
[Fact]
public async Task DocumentWithSchemaResultsInWarning()
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiHeaderTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiHeaderTests.cs
index 5f24378cf..3e6b63314 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiHeaderTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiHeaderTests.cs
@@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
using Xunit;
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiMediaTypeTests.cs
index d2163b230..d3716b2d6 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiMediaTypeTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiMediaTypeTests.cs
@@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Reader.V32;
using Microsoft.OpenApi.Tests;
@@ -25,7 +24,7 @@ public async Task ParseMediaTypeWithExampleShouldSucceed()
var mediaType = await OpenApiModelFactory.LoadAsync(Path.Join(SampleFolderPath, "mediaTypeWithExample.yaml"), OpenApiSpecVersion.OpenApi3_2, new(), SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
// Assert
- mediaType.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiMediaType
{
Example = 5,
@@ -34,9 +33,7 @@ public async Task ParseMediaTypeWithExampleShouldSucceed()
Type = JsonSchemaType.Number,
Format = "float"
}
- }, options => options.IgnoringCyclicReferences()
- .Excluding(m => m.Example.Parent)
- );
+ }, mediaType, nameof(JsonNode.Parent));
}
[Fact]
@@ -46,7 +43,7 @@ public async Task ParseMediaTypeWithExamplesShouldSucceed()
var mediaType = await OpenApiModelFactory.LoadAsync(Path.Join(SampleFolderPath, "mediaTypeWithExamples.yaml"), OpenApiSpecVersion.OpenApi3_2, new(), SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
// Assert
- mediaType.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiMediaType
{
Examples = new Dictionary
@@ -65,9 +62,7 @@ public async Task ParseMediaTypeWithExamplesShouldSucceed()
Type = JsonSchemaType.Number,
Format = "float"
}
- }, options => options.IgnoringCyclicReferences()
- .Excluding(m => m.Examples["example1"].Value.Parent)
- .Excluding(m => m.Examples["example2"].Value.Parent));
+ }, mediaType, nameof(JsonNode.Parent));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiSchemaTests.cs
index 6426733e3..184a2e744 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiSchemaTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiSchemaTests.cs
@@ -6,8 +6,6 @@
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using FluentAssertions;
-using FluentAssertions.Equivalency;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Tests;
using Xunit;
@@ -291,10 +289,7 @@ public async Task ParseAdvancedV32SchemaShouldSucceed()
};
// Assert
- schema.Should().BeEquivalentTo(expectedSchema, options => options
- .IgnoringCyclicReferences()
- .Excluding((IMemberInfo memberInfo) =>
- memberInfo.Path.EndsWith("Parent")));
+ OpenApiTestAssert.Equivalent(expectedSchema, schema, nameof(JsonNode.Parent));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs
index 9d3d3e535..7034eb46d 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs
@@ -13,7 +13,6 @@
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Tests;
using Moq;
@@ -55,7 +54,7 @@ public void ParseDocumentFromInlineStringShouldSucceed()
paths: {}",
OpenApiConstants.Yaml, SettingsFixture.ReaderSettings);
- result.Document.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiDocument
{
Info = new OpenApiInfo
@@ -64,7 +63,7 @@ public void ParseDocumentFromInlineStringShouldSucceed()
Version = "0.9.1"
},
Paths = new OpenApiPaths()
- }, options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri));
+ }, result.Document, nameof(OpenApiDocument.Workspace), nameof(OpenApiDocument.BaseUri));
Assert.Equivalent(
new OpenApiDiagnostic()
@@ -96,7 +95,7 @@ public async Task ParseBasicDocumentWithMultipleServersShouldSucceed()
var result = await OpenApiDocument.LoadAsync(path, SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
Assert.Empty(result.Diagnostic.Errors);
- result.Document.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiDocument
{
Info = new OpenApiInfo
@@ -118,7 +117,7 @@ public async Task ParseBasicDocumentWithMultipleServersShouldSucceed()
}
],
Paths = new OpenApiPaths()
- }, options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri));
+ }, result.Document, nameof(OpenApiDocument.Workspace), nameof(OpenApiDocument.BaseUri));
}
[Fact]
public async Task ParseBrokenMinimalDocumentShouldYieldExpectedDiagnostic()
@@ -131,7 +130,7 @@ public async Task ParseBrokenMinimalDocumentShouldYieldExpectedDiagnostic()
var result = await OpenApiDocument.LoadAsync(memoryStream, settings: SettingsFixture.ReaderSettings, cancellationToken: TestContext.Current.CancellationToken);
- result.Document.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiDocument
{
Info = new OpenApiInfo
@@ -139,7 +138,7 @@ public async Task ParseBrokenMinimalDocumentShouldYieldExpectedDiagnostic()
Version = "0.9"
},
Paths = new OpenApiPaths()
- }, options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri));
+ }, result.Document, nameof(OpenApiDocument.Workspace), nameof(OpenApiDocument.BaseUri));
Assert.Equivalent(
new OpenApiDiagnostic
@@ -192,7 +191,7 @@ public async Task ParseMinimalDocumentShouldSucceed()
{
var result = await OpenApiDocument.LoadAsync(Path.Join(SampleFolderPath, "minimalDocument.yaml"), SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
- result.Document.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiDocument
{
Info = new OpenApiInfo
@@ -201,7 +200,7 @@ public async Task ParseMinimalDocumentShouldSucceed()
Version = "0.9.1"
},
Paths = new OpenApiPaths()
- }, options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri));
+ }, result.Document, nameof(OpenApiDocument.Workspace), nameof(OpenApiDocument.BaseUri));
Assert.Equivalent(
new OpenApiDiagnostic()
@@ -591,7 +590,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
Components = components
};
- actual.Document.Should().BeEquivalentTo(expectedDoc, options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri));
+ OpenApiTestAssert.Equivalent(expectedDoc, actual.Document, nameof(OpenApiDocument.Workspace), nameof(OpenApiDocument.BaseUri));
Assert.Equivalent(
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0, Format = OpenApiConstants.Yaml }, actual.Diagnostic);
@@ -1060,12 +1059,10 @@ [new OpenApiSecuritySchemeReference("securitySchemeName2")] =
expected.RegisterComponents();
expected.SetReferenceHostDocument();
- actual.Document.Should().BeEquivalentTo(expected, options => options
- .IgnoringCyclicReferences()
- .Excluding(ctx => ctx.Path.Contains("Paths[\"/pets\"].Operations[HttpMethod.Get].Tags"))
- .Excluding(ctx => ctx.Path.Contains("Paths[\"/pets\"].Operations[HttpMethod.Post].Tags"))
- .Excluding(x => x.Workspace)
- .Excluding(y => y.BaseUri));
+ OpenApiTestAssert.Equivalent(expected, actual.Document, path =>
+ path.MemberName is nameof(OpenApiDocument.Workspace) or nameof(OpenApiDocument.BaseUri)
+ || path.Value.Contains($"{nameof(OpenApiDocument.Paths)}[/pets].{nameof(OpenApiPathItem.Operations)}[{HttpMethod.Get}].{nameof(OpenApiOperation.Tags)}")
+ || path.Value.Contains($"{nameof(OpenApiDocument.Paths)}[/pets].{nameof(OpenApiPathItem.Operations)}[{HttpMethod.Post}].{nameof(OpenApiOperation.Tags)}"));
Assert.Equivalent(
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0, Format = OpenApiConstants.Yaml }, actual.Diagnostic);
@@ -1099,7 +1096,7 @@ public async Task HeaderParameterShouldAllowExample()
var exampleHeader = result.Document.Components?.Headers?["example-header"];
Assert.NotNull(exampleHeader);
- exampleHeader.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiHeader()
{
Description = "Test header with example",
@@ -1115,12 +1112,11 @@ public async Task HeaderParameterShouldAllowExample()
Type = JsonSchemaType.String,
Format = "uuid"
},
- }, options => options.IgnoringCyclicReferences()
- .Excluding(e => e.Example.Parent));
+ }, exampleHeader, nameof(JsonNode.Parent));
var examplesHeader = result.Document.Components?.Headers?["examples-header"];
Assert.NotNull(examplesHeader);
- examplesHeader.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiHeader()
{
Description = "Test header with example",
@@ -1148,9 +1144,7 @@ public async Task HeaderParameterShouldAllowExample()
Type = JsonSchemaType.String,
Format = "uuid"
},
- }, options => options.IgnoringCyclicReferences()
- .Excluding(e => e.Examples["uuid1"].Value.Parent)
- .Excluding(e => e.Examples["uuid2"].Value.Parent));
+ }, examplesHeader, nameof(JsonNode.Parent));
}
[Fact]
@@ -1430,13 +1424,7 @@ public async Task ParseDocWithRefsUsingProxyReferencesSucceeds()
var actualParamReference = Assert.IsType(actualParam);
// Assert
- actualParamReference.Should().BeEquivalentTo(expectedParamReference, options => options
- .Excluding(x => x.Reference)
- .Excluding(x => x.Target)
- .Excluding(x => x.RecursiveTarget)
- .Excluding(x => x.Schema.Default.Parent)
- .Excluding(x => x.Schema.Default.Options)
- .IgnoringCyclicReferences());
+ OpenApiTestAssert.Equivalent(expectedParamReference, actualParamReference, nameof(OpenApiParameterReference.Reference), nameof(OpenApiParameterReference.Target), nameof(OpenApiParameterReference.RecursiveTarget), nameof(JsonNode.Parent), nameof(JsonNode.Options));
Assert.Equal(expectedSerializedDoc.MakeLineBreaksEnvironmentNeutral(), outputDoc);
}
@@ -1487,7 +1475,7 @@ public void ParseBasicDocumentWithServerVariableShouldSucceed()
Format = OpenApiConstants.Yaml
}, result.Diagnostic);
- result.Document.Should().BeEquivalentTo(expected, options => options.Excluding(x => x.BaseUri));
+ OpenApiTestAssert.Equivalent(expected, result.Document, nameof(OpenApiDocument.BaseUri));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiExampleTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiExampleTests.cs
index b356f45c0..ead7840cd 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiExampleTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiExampleTests.cs
@@ -4,8 +4,8 @@
using System.IO;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
+using Microsoft.OpenApi.Tests;
using Xunit;
namespace Microsoft.OpenApi.Readers.Tests.V3Tests
@@ -56,15 +56,7 @@ public async Task ParseAdvancedExampleShouldSucceed()
}
};
- example.Should().BeEquivalentTo(expected, options => options.IgnoringCyclicReferences()
- .Excluding(e => e.Value["versions"][0]["status"].Root)
- .Excluding(e => e.Value["versions"][0]["id"].Root)
- .Excluding(e => e.Value["versions"][0]["links"][0]["href"].Root)
- .Excluding(e => e.Value["versions"][0]["links"][0]["rel"].Root)
- .Excluding(e => e.Value["versions"][1]["status"].Root)
- .Excluding(e => e.Value["versions"][1]["id"].Root)
- .Excluding(e => e.Value["versions"][1]["links"][0]["href"].Root)
- .Excluding(e => e.Value["versions"][1]["links"][0]["rel"].Root));
+ OpenApiTestAssert.Equivalent(expected, example, nameof(JsonNode.Root));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiHeaderTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiHeaderTests.cs
index ffc89e34f..38281018c 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiHeaderTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiHeaderTests.cs
@@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
using Xunit;
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs
index 9379c38e8..a11b044f4 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs
@@ -6,8 +6,8 @@
using System.IO;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
+using Microsoft.OpenApi.Tests;
using Xunit;
namespace Microsoft.OpenApi.Readers.Tests.V3Tests
@@ -24,7 +24,7 @@ public async Task ParseAdvancedInfoShouldSucceed()
var openApiInfo = await OpenApiModelFactory.LoadAsync(Path.Join(SampleFolderPath, "advancedInfo.yaml"), OpenApiSpecVersion.OpenApi3_0, new(), SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
// Assert
- openApiInfo.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiInfo
{
Title = "Advanced Info",
@@ -61,20 +61,7 @@ public async Task ParseAdvancedInfoShouldSucceed()
}),
["x-list"] = new JsonNodeExtension (new JsonArray { "1", "2" })
}
- }, options => options.IgnoringCyclicReferences()
- .Excluding(i => ((JsonNodeExtension)i.Contact.Extensions["x-twitter"]).Node.Parent)
- .Excluding(i => ((JsonNodeExtension)i.License.Extensions["x-disclaimer"]).Node.Parent)
- .Excluding(i => ((JsonNodeExtension)i.Extensions["x-something"]).Node.Parent)
- .Excluding(i => ((JsonNodeExtension)i.Extensions["x-contact"]).Node["name"].Parent)
- .Excluding(i => ((JsonNodeExtension)i.Extensions["x-contact"]).Node["name"].Root)
- .Excluding(i => ((JsonNodeExtension)i.Extensions["x-contact"]).Node["url"].Parent)
- .Excluding(i => ((JsonNodeExtension)i.Extensions["x-contact"]).Node["url"].Root)
- .Excluding(i => ((JsonNodeExtension)i.Extensions["x-contact"]).Node["email"].Parent)
- .Excluding(i => ((JsonNodeExtension)i.Extensions["x-contact"]).Node["email"].Root)
- .Excluding(i => ((JsonNodeExtension)i.Extensions["x-list"]).Node[0].Parent)
- .Excluding(i => ((JsonNodeExtension)i.Extensions["x-list"]).Node[0].Root)
- .Excluding(i => ((JsonNodeExtension)i.Extensions["x-list"]).Node[1].Parent)
- .Excluding(i => ((JsonNodeExtension)i.Extensions["x-list"]).Node[1].Root));
+ }, openApiInfo, nameof(JsonNode.Parent), nameof(JsonNode.Root));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs
index 566f50ee4..d533a2078 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs
@@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Reader.V3;
using Microsoft.OpenApi.Tests;
@@ -25,7 +24,7 @@ public async Task ParseMediaTypeWithExampleShouldSucceed()
var mediaType = await OpenApiModelFactory.LoadAsync(Path.Join(SampleFolderPath, "mediaTypeWithExample.yaml"), OpenApiSpecVersion.OpenApi3_0, new(), SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
// Assert
- mediaType.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiMediaType
{
Example = 5,
@@ -34,9 +33,7 @@ public async Task ParseMediaTypeWithExampleShouldSucceed()
Type = JsonSchemaType.Number,
Format = "float"
}
- }, options => options.IgnoringCyclicReferences()
- .Excluding(m => m.Example.Parent)
- );
+ }, mediaType, nameof(JsonNode.Parent));
}
[Fact]
@@ -46,7 +43,7 @@ public async Task ParseMediaTypeWithExamplesShouldSucceed()
var mediaType = await OpenApiModelFactory.LoadAsync(Path.Join(SampleFolderPath, "mediaTypeWithExamples.yaml"), OpenApiSpecVersion.OpenApi3_0, new(), SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
// Assert
- mediaType.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiMediaType
{
Examples = new Dictionary
@@ -65,9 +62,7 @@ public async Task ParseMediaTypeWithExamplesShouldSucceed()
Type = JsonSchemaType.Number,
Format = "float"
}
- }, options => options.IgnoringCyclicReferences()
- .Excluding(m => m.Examples["example1"].Value.Parent)
- .Excluding(m => m.Examples["example2"].Value.Parent));
+ }, mediaType, nameof(JsonNode.Parent));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs
index 8756e90f6..de462ebb2 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs
@@ -7,7 +7,7 @@
using System.Net.Http;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using FluentAssertions;
+using Microsoft.OpenApi.Tests;
using Microsoft.OpenApi.Reader;
using Xunit;
@@ -71,9 +71,7 @@ public async Task ParseOperationWithParameterWithNoLocationShouldSucceed()
};
// Assert
- expectedOp.Should().BeEquivalentTo(operation,
- options =>
- options.Excluding(x => x.Tags));
+ OpenApiTestAssert.Equivalent(expectedOp, operation, nameof(OpenApiOperation.Tags));
}
[Fact]
public void DeduplicatesTagReferences()
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs
index 4eca7dc9e..764ebac7a 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs
@@ -3,10 +3,11 @@
using System.Collections.Generic;
using System.IO;
-using FluentAssertions;
+using System.Text.Json.Nodes;
using Microsoft.OpenApi.Reader;
using Xunit;
using Microsoft.OpenApi.Reader.V3;
+using Microsoft.OpenApi.Tests;
using System.Threading.Tasks;
using System.Net.Http;
@@ -240,7 +241,7 @@ public async Task ParseParameterWithExampleShouldSucceed()
var parameter = await OpenApiModelFactory.LoadAsync(Path.Join(SampleFolderPath, "parameterWithExample.yaml"), OpenApiSpecVersion.OpenApi3_0, new(), settings: SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
// Assert
- parameter.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiParameter
{
In = null,
@@ -253,7 +254,7 @@ public async Task ParseParameterWithExampleShouldSucceed()
Type = JsonSchemaType.Number,
Format = "float"
}
- }, options => options.IgnoringCyclicReferences().Excluding(p => p.Example.Parent));
+ }, parameter, nameof(JsonNode.Parent));
}
[Fact]
@@ -263,7 +264,7 @@ public async Task ParseParameterWithExamplesShouldSucceed()
var parameter = await OpenApiModelFactory.LoadAsync(Path.Join(SampleFolderPath, "parameterWithExamples.yaml"), OpenApiSpecVersion.OpenApi3_0, new(), settings: SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
// Assert
- parameter.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiParameter
{
In = null,
@@ -286,9 +287,7 @@ public async Task ParseParameterWithExamplesShouldSucceed()
Type = JsonSchemaType.Number,
Format = "float"
}
- }, options => options.IgnoringCyclicReferences()
- .Excluding(p => p.Examples["example1"].Value.Parent)
- .Excluding(p => p.Examples["example2"].Value.Parent));
+ }, parameter, nameof(JsonNode.Parent));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs
index 85126723b..f574245e6 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs
@@ -6,8 +6,6 @@
using System.Net.Http;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using FluentAssertions;
-using FluentAssertions.Equivalency;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Reader.V3;
using Microsoft.OpenApi.Tests;
@@ -67,12 +65,12 @@ public void ParseExampleStringFragmentShouldSucceed()
// Assert
Assert.Equivalent(new OpenApiDiagnostic(), diagnostic);
- jsonNodeExtension.Should().BeEquivalentTo(new JsonNodeExtension(
+ OpenApiTestAssert.Equivalent(new JsonNodeExtension(
new JsonObject
{
["foo"] = "bar",
["baz"] = new JsonArray() { 1, 2 }
- }), options => options.IgnoringCyclicReferences());
+ }), jsonNodeExtension);
}
[Fact]
@@ -90,12 +88,12 @@ public void ParseEnumFragmentShouldSucceed()
// Assert
Assert.Equivalent(new OpenApiDiagnostic(), diagnostic);
- jsonNodeExtension.Should().BeEquivalentTo(new JsonNodeExtension(
+ OpenApiTestAssert.Equivalent(new JsonNodeExtension(
new JsonArray
{
"foo",
"baz"
- }), options => options.IgnoringCyclicReferences());
+ }), jsonNodeExtension);
}
[Fact]
@@ -254,7 +252,7 @@ public void ParseBasicSchemaWithExampleShouldSucceed()
// Assert
Assert.Equivalent(new OpenApiDiagnostic(), diagnostic);
- schema.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiSchema
{
Type = JsonSchemaType.Object,
@@ -279,12 +277,7 @@ public void ParseBasicSchemaWithExampleShouldSucceed()
["name"] = new JsonNodeExtension("Puma").Node,
["id"] = new JsonNodeExtension(1).Node
}
- }, options => options
- .IgnoringCyclicReferences()
- .Excluding((IMemberInfo memberInfo) =>
- memberInfo.Path.EndsWith("Parent"))
- .Excluding((IMemberInfo memberInfo) =>
- memberInfo.Path.EndsWith("Root")));
+ }, schema, nameof(JsonNode.Parent), nameof(JsonNode.Root));
}
[Fact]
diff --git a/test/Microsoft.OpenApi.Tests/DefaultSettingsFixture.cs b/test/Microsoft.OpenApi.Tests/DefaultSettingsFixture.cs
deleted file mode 100644
index d2afed0c6..000000000
--- a/test/Microsoft.OpenApi.Tests/DefaultSettingsFixture.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT license.
-
-using FluentAssertions;
-
-namespace Microsoft.OpenApi.Tests
-{
- ///
- /// Fixture containing default settings for external libraries.
- ///
- public class DefaultSettingsFixture
- {
- ///
- /// Initializes an instance of .
- ///
- public DefaultSettingsFixture()
- {
- // We need RespectingRuntimeTypes() to ensure equivalence test works property,
- // given that there are multiple types that can be used for the declared type OpenApiAny.
- // Without this option, properties specific to those types would not be compared.
- AssertionOptions.AssertEquivalencyUsing(
- o => o
- .AllowingInfiniteRecursion()
- .RespectingRuntimeTypes()
- .WithStrictOrdering());
- }
- }
-}
diff --git a/test/Microsoft.OpenApi.Tests/DefaultSettingsFixtureCollection.cs b/test/Microsoft.OpenApi.Tests/DefaultSettingsFixtureCollection.cs
deleted file mode 100644
index 22f562c4d..000000000
--- a/test/Microsoft.OpenApi.Tests/DefaultSettingsFixtureCollection.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT license.
-
-using Xunit;
-
-namespace Microsoft.OpenApi.Tests
-{
- ///
- /// Collection dummy class for .
- ///
- ///
- /// This class is needed in xUnit framework to define collection name
- /// to be used in unit test classes.
- ///
- [CollectionDefinition("DefaultSettings")]
- public class DefaultSettingsFixtureCollection : ICollectionFixture
- {
- }
-}
diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj
index a2b406061..1f127af0d 100644
--- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj
+++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj
@@ -10,7 +10,6 @@
-
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs
index b229279fc..c1815a2d7 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs
@@ -10,7 +10,6 @@
using System.Text.Json.Schema;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.OpenApi.Reader;
using VerifyXunit;
using Xunit;
@@ -637,9 +636,7 @@ public void CloningSchemaExamplesWorks(JsonNode example)
var schemaCopy = schema.CreateShallowCopy();
// Act && Assert
- schema.Example.Should().BeEquivalentTo(schemaCopy.Example, options => options
- .IgnoringCyclicReferences()
- .Excluding(x => x.Options));
+ OpenApiTestAssert.Equivalent(schemaCopy.Example, schema.Example, nameof(JsonNode.Options));
}
#pragma warning restore CS0618
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs
index 8022d1070..47edf9aa9 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs
@@ -6,7 +6,6 @@
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
-using FluentAssertions;
using VerifyXunit;
using Xunit;
using System.Text.Json.Nodes;
@@ -234,14 +233,15 @@ public void SchemesShouldConsiderOnlyReferenceIdForEquality()
Assert.Equal(2, securityRequirement.Count);
- securityRequirement.Should().BeEquivalentTo(
+ OpenApiTestAssert.Equivalent(
new OpenApiSecurityRequirement
{
// This should work with any security scheme object
// as long as Reference.Id os securityScheme1
[new OpenApiSecuritySchemeReference("securityScheme1", null)] = new List(),
[new OpenApiSecuritySchemeReference("securityScheme2", null)] = new List { "scope1", "scope2" },
- });
+ },
+ securityRequirement);
}
}
}
diff --git a/test/Microsoft.OpenApi.Tests/OpenApiTestAssert.cs b/test/Microsoft.OpenApi.Tests/OpenApiTestAssert.cs
new file mode 100644
index 000000000..e9bd68048
--- /dev/null
+++ b/test/Microsoft.OpenApi.Tests/OpenApiTestAssert.cs
@@ -0,0 +1,158 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license.
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Text.Json.Nodes;
+using Xunit;
+
+namespace Microsoft.OpenApi.Tests;
+
+public static class OpenApiTestAssert
+{
+ public static void Equivalent(T expected, T actual, params string[] excludedMemberNames)
+ {
+ Equivalent(expected, actual, path => excludedMemberNames.Contains(path.MemberName));
+ }
+
+ public static void Equivalent(T expected, T actual, Func exclude)
+ {
+ Compare(expected, actual, EquivalencyPath.Root, exclude, new HashSet());
+ }
+
+ public readonly record struct EquivalencyPath(string Value, string MemberName)
+ {
+ public static EquivalencyPath Root { get; } = new(string.Empty, string.Empty);
+
+ public EquivalencyPath Member(string memberName)
+ {
+ var value = string.IsNullOrEmpty(Value) ? memberName : $"{Value}.{memberName}";
+ return new(value, memberName);
+ }
+
+ public EquivalencyPath Index(object index)
+ {
+ return new($"{Value}[{index}]", MemberName);
+ }
+ }
+
+ private static void Compare(object expected, object actual, EquivalencyPath path, Func exclude, HashSet visited)
+ {
+ if (exclude(path))
+ {
+ return;
+ }
+
+ if (expected is null || actual is null)
+ {
+ Assert.Equal(expected, actual);
+ return;
+ }
+
+ if (expected is JsonNode || actual is JsonNode)
+ {
+ var expectedNode = Assert.IsAssignableFrom(expected);
+ var actualNode = Assert.IsAssignableFrom(actual);
+ Assert.True(JsonNode.DeepEquals(expectedNode, actualNode), $"Expected JSON node at '{path.Value}' to be equivalent.");
+ return;
+ }
+
+ var expectedType = expected.GetType();
+ if (IsSimpleType(expectedType))
+ {
+ Assert.Equal(expected, actual);
+ return;
+ }
+
+ if (!expectedType.IsValueType)
+ {
+ var pair = new ReferencePair(expected, actual);
+ if (!visited.Add(pair))
+ {
+ return;
+ }
+ }
+
+ if (expected is IDictionary expectedDictionary && actual is IDictionary actualDictionary)
+ {
+ Assert.Equal(expectedDictionary.Count, actualDictionary.Count);
+ foreach (DictionaryEntry expectedEntry in expectedDictionary)
+ {
+ Assert.True(actualDictionary.Contains(expectedEntry.Key), $"Expected dictionary at '{path.Value}' to contain key '{expectedEntry.Key}'.");
+ Compare(expectedEntry.Value, actualDictionary[expectedEntry.Key], path.Index(expectedEntry.Key), exclude, visited);
+ }
+
+ return;
+ }
+
+ if (expected is IEnumerable expectedEnumerable && actual is IEnumerable actualEnumerable && expected is not string)
+ {
+ var expectedItems = expectedEnumerable.Cast