public async Task Deserialize()
        {
            using (Stream stream = new MemoryStream(data))
            {
                stream.Seek(0, SeekOrigin.Begin);
                var result = await instance.Deserialize <DataInstance>(stream);

                Assert.AreEqual("Test", result.Text);
            }
        }
        public void SerializeWithCustom()
        {
            var serializer = new JsonSerializer {
                DateFormatString = "yyyy-yyyy-dd-M"
            };
            var result   = instance.SerializeArray(subscription, serializer);
            var text     = Encoding.UTF8.GetString(result);
            var contains = text.Contains(DateTime.Today.ToString("yyyy-yyyy-dd-M"));

            Assert.IsTrue(contains);

            var backInstance = instance.Deserialize <DataInstance>(result, serializer);

            Assert.AreEqual(subscription.Date, backInstance.Date);
        }
示例#3
0
        public void SerializeAttachEntityAttributes()
        {
            var defaultSerializer = new BasicJsonSerializer();
            var attach            = new AttachEntityAttributes("$serverUserId", "testId");
            var events            = new List <AppMetrAction> {
                attach
            };
            var batch        = new Batch(Guid.NewGuid().ToString(), 1, events);
            var json         = defaultSerializer.Serialize(batch);
            var receiveBatch = defaultSerializer.Deserialize <Batch>(json);

            _output.WriteLine("Json: " + json);

            Assert.Equal(1, receiveBatch.GetBatch().Count);
            var receivedAction = (AttachEntityAttributes)receiveBatch.GetBatch()[0];

            Assert.Equal("$serverUserId", receivedAction.GetEntityName());
            Assert.Equal("testId", receivedAction.GetEntityValue());
        }
示例#4
0
        public void SerializeServerInstall()
        {
            var defaultSerializer = new BasicJsonSerializer();
            var install           = Events.ServerInstall("test").SetProperties(new Dictionary <string, object>
            {
                { "key", "value" }
            });
            var events = new List <AppMetrAction> {
                install
            };
            var batch        = new Batch(Guid.NewGuid().ToString(), 1, events);
            var json         = defaultSerializer.Serialize(batch);
            var receiveBatch = defaultSerializer.Deserialize <Batch>(json);

            Assert.Equal(1, receiveBatch.GetBatch().Count);
            var receivedAction = receiveBatch.GetBatch()[0];

            Assert.Equal("test", receivedAction.GetUserId());
            Assert.Equal(1, receivedAction.GetProperties().Count);
            Assert.Equal("value", receivedAction.GetProperties()["key"]);
        }