Пример #1
0
        public void Serialize_NonSerializableDataObject_ThrowsSerializationException( )
        {
            var formatter = FormatterFactory <NonSerializableDataObject> .CreateFormatter(FormatterType.BinaryFormatter);

            var fixture = new Fixture( );
            var input   = fixture.Create <NonSerializableDataObject>( );

            Should.Throw <SerializationException>(
                () => formatter.Serialize(input));
        }
Пример #2
0
        public void CreateFormattersTest_CustomTypes(Format format, Type expectedType, IEnumerable <Type> types, IEnumerable <Type> expectedTypes)
        {
            IFormatter <TestEntity> sut = FormatterFactory.CreateFormatter <TestEntity>(format, types);

            Assert.IsType(expectedType, sut);
            if (sut is TypesFormatter <TestEntity> typesFormatter)
            {
                Assert.Equal(expectedTypes, typesFormatter.KnownTypes);
            }
        }
Пример #3
0
        public void SerializeAndDeserialize_String_ShouldBeEqual( )
        {
            var formatter = FormatterFactory <string> .CreateFormatter(FormatterType.BinaryFormatter);

            var fixture          = new Fixture( );
            var expected         = fixture.Create <string>( );
            var serializedResult = formatter.Serialize(expected);
            var actual           = formatter.Deserialize(serializedResult);

            actual.ShouldBeEquivalentTo(expected);
        }
        public void SerializeAndDeserialize_MessagePackDataObject_ShouldBeEqual( )
        {
            var formatter = FormatterFactory <MessagePackDataObject> .CreateFormatter(FormatterType.MessagePackFormatter);

            var fixture          = new Fixture( );
            var expected         = fixture.Create <MessagePackDataObject>( );
            var serializedResult = formatter.Serialize(expected);
            var actual           = formatter.Deserialize(serializedResult);

            actual.ShouldBeEquivalentTo(expected);
        }
Пример #5
0
        public void Serialize_NullInput_ThrowsArgumentNullException( )
        {
            var formatter = FormatterFactory <SerializableDataObject> .CreateFormatter(FormatterType.BinaryFormatter);

            var fixture = new Fixture( );

            fixture.Register <SerializableDataObject>(() => null);
            var input = fixture.Create <SerializableDataObject>( );

            Should.Throw <ArgumentNullException>(
                () => formatter.Serialize(input));
        }
        public void Deserialize_NullInput_ThrowsArgumentNullException( )
        {
            var formatter = FormatterFactory <MessagePackDataObject> .CreateFormatter(FormatterType.MessagePackFormatter);

            var fixture = new Fixture( );

            fixture.Register <byte[]>(() => null);
            var input = fixture.Create <byte[]>( );

            Should.Throw <ArgumentNullException>(
                () => formatter.Deserialize(input));
        }
Пример #7
0
        public void Deserialize_ZeroLengthInput_ThrowsArgumentException( )
        {
            var formatter = FormatterFactory <SerializableDataObject> .CreateFormatter(FormatterType.BinaryFormatter);

            var fixture = new Fixture
            {
                RepeatCount = 0
            };
            var input = fixture.Create <byte[]>( );

            Should.Throw <ArgumentException>(
                () => formatter.Deserialize(input));
        }
Пример #8
0
        public void Deserialize_NonSerializedSerializableDataObject_ThrowsSerializationException( )
        {
            var formatter = FormatterFactory <SerializableDataObject> .CreateFormatter(FormatterType.BinaryFormatter);

            var fixture = new Fixture
            {
                RepeatCount = 10
            };
            var input = fixture.Create <byte[]>( );

            Should.Throw <SerializationException>(
                () => formatter.Deserialize(input));
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SocketBase{TCommandModel}"/> class.
        /// </summary>
        /// <param name="formatterType">Type of the formatter.</param>
        /// <param name="compressType">Type of the compress.</param>
        /// <param name="logger">The logger.</param>
        internal SocketBase(FormatterType?formatterType, CompressType?compressType, ILogger logger)
        {
            IgnoreFormatter = typeof(TCommandModel) == typeof(byte[]);

            if (IgnoreFormatter == false)
            {
                if (formatterType == null)
                {
                    formatterType = FormatterType.BinaryFormatter;
                }

                CommandFormatter = FormatterFactory <TCommandModel> .CreateFormatter(formatterType.Value);
            }

            if (compressType == null)
            {
                compressType = CompressType.Default;
            }

            Compressor = CompressorFactory.CreateCompressor(compressType.Value);
            Logger     = logger;
        }
Пример #10
0
 public void CreateFormatter_FormatterType_ShouldNotThrowException(FormatterType formatterType)
 {
     Shouldly.Should.NotThrow(
         () => FormatterFactory <string> .CreateFormatter(formatterType));
 }
Пример #11
0
 public Serializer(Encoding encoding, Format format, IEnumerable <Type> knownTypes) : this(encoding, FormatterFactory.CreateFormatter <T>(format, knownTypes))
 {
 }
Пример #12
0
 public Serializer(Encoding encoding, Format format)
 {
     Encoding  = encoding ?? throw new ArgumentNullException(nameof(encoding));
     Formatter = FormatterFactory.CreateFormatter <T>(format);
 }
Пример #13
0
        public void CreateFormattersTest_DefaultTypes(Format format, Type expectedType)
        {
            IFormatter <TestEntity> sut = FormatterFactory.CreateFormatter <TestEntity>(format);

            Assert.IsType(expectedType, sut);
        }