Exemplo n.º 1
0
        public void Lz4BinFormatsToStream()
        {
            var test = TestResourceFactory.CreateRandom() as MockClassC;
            var bson = new BSONFormatter();
            var zip = new LZ4ZipFormatter(bson);

            var bytes = bson.FormatObjStream(test);

            var binFormatted = zip.Format(bytes);
            var buffer = zip.Unformat(binFormatted);

            var unformatted = bson.UnformatObj<MockClassA>(buffer) as MockClassC;

            Assert.AreEqual(unformatted.Id, test.Id);
            Assert.AreEqual(unformatted.Name, test.Name);
            Assert.AreEqual(unformatted.GetSomeCheckSum[0], test.GetSomeCheckSum[0]);
            Assert.AreEqual(unformatted.Location.X, test.Location.X);
            Assert.AreEqual(unformatted.Location.Y, test.Location.Y);
            Assert.AreEqual(unformatted.Location.Z, test.Location.Z);
            Assert.AreEqual(unformatted.Location.W, test.Location.W);
            Assert.AreEqual(unformatted.ReferenceCode, test.ReferenceCode);
            Assert.AreEqual(unformatted.ReplicationID, test.ReplicationID);
        }
Exemplo n.º 2
0
        public void Lz4FormatsToBytes()
        {
            var test = TestResourceFactory.CreateRandom() as MockClassC;
            var zip = new LZ4ZipFormatter(TestResourceFactory.CreateBsonFormatter());

            var formatted = zip.FormatObj(test);

            var unformatted = zip.UnformatObj<MockClassA>(formatted) as MockClassC;

            Assert.AreEqual(unformatted.Id, test.Id);
            Assert.AreEqual(unformatted.Name, test.Name);
            Assert.AreEqual(unformatted.GetSomeCheckSum[0], test.GetSomeCheckSum[0]);
            Assert.AreEqual(unformatted.Location.X, test.Location.X);
            Assert.AreEqual(unformatted.Location.Y, test.Location.Y);
            Assert.AreEqual(unformatted.Location.Z, test.Location.Z);
            Assert.AreEqual(unformatted.Location.W, test.Location.W);
            Assert.AreEqual(unformatted.ReferenceCode, test.ReferenceCode);
            Assert.AreEqual(unformatted.ReplicationID, test.ReplicationID);
        }
Exemplo n.º 3
0
        public void Lz4UnparsesJObjectToStream()
        {
            var arraySettings = BSONFormatter.GetDefaultSettings();
            arraySettings.TypeNameHandling = BESSy.Json.TypeNameHandling.Objects;

            var bson = new BSONFormatter(arraySettings);
            var zip = new LZ4ZipFormatter(bson);

            var test = TestResourceFactory.CreateRandom() as MockClassC;

            var stream = zip.FormatObjStream(test);
            var len = stream.Length;

            var copy = new MemoryStream();
            stream.CopyTo(copy);

            var unformatted = zip.Parse(stream);

            var formatted = zip.Unparse(unformatted);

            Assert.AreEqual(new StreamReader(copy).ReadToEnd(), new StreamReader(formatted).ReadToEnd());

            Stream os;
            zip.TryUnparse(unformatted, out os);
        }
Exemplo n.º 4
0
        public void Lz4SafeFormatsToStream()
        {
            var test = TestResourceFactory.CreateRandom() as MockClassC;
            var zip = new LZ4ZipFormatter(TestResourceFactory.CreateBsonFormatter());

            Stream formatted;

            Assert.IsTrue(zip.TryFormatObj(test, out formatted));

            MockClassA raw;

            Assert.IsTrue(zip.TryUnformatObj<MockClassA>(formatted, out raw));

            var unformatted = raw as MockClassC;

            Assert.AreEqual(unformatted.Id, test.Id);
            Assert.AreEqual(unformatted.Name, test.Name);
            Assert.AreEqual(unformatted.GetSomeCheckSum[0], test.GetSomeCheckSum[0]);
            Assert.AreEqual(unformatted.Location.X, test.Location.X);
            Assert.AreEqual(unformatted.Location.Y, test.Location.Y);
            Assert.AreEqual(unformatted.Location.Z, test.Location.Z);
            Assert.AreEqual(unformatted.Location.W, test.Location.W);
            Assert.AreEqual(unformatted.ReferenceCode, test.ReferenceCode);
            Assert.AreEqual(unformatted.ReplicationID, test.ReplicationID);

            var invalid = Encoding.UTF8.GetBytes("{ this is invalid.");

            //Check false conditions.
            Assert.IsFalse(zip.TryFormatObj(default(MockClassA), out formatted));
            Assert.IsFalse(zip.TryUnformatObj((byte[])null, out raw));
            Assert.IsFalse(zip.TryUnformatObj(invalid, out raw));
        }
Exemplo n.º 5
0
        public void Lz4ParsesJObjectFromStream()
        {
            var arraySettings = BSONFormatter.GetDefaultSettings();
            arraySettings.TypeNameHandling = BESSy.Json.TypeNameHandling.Objects;

            var bson = new BSONFormatter(arraySettings);
            var zip = new LZ4ZipFormatter(bson);

            var test = TestResourceFactory.CreateRandom() as MockClassC;

            var stream = zip.FormatObjStream(test);

            var unformatted = zip.Parse(stream);

            Assert.AreEqual(unformatted.Value<int>("Id"), test.Id);
            Assert.AreEqual(unformatted.Value<string>("Name"), test.Name);
            Assert.AreEqual((double)unformatted["GetSomeCheckSum"][0], test.GetSomeCheckSum[0]);
            Assert.AreEqual((double)unformatted["Location"]["X"], test.Location.X);
            Assert.AreEqual((double)unformatted["Location"]["Y"], test.Location.Y);
            Assert.AreEqual((double)unformatted["Location"]["Z"], test.Location.Z);
            Assert.AreEqual((double)unformatted["Location"]["W"], test.Location.W);
            Assert.AreEqual((string)unformatted["ReferenceCode"], test.ReferenceCode);
            Assert.AreEqual((Guid)unformatted["ReplicationID"], test.ReplicationID);
        }
        public void FormatterCompressesVeryLargeFiles()
        {
            var test = new Mocks.MockImageContainer(testRes.IronAsteroid_NRM) { Name = "IronAsteroid_NRM" };

            var bson = new BSONFormatter();
            var zip = new LZ4ZipFormatter(bson);

            var bytes = bson.FormatObjStream(test);

            var binFormatted = zip.Format(bytes);

            var buffer = zip.Unformat(binFormatted);

            var unformatted = bson.UnformatObj<ResourceContainer>(buffer) as MockImageContainer;

            Assert.AreEqual(unformatted.Name, test.Name);
            Assert.AreEqual(unformatted.GetResource<Bitmap>().Size.Width, test.GetResource<Bitmap>().Size.Width);
        }
        public void FormatterCompressesVeryLargeFileStreams()
        {
            var test = new Mocks.MockStreamContainer(new MemoryStream(testRes.MiscAngelic)) { Name = "MiscAngelic" };

            var bson = new BSONFormatter();
            var zip = new LZ4ZipFormatter(bson);

            var bytes = bson.FormatObjStream(test);

            var binFormatted = zip.Format(bytes);

            var buffer = zip.Unformat(binFormatted);

            var unformatted = bson.UnformatObj<ResourceStreamContainer>(buffer) as MockStreamContainer;

            Assert.AreEqual(unformatted.Name, test.Name);
            Assert.AreEqual(unformatted.GetResource<Stream>().Length, test.GetResource<Stream>().Length);
        }