internal void GenericEvents(ConfiguratorFake c) { WHEN["scanning a generic event"] = () => c = Scan(typeof(GenericEvent <>), typeof(DataClass1), typeof(DataClass2)); THEN["RegisterGenericArgument is called"] = () => c.Class(typeof(GenericEvent <>)).GenericArguments.Should().BeEquivalentTo(typeof(DataClass1), typeof(DataClass2)); WHEN["scanning a generic event without GenericArguments", ThenIsThrown <ConfigurationException>()] = () => Scan(typeof(GenericClassWithoutArgs <string>)); WHEN["scanning a generic class without a Name"] = () => c = Scan(typeof(GenericEvent <>), typeof(DataClass1), typeof(DataClass2)); THEN["it is registered with its simple class name"] = () => c.ClassNames.Should().Contain("SerializationFeatureGenericEvent"); }
internal void PropertyMappings(ConfiguratorFake c, ClassConfiguratorFake cc) { WHEN["scanning a class"] = () => cc = (c = Scan(typeof(SimpleEvent))).Class <SimpleEvent>(); THEN["the Name attribute is considered"] = () => cc.PropertyNames.Should().Contain("TestName"); WHEN["scanning a class with well known property types"] = () => cc = Scan(typeof(EventWithProperties)).Class <EventWithProperties>(); THEN["all public properties are mapped"] = () => cc.PropertyNames.Should().BeEquivalentTo("StringProperty", "UriProperty", "ListProperty", "StructProperty", "ObjectProperty"); WHEN["scanning a derived class"] = () => c = Scan(typeof(DerivedEvent), typeof(BaseEvent), typeof(TestEvent)); THEN["only the declared properties are mapped"] = () => { c.Class <BaseEvent>().PropertyNames.Should().Contain(nameof(BaseEvent.BaseProperty)); c.Class <DerivedEvent>().PropertyNames.Should().Contain(nameof(DerivedEvent.DerivedProperty)); }; WHEN["scanning an event with a data class property"] = () => cc = Scan(typeof(EventWithDataClass), typeof(DataClass1)).Class <EventWithDataClass>(); THEN["it is correctly mapped"] = () => cc.PropertyNames.Should().BeEquivalentTo(nameof(EventWithDataClass.DataClassProperty)); WHEN["a data class references a type that is not marked as data class"] = null; THEN["Scan", ThrowsA <ConfigurationException>()] = () => c = Scan(typeof(ClassWithInvalidProperty), typeof(ClassWithoutContractAttribute)); }