Skip to content

Commit f24b86f

Browse files
authored
new content-type support
1 parent cca7e9f commit f24b86f

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.3.9</Version>
3+
<Version>0.3.10</Version>
44
</PropertyGroup>
55
</Project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using QAToolKit.Core.Exceptions;
2+
using QAToolKit.Core.Models;
3+
using Xunit;
4+
5+
namespace QAToolKit.Core.Test.Models
6+
{
7+
public class ContentTypeTextJsonTests
8+
{
9+
[Fact]
10+
public void ContentTypeTextJsonTestsPresent_Success()
11+
{
12+
Assert.Equal("text/json", ContentType.TextJson.Value());
13+
}
14+
15+
[Theory]
16+
[InlineData("text/json")]
17+
public void ContentTypeTextJsonFromString_Success(string value)
18+
{
19+
Assert.Equal(ContentType.TextJson, ContentType.From(value));
20+
}
21+
22+
[Theory]
23+
[InlineData("")]
24+
[InlineData(null)]
25+
[InlineData("somestring")]
26+
public void ConvertFromString_Fails(string value)
27+
{
28+
Assert.Throws<QAToolKitCoreException>(() => ContentType.From(value));
29+
}
30+
31+
[Theory]
32+
[InlineData(ContentType.Enumeration.TextJson)]
33+
public void ConverTextJsonFromEnum_Success(ContentType.Enumeration value)
34+
{
35+
Assert.Equal(ContentType.TextJson, ContentType.From(value));
36+
}
37+
38+
[Fact]
39+
public void ConvertTextJsonObjectToString_Success()
40+
{
41+
Assert.Equal("text/json", ContentType.TextJson.Value());
42+
}
43+
44+
[Fact]
45+
public void ConvertTextJsonObjectToEnum_Success()
46+
{
47+
Assert.Equal(ContentType.Enumeration.TextJson, ContentType.ToEnum(ContentType.TextJson));
48+
}
49+
50+
[Fact]
51+
public void ConvertTextJsonStringToEnum_Success()
52+
{
53+
Assert.Equal(ContentType.Enumeration.TextJson, ContentType.ToEnum("text/json"));
54+
}
55+
56+
[Theory]
57+
[InlineData("")]
58+
[InlineData(null)]
59+
[InlineData("somestring")]
60+
public void ConvertStringToEnum_Fails(string value)
61+
{
62+
Assert.Throws<QAToolKitCoreException>(() => ContentType.ToEnum(value));
63+
}
64+
65+
[Fact]
66+
public void ConvertTextJsonStringToContentType_Success()
67+
{
68+
Assert.Equal(ContentType.TextJson, ContentType.From("text/json"));
69+
}
70+
}
71+
}

src/QAToolKit.Core/Models/ContentType.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ public enum Enumeration
3535
/// <summary>
3636
/// text/plain content type
3737
/// </summary>
38-
TextPlain
38+
TextPlain,
39+
/// <summary>
40+
/// text/json content type
41+
/// </summary>
42+
TextJson
3943
}
4044

4145
private readonly string _value;
@@ -64,6 +68,10 @@ public enum Enumeration
6468
/// text/plain content type
6569
/// </summary>
6670
public static readonly ContentType TextPlain = new ContentType("text/plain");
71+
/// <summary>
72+
/// text/json content type
73+
/// </summary>
74+
public static readonly ContentType TextJson = new ContentType("text/json");
6775

6876
/// <summary>
6977
/// Content type constructor
@@ -103,6 +111,7 @@ public static ContentType From(string value)
103111
"application/octet-stream" => OctetStream,
104112
"multipart/form-data" => MultipartFormData,
105113
"text/plain" => TextPlain,
114+
"text/json" => TextJson,
106115
_ => throw new QAToolKitCoreException($"{value} is invalid content type. Check the documentation which types are supported."),
107116
};
108117
}
@@ -122,6 +131,7 @@ public static ContentType From(Enumeration value)
122131
Enumeration.OctetStream => OctetStream,
123132
Enumeration.MultipartFormData => MultipartFormData,
124133
Enumeration.TextPlain => TextPlain,
134+
Enumeration.TextJson => TextJson,
125135
_ => throw new QAToolKitCoreException($"{value} is invalid content type. Check the documentation which types are supported."),
126136
};
127137
}
@@ -146,6 +156,7 @@ public static Enumeration ToEnum(ContentType value)
146156
"application/octet-stream" => Enumeration.OctetStream,
147157
"multipart/form-data" => Enumeration.MultipartFormData,
148158
"text/plain" => Enumeration.TextPlain,
159+
"text/json" => Enumeration.TextJson,
149160
_ => throw new QAToolKitCoreException($"{value} is invalid content type. Check the documentation which types are supported."),
150161
};
151162
}
@@ -170,6 +181,7 @@ public static Enumeration ToEnum(string value)
170181
"application/octet-stream" => Enumeration.OctetStream,
171182
"multipart/form-data" => Enumeration.MultipartFormData,
172183
"text/plain" => Enumeration.TextPlain,
184+
"text/json" => Enumeration.TextJson,
173185
_ => throw new QAToolKitCoreException($"{value} is invalid content type. Check the documentation which types are supported."),
174186
};
175187
}

0 commit comments

Comments
 (0)