public void WeGetNiceErrorIfDeserializationFails()
        {
            var configuration = new SuperiolizerConfiguration(Encoding.UTF8)
                                .WithCustomSerializer(dateTime => "THIS IS JUST A KNOWN VALUE", DateTime.Parse);

            var superiolizer = new Superiolizer(configuration);

            var serializationException = Assert.Throws <SerializationException>(() => superiolizer.Roundtrip(DateTime.Today));

            Console.WriteLine(serializationException);

            Assert.That(serializationException.ToString(), Contains.Substring("THIS IS JUST A KNOWN VALUE"));
        }
        public void CanUseCustomNames()
        {
            var configuration = new SuperiolizerConfiguration(Encoding.UTF8)
                                .WithShortName <InnerClass.InnerInnerClass.ThisIsTheClass>("ThisIsTheClass");

            var superiolizer = new Superiolizer(configuration);

            var instanceWithSillyName = new InnerClass.InnerInnerClass.ThisIsTheClass {
                Value = 23
            };

            string jsonText;
            var    roundtrippedInstanceWithSillyName = superiolizer.Roundtrip(instanceWithSillyName, out jsonText);

            Console.WriteLine(jsonText);

            Assert.That(roundtrippedInstanceWithSillyName.Value, Is.EqualTo(23));
            Assert.That(jsonText, Does.Not.Contain("InnerClass+InnerInnerClass+ThisIsTheClass"));
            Assert.That(jsonText, Does.Not.Contain("HybridDb.Superiolizer.Tests"));
        }
        public void CanRoundtripCustomSerializedDate()
        {
            var configuration = new SuperiolizerConfiguration(Encoding.UTF8);

            Func <Date, string> customDateSerializerFunction = date => $"{date.Year:0000}/{date.Month:00}/{date.Day:00}";

            configuration.WithCustomSerializer(customDateSerializerFunction,
                                               str =>
            {
                var parts = str.Split('/');
                return(new Date(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2])));
            });

            var superiolizer = new Superiolizer(configuration);

            var properDateValueType = new Date(2016, 11, 22);
            var classWithDates      = new ClassWithDates(properDateValueType, dateList: new[]
            {
                new Date(2016, 11, 20),
                new Date(2016, 11, 21),
                new Date(2016, 11, 22)
            });

            string jsonText;

            var roundtrippedClassWithDates = superiolizer.Roundtrip(classWithDates, out jsonText);

            Console.WriteLine(jsonText);

            var expectedDateLayout = customDateSerializerFunction(properDateValueType);

            Assert.That(jsonText, Contains.Substring(expectedDateLayout));
            Assert.That(roundtrippedClassWithDates.Date, Is.EqualTo(properDateValueType));
            Assert.That(roundtrippedClassWithDates.DateList, Is.EqualTo(new[]
            {
                new Date(2016, 11, 20),
                new Date(2016, 11, 21),
                new Date(2016, 11, 22)
            }));
        }