internal void StreamNames(ConfiguratorFake c) { WHEN["scanning a class with StreamAttribute and Name"] = () => c = Scan(typeof(SampleStreamWithName));; THEN["its configured name is used"] = () => c.StreamName.Should().Be("TestName"); WHEN["scanning a class with StreamAttribute without Name"] = () => c = Scan(typeof(SampleStream));; THEN["its class name is used"] = () => c.StreamName.Should().Be("SampleStream"); }
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)); }
internal void ScanningForNestedClasses(ConfiguratorFake c) { WHEN["scanning a type that contains nested event classes"] = () => c = Scan(typeof(ContainerClass)); THEN["the nested classes are also found"] = () => c.ClassNames.Should().Contain("TestName"); }
internal void EventNames(Type eventType, string expectedName, ConfiguratorFake c) { WHEN["scaning a certain event"] = () => c = Scan(eventType); THEN["RegisterEventClass is called with the expected name"] = () => c.ClassName.Should().Be(expectedName); }
private ConfiguratorFake Scan(params Type[] types) { var c = new ConfiguratorFake(); return(c); }