Skip to content
Permalink
Browse files

Add tests for UrlAttribute, PhoneAttribute, EmailAddressAttribute (#963)

  • Loading branch information...
vanashimko authored and RicoSuter committed May 8, 2019
1 parent c10d51d commit 4e2f2bc844a63a32e420e130c12bbab03beb2ee6
Showing with 18 additions and 51 deletions.
  1. +18 −51 src/NJsonSchema.Tests/Generation/AnnotationsGenerationTests.cs
@@ -341,64 +341,31 @@ public class DataTypeAttributeClass
[DataType(DataType.Url)]
public string Url { get; set; }

#if !LEGACY
[DataType(DataType.Upload)]
public string Upload { get; set; }
#endif
}

[Fact]
public async Task When_DataTypeAttribute_is_DateTime_then_the_format_property_is_datetime()
{
var schema = await JsonSchema4.FromTypeAsync<DataTypeAttributeClass>();
var property = schema.Properties["DateTime"];

Assert.Equal("date-time", property.Format);
}
[EmailAddress] // should be equivalent to [DataType(DataType.EmailAddress)]
public string EmailAddress2 { get; set; }

[Fact]
public async Task When_DataTypeAttribute_is_Date_then_the_format_property_is_date()
{
var schema = await JsonSchema4.FromTypeAsync<DataTypeAttributeClass>();
var property = schema.Properties["Date"];
[Phone] // should be equivalent to [DataType(DataType.PhoneNumber)]
public string PhoneNumber2 { get; set; }

Assert.Equal("date", property.Format);
[Url] // should be equivalent to [DataType(DataType.Url)]
public string Url2 { get; set; }
}

[Fact]
public async Task When_DataTypeAttribute_is_Time_then_the_format_property_is_time()
{
var schema = await JsonSchema4.FromTypeAsync<DataTypeAttributeClass>();
var property = schema.Properties["Time"];

Assert.Equal("time", property.Format);
}

[Fact]
public async Task When_DataTypeAttribute_is_EmailAddress_then_the_format_property_is_email()
{
var schema = await JsonSchema4.FromTypeAsync<DataTypeAttributeClass>();
var property = schema.Properties["EmailAddress"];

Assert.Equal("email", property.Format);
}

[Fact]
public async Task When_DataTypeAttribute_is_PhoneNumber_then_the_format_property_is_phone()
{
var schema = await JsonSchema4.FromTypeAsync<DataTypeAttributeClass>();
var property = schema.Properties["PhoneNumber"];

Assert.Equal("phone", property.Format);
}

[Fact]
public async Task When_DataTypeAttribute_is_Url_then_the_format_property_is_uri()
[Theory]
[InlineData(nameof(DataTypeAttributeClass.EmailAddress), "email")]
[InlineData(nameof(DataTypeAttributeClass.PhoneNumber), "phone")]
[InlineData(nameof(DataTypeAttributeClass.DateTime), "date-time")]
[InlineData(nameof(DataTypeAttributeClass.Time), "time")]
[InlineData(nameof(DataTypeAttributeClass.Url), "uri")]
[InlineData(nameof(DataTypeAttributeClass.EmailAddress2), "email")]
[InlineData(nameof(DataTypeAttributeClass.PhoneNumber2), "phone")]
[InlineData(nameof(DataTypeAttributeClass.Url2), "uri")]
public async Task When_DataTypeAttribute_is_set_then_the_format_property_should_come_from_the_attribute(string propertyName, string expectedFormat)
{
var schema = await JsonSchema4.FromTypeAsync<DataTypeAttributeClass>();
var property = schema.Properties["Url"];
var property = schema.Properties[propertyName];

Assert.Equal("uri", property.Format);
Assert.Equal(expectedFormat, property.Format);
}

[JsonSchemaIgnore]

0 comments on commit 4e2f2bc

Please sign in to comment.
You can’t perform that action at this time.