private DefaultSortingTransformer GetTransformer() { var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); var registry = new ResourceTypeRegistry(); registry.AddRegistration(registrar.BuildRegistration(typeof(Dummy), "dummies")); registry.AddRegistration(registrar.BuildRegistration(typeof(Dummy2), "dummy2s")); return(new DefaultSortingTransformer(registry)); }
private DefaultFilteringTransformer GetTransformer() { var pluralizationService = new PluralizationService(new Dictionary <string, string> { { "Dummy", "Dummies" } }); var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(pluralizationService)); var registry = new ResourceTypeRegistry(); registry.AddRegistration(registrar.BuildRegistration(typeof(Dummy))); registry.AddRegistration(registrar.BuildRegistration(typeof(RelatedItemWithId))); return(new DefaultFilteringTransformer(registry)); }
public void BuildRegistration_sets_up_correct_attribute_for_to_one_complex_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttributeHelper(reg, "to-one-complex-type-field", new JObject { { "intProp", 32 }, { "StringProp", "qux" } }, grabBag => { grabBag.ToOneComplexTypeField.Should().NotBeNull(); grabBag.ToOneComplexTypeField.IntProp.Should().Be(32); grabBag.ToOneComplexTypeField.StringProp.Should().Be("qux"); }, token => { ((int)token["intProp"]).Should().Be(32); ((string)token["StringProp"]).Should().Be("qux"); }); AssertAttribute(reg, "to-one-complex-type-field", null, null, (SampleComplexType)null, g => g.ToOneComplexTypeField); }
public void BuildRegistration_sets_up_correct_attribute_for_string_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttribute(reg, "string-field", "asdf", "asdf", "asdf", g => g.StringField); AssertAttribute(reg, "string-field", null, null, (string)null, g => g.StringField); }
public void BuildRegistration_sets_up_correct_attribute_for_nullable_enum_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttribute(reg, "nullable-enum-field", (int)SampleEnum.Value1, SampleEnum.Value1, (int)SampleEnum.Value1, g => g.NullableEnumField); AssertAttribute(reg, "nullable-enum-field", null, null, (SampleEnum?)null, g => g.NullableEnumField); }
public void BuildRegistration_sets_up_correct_attribute_for_Double_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttribute(reg, "double-field", 0d, 0d, 0d, g => g.DoubleField); AssertAttribute(reg, "double-field", 20000000000.1234d, 20000000000.1234d, 20000000000.1234d, g => g.DoubleField); AssertAttribute(reg, "double-field", null, 0d, 0d, g => g.DoubleField); }
public void BuildRegistration_sets_up_correct_attribute_for_nullable_UInt64_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttribute(reg, "nullable-uint64-field", 0, (UInt64?)0, (UInt64?)0, g => g.NullableUint64Field); AssertAttribute(reg, "nullable-uint64-field", 20000000000, (UInt64?)20000000000, (UInt64?)20000000000, g => g.NullableUint64Field); AssertAttribute(reg, "nullable-uint64-field", null, null, (UInt64?)null, g => g.NullableUint64Field); }
public void BuildRegistration_sets_up_correct_attribute_for_UInt16_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttribute(reg, "uint16-field", 0, 0, 0, g => g.Uint16Field); AssertAttribute(reg, "uint16-field", 4000, 4000, 4000, g => g.Uint16Field); AssertAttribute(reg, "uint16-field", null, 0, 0, g => g.Uint16Field); }
public void BuildRegistration_sets_up_correct_attribute_for_nullable_boolean_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttribute(reg, "nullable-boolean-field", false, false, false, g => g.NullableBooleanField); AssertAttribute(reg, "nullable-boolean-field", true, true, true, g => g.NullableBooleanField); AssertAttribute(reg, "nullable-boolean-field", null, null, (Boolean?)null, g => g.NullableBooleanField); }
public void Cant_register_type_with_two_properties_with_the_same_name() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); Type saladType = typeof(Salad); // Act Action action = () => registrar.BuildRegistration(saladType); // Assert action.ShouldThrow <InvalidOperationException>().Which.Message.Should() .Be("Failed to register type `Salad` because contains multiple properties that would serialize as `salad-type`."); }
public void Cant_register_type_with_non_id_property_called_id() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act Action action = () => registrar.BuildRegistration(typeof(Continent)); // Assert action.ShouldThrow <InvalidOperationException>() .Which.Message.Should() .Be("Failed to register type `Continent` because it contains a non-id property that would serialize as \"id\"."); }
public void Cant_register_type_with_missing_id() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act Action action = () => registrar.BuildRegistration(typeof(InvalidModel)); // Assert action.ShouldThrow <InvalidOperationException>() .Which.Message.Should() .Be("Unable to determine Id property for type `InvalidModel`."); }
public void BuildRegistration_sets_up_correct_attribute_for_nullable_Decimal_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttribute(reg, "nullable-decimal-field", "0", 0m, "0", g => g.NullableDecimalField); AssertAttribute(reg, "nullable-decimal-field", "20000000000.1234", 20000000000.1234m, "20000000000.1234", g => g.NullableDecimalField); AssertAttribute(reg, "nullable-decimal-field", null, null, (string)null, g => g.NullableDecimalField); }
public void BuildRegistration_sets_up_correct_attribute_for_nullable_DateTime_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttribute(reg, "nullable-date-time-field", "1776-07-04", new DateTime(1776, 07, 04, 0, 0, 0, DateTimeKind.Utc), "1776-07-04T00:00:00", g => g.NullableDateTimeField); AssertAttribute(reg, "nullable-date-time-field", "1776-07-04T00:00:00", new DateTime(1776, 07, 04, 0, 0, 0, DateTimeKind.Utc), "1776-07-04T00:00:00", g => g.NullableDateTimeField); AssertAttribute(reg, "nullable-date-time-field", null, null, (DateTime?)null, g => g.NullableDateTimeField); }
public void BuildRegistration_sets_up_correct_attribute_for_nullable_SByte_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttribute(reg, "nullable-sbyte-field", 0, (SByte?)0, (SByte?)0, g => g.NullableSbyteField); AssertAttribute(reg, "nullable-sbyte-field", 12, (SByte?)12, (SByte?)12, g => g.NullableSbyteField); AssertAttribute(reg, "nullable-sbyte-field", -12, (SByte?)-12, (SByte?)-12, g => g.NullableSbyteField); AssertAttribute(reg, "nullable-sbyte-field", null, null, (SByte?)null, g => g.NullableSbyteField); }
public void BuildRegistration_sets_up_correct_attribute_for_nullable_Single_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttribute(reg, "nullable-single-field", 0f, 0f, 0f, g => g.NullableSingleField); AssertAttribute(reg, "nullable-single-field", 20000000000.1234f, 20000000000.1234f, (Int64?)20000000000.1234f, g => g.NullableSingleField); AssertAttribute(reg, "nullable-single-field", -20000000000.1234f, -20000000000.1234f, -20000000000.1234f, g => g.NullableSingleField); AssertAttribute(reg, "nullable-single-field", null, null, (Single?)null, g => g.NullableSingleField); }
public void BuildRegistration_sets_up_correct_attribute_for_nullable_guid_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert var guid = new Guid("6566f9b4-5245-40de-890d-98b40a4ad656"); AssertAttribute(reg, "nullable-guid-field", "6566f9b4-5245-40de-890d-98b40a4ad656", guid, "6566f9b4-5245-40de-890d-98b40a4ad656", g => g.NullableGuidField); AssertAttribute(reg, "nullable-guid-field", null, null, (Guid?)null, g => g.NullableGuidField); }
public void BuildRegistration_sets_up_correct_attribute_for_nullable_DateTimeOffset_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert var testDateTimeOffset = new DateTimeOffset(new DateTime(1776, 07, 04), TimeSpan.FromHours(-5)); AssertAttribute(reg, "nullable-date-time-offset-field", "1776-07-04T00:00:00-05:00", testDateTimeOffset, "1776-07-04T00:00:00.0000000-05:00", g => g.NullableDateTimeOffsetField); AssertAttribute(reg, "nullable-date-time-offset-field", null, null, (DateTimeOffset?)null, g => g.NullableDateTimeOffsetField); }
public void BuildRegistration_sets_up_correct_attribute_for_Decimal_field_non_en_US() { // Set up non US culture var culture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo("se-SE"); // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); AssertAttribute(reg, "decimal-field", "20000000000.1234", 20000000000.1234m, "20000000000.1234", g => g.DecimalField); Thread.CurrentThread.CurrentCulture = culture; }
public void BuildRegistration_sets_up_correct_attribute_for_DateTimeOffset_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert var testDateTimeOffset1 = new DateTimeOffset(new DateTime(1776, 07, 04), TimeSpan.FromHours(-5)); var testDateTimeOffset2 = new DateTimeOffset(new DateTime(1776, 07, 04, 12, 30, 0), TimeSpan.FromHours(0)); var testDateTimeOffset3 = new DateTimeOffset(new DateTime(2015, 03, 11, 04, 31, 0), TimeSpan.FromHours(0)); AssertAttribute(reg, "date-time-offset-field", "1776-07-04T00:00:00-05:00", testDateTimeOffset1, "1776-07-04T00:00:00.0000000-05:00", g => g.DateTimeOffsetField); AssertAttribute(reg, "date-time-offset-field", "1776-07-04T12:30:00+00:00", testDateTimeOffset2, "1776-07-04T12:30:00.0000000+00:00", g => g.DateTimeOffsetField); AssertAttribute(reg, "date-time-offset-field", "2015-03-11T04:31:00.0000000+00:00", testDateTimeOffset3, "2015-03-11T04:31:00.0000000+00:00", g => g.DateTimeOffsetField); AssertAttribute(reg, "date-time-offset-field", null, new DateTimeOffset(), "0001-01-01T00:00:00.0000000+00:00", g => g.DateTimeOffsetField); }
public void BuildRegistration_sets_up_correct_attribute_for_to_many_complex_field() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var reg = registrar.BuildRegistration(typeof(AttributeGrabBag)); // Assert AssertAttributeHelper(reg, "to-many-complex-type-field", new JArray { new JObject { { "intProp", 49 }, { "StringProp", "blue" } }, new JObject { { "intProp", 67 }, { "StringProp", "orange" } } }, grabBag => { var result = grabBag.ToManyComplexTypeField.ToArray(); result.Length.Should().Be(2); result[0].IntProp.Should().Be(49); result[0].StringProp.Should().Be("blue"); result[1].IntProp.Should().Be(67); result[1].StringProp.Should().Be("orange"); }, token => { var jarray = (JArray)token; jarray.Count.Should().Be(2); ((int)jarray[0]["intProp"]).Should().Be(49); ((string)jarray[0]["StringProp"]).Should().Be("blue"); ((int)jarray[1]["intProp"]).Should().Be(67); ((string)jarray[1]["StringProp"]).Should().Be("orange"); }); AssertAttribute(reg, "to-many-complex-type-field", null, null, (SampleComplexType[])null, g => g.ToManyComplexTypeField); }
public void BuildRegistration_sets_up_registration_correctly() { // Arrange var registrar = new ResourceTypeRegistrar(new DefaultNamingConventions(new PluralizationService())); // Act var postReg = registrar.BuildRegistration(typeof(Post)); // Assert postReg.IdProperty.Should().BeSameAs(typeof(Post).GetProperty("Id")); postReg.ResourceTypeName.Should().Be("posts"); postReg.Attributes.Length.Should().Be(1); postReg.Attributes.First().Property.Should().BeSameAs(typeof(Post).GetProperty("Title")); postReg.Relationships.Length.Should().Be(2); postReg.Relationships[0].IsToMany.Should().BeFalse(); postReg.Relationships[0].Property.Should().BeSameAs(typeof(Post).GetProperty("Author")); postReg.Relationships[0].SelfLinkTemplate.Should().BeNull(); postReg.Relationships[0].RelatedResourceLinkTemplate.Should().BeNull(); postReg.Relationships[1].IsToMany.Should().BeTrue(); postReg.Relationships[1].Property.Should().BeSameAs(typeof(Post).GetProperty("Comments")); postReg.Relationships[1].SelfLinkTemplate.Should().Be("/posts/{1}/relationships/comments"); postReg.Relationships[1].RelatedResourceLinkTemplate.Should().Be("/posts/{1}/comments"); }