Skip to content

Commit e7c999c

Browse files
Add Unit tests to validate property type text ✅
1 parent a08bb18 commit e7c999c

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Linq;
2+
using System.Runtime.Serialization;
3+
4+
namespace Notion.Client.Extensions
5+
{
6+
public static class EnumExtensions
7+
{
8+
public static string GetEnumMemberValue<T>(this T enumValue) where T : System.Enum
9+
{
10+
var enumType = typeof(T);
11+
var memInfo = enumType.GetMember(enumValue.ToString());
12+
var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType<EnumMemberAttribute>().FirstOrDefault();
13+
14+
if (attr != null)
15+
{
16+
return attr.Value;
17+
}
18+
19+
return null;
20+
}
21+
}
22+
}

Test/Notion.UnitTests/PropertyTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Notion.Client;
3+
using Notion.Client.Extensions;
34
using Xunit;
45

56
namespace Notion.UnitTests
@@ -33,5 +34,33 @@ public void TestPropertyType(Type type, PropertyType expectedPropertyType)
3334

3435
Assert.Equal(expectedPropertyType, actualPropertyType);
3536
}
37+
38+
[Theory]
39+
[InlineData(typeof(CheckboxProperty), "checkbox")]
40+
[InlineData(typeof(CreatedByProperty), "created_by")]
41+
[InlineData(typeof(CreatedTimeProperty), "created_time")]
42+
[InlineData(typeof(DateProperty), "date")]
43+
[InlineData(typeof(EmailProperty), "email")]
44+
[InlineData(typeof(FileProperty), "file")]
45+
[InlineData(typeof(FormulaProperty), "formula")]
46+
[InlineData(typeof(LastEditedByProperty), "last_edited_by")]
47+
[InlineData(typeof(LastEditedTimeProperty), "last_edited_time")]
48+
[InlineData(typeof(NumberProperty), "number")]
49+
[InlineData(typeof(PeopleProperty), "people")]
50+
[InlineData(typeof(PhoneNumberProperty), "phone_number")]
51+
[InlineData(typeof(RelationProperty), "relation")]
52+
[InlineData(typeof(RichTextProperty), "rich_text")]
53+
[InlineData(typeof(RollupProperty), "rollup")]
54+
[InlineData(typeof(SelectProperty), "select")]
55+
[InlineData(typeof(TitleProperty), "title")]
56+
[InlineData(typeof(UrlProperty), "url")]
57+
public void TestPropertyTypeText(Type type, string expectedPropertyType)
58+
{
59+
var typeInstance = (Property)Activator.CreateInstance(type);
60+
61+
var actualPropertyType = typeInstance.Type.GetEnumMemberValue();
62+
63+
Assert.Equal(expectedPropertyType, actualPropertyType);
64+
}
3665
}
3766
}

0 commit comments

Comments
 (0)