Skip to content

Commit 210450f

Browse files
committed
Update tests
1 parent d19e4c2 commit 210450f

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

src/OpenApi/test/OpenApiGeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void AddsMultipleResponseFormatsFromMetadataWithPoco()
170170
var content = Assert.Single(createdResponseType.Content);
171171

172172
Assert.NotNull(createdResponseType);
173-
Assert.Equal("object", content.Value.Schema.Type);
173+
Assert.Equal("string", content.Value.Schema.Type);
174174
Assert.Equal("application/json", createdResponseType.Content.Keys.First());
175175

176176
var badRequestResponseType = responses["400"];
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections;
5+
using System.Text.Json.Nodes;
6+
using Microsoft.AspNetCore.OpenApi;
7+
8+
namespace Microsoft.AspNetCore.OpenApi.Tests;
9+
10+
public class OpenApiSchemaGeneratorTests
11+
{
12+
[Theory]
13+
[InlineData(typeof(Dictionary<string, string>))]
14+
[InlineData(typeof(Todo))]
15+
public void CanGenerateCorrectSchemaForDictionaryTypes(Type type)
16+
{
17+
var schema = OpenApiSchemaGenerator.GetOpenApiSchema(type);
18+
Assert.NotNull(schema);
19+
Assert.Equal("object", schema.Type);
20+
}
21+
22+
[Theory]
23+
[InlineData(typeof(IList<string>))]
24+
[InlineData(typeof(Products))]
25+
public void CanGenerateSchemaForListTypes(Type type)
26+
{
27+
var schema = OpenApiSchemaGenerator.GetOpenApiSchema(type);
28+
Assert.NotNull(schema);
29+
Assert.Equal("array", schema.Type);
30+
}
31+
32+
[Theory]
33+
[InlineData(typeof(DateTime))]
34+
[InlineData(typeof(DateTimeOffset))]
35+
public void CanGenerateSchemaForDateTimeTypes(Type type)
36+
{
37+
var schema = OpenApiSchemaGenerator.GetOpenApiSchema(type);
38+
Assert.NotNull(schema);
39+
Assert.Equal("string", schema.Type);
40+
Assert.Equal("date-time", schema.Format);
41+
}
42+
43+
[Fact]
44+
public void CanGenerateSchemaForDateSpanTypes()
45+
{
46+
var schema = OpenApiSchemaGenerator.GetOpenApiSchema(typeof(TimeSpan));
47+
Assert.NotNull(schema);
48+
Assert.Equal("string", schema.Type);
49+
Assert.Equal("date-span", schema.Format);
50+
}
51+
52+
class Todo : Dictionary<string, object> { }
53+
class Products : IList<int>
54+
{
55+
public int this[int index] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
56+
57+
public int Count => throw new NotImplementedException();
58+
59+
public bool IsReadOnly => throw new NotImplementedException();
60+
61+
public void Add(int item)
62+
{
63+
throw new NotImplementedException();
64+
}
65+
66+
public void Clear()
67+
{
68+
throw new NotImplementedException();
69+
}
70+
71+
public bool Contains(int item)
72+
{
73+
throw new NotImplementedException();
74+
}
75+
76+
public void CopyTo(int[] array, int arrayIndex)
77+
{
78+
throw new NotImplementedException();
79+
}
80+
81+
public IEnumerator<int> GetEnumerator()
82+
{
83+
throw new NotImplementedException();
84+
}
85+
86+
public int IndexOf(int item)
87+
{
88+
throw new NotImplementedException();
89+
}
90+
91+
public void Insert(int index, int item)
92+
{
93+
throw new NotImplementedException();
94+
}
95+
96+
public bool Remove(int item)
97+
{
98+
throw new NotImplementedException();
99+
}
100+
101+
public void RemoveAt(int index)
102+
{
103+
throw new NotImplementedException();
104+
}
105+
106+
IEnumerator IEnumerable.GetEnumerator()
107+
{
108+
throw new NotImplementedException();
109+
}
110+
}
111+
}

0 commit comments

Comments
 (0)