Skip to content

Commit 31a3cd9

Browse files
committed
Add test cases for external docs and response
1 parent 620b0f2 commit 31a3cd9

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System.Collections.Generic;
5+
using Microsoft.OpenApi.Models;
6+
using Microsoft.OpenApi.Validations;
7+
using Xunit;
8+
9+
namespace Microsoft.OpenApi.Tests.Models
10+
{
11+
public class OpenApiExternalDocsValidationTests
12+
{
13+
[Fact]
14+
public void ValidateUrlIsRequiredInExternalDocs()
15+
{
16+
// Arrange
17+
IEnumerable<ValidationError> errors;
18+
OpenApiExternalDocs externalDocs = new OpenApiExternalDocs();
19+
20+
// Act
21+
bool result = externalDocs.Validate(out errors);
22+
23+
// Assert
24+
Assert.False(result);
25+
Assert.NotNull(errors);
26+
ValidationError error = Assert.Single(errors);
27+
Assert.Equal("The field 'url' in 'External Documentation' object is REQUIRED.", error.ErrorMessage);
28+
}
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System.Collections.Generic;
5+
using Microsoft.OpenApi.Models;
6+
using Microsoft.OpenApi.Validations;
7+
using Xunit;
8+
9+
namespace Microsoft.OpenApi.Tests.Models
10+
{
11+
public class OpenApiResponseValidationTests
12+
{
13+
[Fact]
14+
public void ValidateDescriptionIsRequiredInResponse()
15+
{
16+
// Arrange
17+
IEnumerable<ValidationError> errors;
18+
OpenApiResponse response = new OpenApiResponse();
19+
20+
// Act
21+
bool result = response.Validate(out errors);
22+
23+
// Assert
24+
Assert.False(result);
25+
Assert.NotNull(errors);
26+
ValidationError error = Assert.Single(errors);
27+
Assert.Equal("The field 'description' in 'response' object is REQUIRED.", error.ErrorMessage);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)