private FileNode(NodeType nodeType, Type type, Encoding encoding, Options options) { _type = type.ToCachedType(); if (nodeType != NodeType.Array || !_type.IsEnumerable) throw new BenderException("Only arrays can be serialized."); _encoding = encoding ?? DefaultEncoding; _options = options; }
public FileNode(NodeType nodeType, Type type, Options options) { _options = options; _type = type.ToCachedType(); if (nodeType != NodeType.Array || !_type.IsEnumerable) throw new BenderException("Only arrays can be serialized."); _rows = new List<RowNode>(); }
public void should_set_simple_types(Type type, object value) { var result = new SimpleValue(type.ToCachedType()); new ValueNode(CreateContext(Mode.Deserialize), null, result, null, null).Value = value; result.Instance.ShouldEqual(value); }
public void should_fail_to_set_null_on_value_types(Type type) { Assert.Throws<ValueCannotBeNullDeserializationException>(() => new ValueNode(CreateContext(Mode.Deserialize), null, new SimpleValue(type.ToCachedType()), null, null).Value = null); }
public void should_fail_to_parse_invalid_string_values_and_return_friendly_message(Type type, object value) { if (type.Is<string>()) return; var messageType = type.GetUnderlyingNullableType(); messageType = messageType.IsEnum ? typeof(Enum) : messageType; Assert.Throws<ValueParseException>(() => new ValueNode(CreateContext(Mode.Deserialize), null, new SimpleValue(type.ToCachedType()), null, null).Value = "yada") .FriendlyMessage.ShouldEqual(Options.Create().Deserialization .FriendlyParseErrorMessages[messageType].ToFormat("yada")); }
public void should_set_null_on_nullable_types_when_empty_string_is_passed(Type type) { var value = new SimpleValue(type.ToCachedType()); new ValueNode(CreateContext(Mode.Deserialize), null, value, null, null).Value = ""; value.Instance.ShouldBeNull(); }
public void should_enumerate_members_on_specified_type(Type type, Mode mode, int count) { var nodes = CreateAccessModifierNode(value: new SimpleValue(ConcreteTypeInstance, type.ToCachedType()), mode: mode).ToList(); nodes.ShouldTotal(count); }
public void should_exclude_generic_ilist_members(Type actualType, Type specifiedType) { var nodes = CreateAccessModifierNode(Options.Create(x => x.TreatEnumerableImplsAsObjects().IncludePublicFields()), new SimpleValue(actualType.CreateInstance(), specifiedType.ToCachedType())).ToList(); nodes.ShouldTotal(2); nodes.ShouldContainNode("Property"); nodes.ShouldContainNode("Field"); }
public void should_exclude_collection_interface_members(Type actualType, Type specifiedType) { var nodes = CreateAccessModifierNode(Options.Create(x => x.TreatDictionaryImplsAsObjects().IncludePublicFields()), new SimpleValue(actualType.CreateInstance(), specifiedType.ToCachedType())).ToList(); nodes.ShouldTotal(0); }
public void should_create_collection_interfaces(Type specifiedType, Type resultingType) { var result = ObjectFactory.CreateInstance(specifiedType.ToCachedType()); result.ShouldNotBeNull(); result.ShouldBeType(resultingType); }
public void should_fail_to_create_simple_types(Type type) { Assert.Throws<SimpleTypeInstantiationNotSupportedException>(() => ObjectFactory.CreateInstance(type.ToCachedType())) .Message.ShouldEqual(SimpleTypeInstantiationNotSupportedException.MessageFormat.ToFormat(type.GetFriendlyTypeFullName())); }
public void should_indicate_if_a_type_is_not_a_clr_collection(Type type) { type.ToCachedType().IsBclCollectionType.ShouldBeFalse(); }
public void should_exclude_idictionary_members(Type actualType, Type specifiedType) { var nodes = CreateNode(Options.Create(x => x.TreatDictionaryImplsAsObjects().IncludePublicFields()), new SimpleValue(actualType.CreateInstance(), specifiedType.ToCachedType())).ToList(); nodes.ShouldTotal(2); nodes.ShouldContainNode("Property"); nodes.ShouldContainNode("Field"); }