示例#1
0
        public void TestBinaryDeserialize()
        {
            BinarySerial serializer = new BinarySerial();
            BinaryModel  model      = serializer.DeserializeBinaryData();

            Assert.AreEqual(model.Commmand, serializer.GetModel().Commmand);
        }
示例#2
0
        public void TestBinarySerialize()
        {
            BinarySerial serializer = new BinarySerial();

            serializer.SerializeBinaryData();
            Assert.IsTrue(File.Exists(serializer.GetOutputPath()));
        }
示例#3
0
            protected override bool OnTest()
            {
                Logger.Log("Running BinarySerializable Test...");

                BinarySerial bin1 = new(10);

                // Try saving text1 to file. `ToFile<T>` is a convenience method that opens a
                // file stream and calls `SaveToStream` on the object.
                if (!BinarySerializable.ToFile(bin1, BinarySerialPath, true))
                {
                    return(Logger.LogReturn("Failed! Unable to serialize to file.", false));
                }

                // Try loading previously saved object from file. `FromFile<T>` is a convenience
                // method that opens a file stream and calls `LoadFromStream` on the object.
                BinarySerial bin2 = BinarySerializable.FromFile <BinarySerial>(BinarySerialPath);

                if (bin2 == null)
                {
                    return(Logger.LogReturn("Failed! Unable to deserialize from file.", false));
                }

                // Comparing saved and loaded data.
                if (bin1.NumberData != bin2.NumberData ||
                    !bin1.TextData.Equals(bin2.TextData))
                {
                    return(Logger.LogReturn("Failed! Deserialized object contains different values.", false));
                }

                bin1.Dispose();
                bin2.Dispose();

                try
                {
                    File.Delete(BinarySerialPath);
                }
                catch
                {
                    Logger.Log($"Failed! Unable to delete { BinarySerialPath }.", LogType.Warning);
                }

                return(Logger.LogReturn("BinarySerializable test succeeded!", true));
            }