Beispiel #1
0
 private static string SerializeProtocolAsJsonString(ProtocolDescriptor descriptor)
 {
     using (var writer = new StringWriter())
     {
         ProtocolDescriptorJsonStorage.Save(writer, descriptor);
         return(writer.ToString());
     }
 }
Beispiel #2
0
        public void WhenReadingFromKnownJson_ThenProtocolIsWhatExpected()
        {
            var json = SerializeProtocolAsJsonString(ProtocolFactory.CreateTest());

            using (var reader = new StringReader(json))
            {
                var protocol = ProtocolDescriptorJsonStorage.Load(reader);
                ProtocolFactory.CheckConsistency(protocol);

                Assert.Equal(json, SerializeProtocolAsJsonString(protocol));
            }
        }
Beispiel #3
0
        public void WhenSavingAndLoadingWithUtf16Encoding_ThenRetrievedObjectIsWhatExpected()
        {
            var tempFilePath = Path.GetTempFileName();

            try
            {
                var json = SerializeProtocolAsJsonString(ProtocolFactory.CreateTest());
                File.WriteAllText(tempFilePath, json, Encoding.Unicode);
                ProtocolFactory.CheckConsistency(ProtocolDescriptorJsonStorage.Load(tempFilePath, Encoding.Unicode));
            }
            finally
            {
                File.Delete(tempFilePath);
            }
        }
Beispiel #4
0
        public void WhenSavingWithDefaultSettings_ThenOutputFileIsUtf8Encoded()
        {
            var tempFilePath = Path.GetTempFileName();

            try
            {
                var protocol = ProtocolFactory.CreateTest();
                ProtocolDescriptorJsonStorage.Save(tempFilePath, protocol);

                Assert.True((new FileInfo(tempFilePath)).Length > 0);
                Assert.Equal(SerializeProtocolAsJsonString(protocol), File.ReadAllText(tempFilePath, Encoding.UTF8));
            }
            finally
            {
                File.Delete(tempFilePath);
            }
        }