Skip to content

Commit c3d6161

Browse files
committed
Add test to validate; remove commented out code
1 parent 79ff30c commit c3d6161

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Globalization;
67
using System.IO;
@@ -1670,27 +1671,6 @@ private static OpenApiDocument ParseInputFile(string filePath)
16701671
return openApiDoc;
16711672
}
16721673

1673-
//[Fact]
1674-
//public void CopyConstructorForAdvancedDocumentWorks()
1675-
//{
1676-
// // Arrange & Act
1677-
// var doc = new OpenApiDocument(AdvancedDocument);
1678-
1679-
// var docOpId = doc.Paths["/pets"].Operations[OperationType.Get].OperationId = "findAllMyPets";
1680-
// var advancedDocOpId = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].OperationId;
1681-
// var responseSchemaTypeCopy = doc.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema.Type = "object";
1682-
// var advancedDocResponseSchemaType = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema.Type;
1683-
1684-
// // Assert
1685-
// Assert.NotNull(doc.Info);
1686-
// Assert.NotNull(doc.Servers);
1687-
// Assert.NotNull(doc.Paths);
1688-
// Assert.Equal(2, doc.Paths.Count);
1689-
// Assert.NotNull(doc.Components);
1690-
// Assert.NotEqual(docOpId, advancedDocOpId);
1691-
// Assert.NotEqual(responseSchemaTypeCopy, advancedDocResponseSchemaType);
1692-
//}
1693-
16941674
[Fact]
16951675
public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFormat()
16961676
{
@@ -1858,5 +1838,38 @@ public void OpenApiDocumentCopyConstructorWithAnnotationsSucceeds()
18581838

18591839
Assert.NotEqual(baseDocument.Annotations["key1"], actualDocument.Annotations["key1"]);
18601840
}
1861-
}
1841+
1842+
[Fact]
1843+
public void SerializeExamplesDoesNotThrowNullReferenceException()
1844+
{
1845+
OpenApiDocument doc = new OpenApiDocument
1846+
{
1847+
Paths = new OpenApiPaths
1848+
{
1849+
["test"] = new OpenApiPathItem()
1850+
{
1851+
Operations = new Dictionary<OperationType, OpenApiOperation>()
1852+
{
1853+
[OperationType.Post] = new OpenApiOperation
1854+
{
1855+
RequestBody = new OpenApiRequestBody()
1856+
{
1857+
Content =
1858+
{
1859+
["application/json"] = new OpenApiMediaType()
1860+
{
1861+
Examples = null,
1862+
},
1863+
}
1864+
}
1865+
},
1866+
}
1867+
},
1868+
}
1869+
};
1870+
1871+
OpenApiJsonWriter apiWriter = new OpenApiJsonWriter(new StringWriter());
1872+
doc.Invoking(d => d.SerializeAsV3(apiWriter)).Should().NotThrow();
1873+
}
1874+
}
18621875
}

0 commit comments

Comments
 (0)