Пример #1
0
        private static void TestSerializationOnAllSerializers(Action <ISerializer, string> action, bool testWithoutGraphIdsAsWell = true)
        {
            var serializers = new List <ISerializer>();

            serializers.Add(SerializationTestHelper.GetXmlSerializer(XmlSerializerOptimalizationMode.Performance));
            serializers.Add(SerializationTestHelper.GetXmlSerializer(XmlSerializerOptimalizationMode.PrettyXml));
            serializers.Add(SerializationTestHelper.GetBinarySerializer());
            serializers.Add(SerializationTestHelper.GetJsonSerializer());

            if (testWithoutGraphIdsAsWell)
            {
                var basicJsonSerializer = SerializationTestHelper.GetJsonSerializer();
                basicJsonSerializer.PreserveReferences = false;
                basicJsonSerializer.WriteTypeInfo      = false;
                serializers.Add(basicJsonSerializer);
            }

            foreach (var serializer in serializers)
            {
                var typeName = serializer.GetType().GetSafeFullName();

                Log.Info();
                Log.Info();
                Log.Info();
                Log.Info("=== TESTING SERIALIZER: {0} ===", typeName);
                Log.Info();
                Log.Info();
                Log.Info();

                action(serializer, typeName);
            }
        }
Пример #2
0
        private static void TestSerializationOnAllSerializers(Action <ISerializer, ISerializationConfiguration, string> action,
                                                              bool testWithoutGraphIdsAsWell = true, ISerializationManager serializationManager = null)
        {
            if (serializationManager == null)
            {
                serializationManager = new SerializationManager();
            }

            var serializerConfigurations = new Dictionary <Type, List <ISerializationConfiguration> >();

            serializerConfigurations[typeof(XmlSerializer)] = new List <ISerializationConfiguration>(new[]
            {
                new SerializationConfiguration()
            });

            serializerConfigurations[typeof(BinarySerializer)] = new List <ISerializationConfiguration>(new[]
            {
                new SerializationConfiguration()
            });

            serializerConfigurations[typeof(JsonSerializer)] = new List <ISerializationConfiguration>(new[]
            {
                new JsonSerializationConfiguration
                {
                    UseBson = false
                },
                new JsonSerializationConfiguration
                {
                    UseBson = true
                },
            });

            var serializers = new List <ISerializer>();

            serializers.Add(SerializationTestHelper.GetXmlSerializer(XmlSerializerOptimalizationMode.Performance, serializationManager));
            serializers.Add(SerializationTestHelper.GetXmlSerializer(XmlSerializerOptimalizationMode.PrettyXml, serializationManager));
            serializers.Add(SerializationTestHelper.GetBinarySerializer(serializationManager));
            serializers.Add(SerializationTestHelper.GetJsonSerializer(serializationManager));

            if (testWithoutGraphIdsAsWell)
            {
                var basicJsonSerializer = SerializationTestHelper.GetJsonSerializer(serializationManager);
                basicJsonSerializer.PreserveReferences = false;
                basicJsonSerializer.WriteTypeInfo      = false;
                serializers.Add(basicJsonSerializer);
            }

            foreach (var serializer in serializers)
            {
                var type     = serializer.GetType();
                var typeName = type.GetSafeFullName(false);

                var configurations = serializerConfigurations[type];
                foreach (var configuration in configurations)
                {
                    Log.Info();
                    Log.Info();
                    Log.Info();
                    Log.Info("=== TESTING SERIALIZER: {0} ===", typeName);
                    Log.Info();
                    Log.Info();
                    Log.Info();

                    action(serializer, configuration, typeName);
                }
            }
        }