public void Complex()
        {
            var         ctOrg = ComplexType1.Sample();
            var         bytes = MessagePackSerializer.Serialize(ctOrg);
            string      test  = MessagePackSerializer.ToJson(bytes);
            var         ctDes = MessagePackSerializer.Deserialize <ComplexType1>(bytes);
            SimpleType1 stOrg = ctOrg.Simple1.First();
            SimpleType1 stDes = ctDes.Simple1.First();

            Assert.Equal(stOrg.Id, stOrg.Id);
            Assert.Equal(stDes.Address.Address1, stDes.Address.Address1);
        }
        public void Simple()
        {
            var         ct = ComplexType1.Sample();
            SimpleType1 s1 = ct.Simple1.First();
            //MessagePackSerializer.SetDefaultResolver(ContractlessStandardResolver.Instance);
            var    bytes = MessagePackSerializer.Serialize(s1);
            string test  = MessagePackSerializer.ToJson(bytes);
            var    s2    = MessagePackSerializer.Deserialize <SimpleType1>(bytes);

            Assert.Equal(s1.Id, s2.Id);
            Assert.Equal(s1.Address.Address1, s2.Address.Address1);
        }
Пример #3
0
        public async Task PostMsgPack()
        {
            var ct               = ComplexType1.Sample();
            var bytes            = MessagePackSerializer.Serialize(ct);
            ByteArrayContent bae = new ByteArrayContent(bytes);

            using (var client = new TestClientProvider().Client)
            {
                var response = await client.PostAsync("/api/values/sendmessage", bae);

                var result = await response.Content.ReadAsAsync <ComplexType1>();

                Assert.Equal(ct.Simple1.First().Id, result.Simple1.First().Id);
            }
        }
Пример #4
0
        public async Task CanSave()
        {
            var ct    = ComplexType1.Sample();
            var bytes = MessagePackSerializer.Serialize(ct);

            string connStr                = "UseDevelopmentStorage=true";
            string containerName          = "mobileuploads";
            CloudStorageAccount account   = CloudStorageAccount.Parse(connStr);
            CloudBlobClient     client    = account.CreateCloudBlobClient();
            CloudBlobContainer  container = client.GetContainerReference(containerName);
            await container.CreateIfNotExistsAsync();

            BlobContainerPermissions containerPermissions = new BlobContainerPermissions()
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            };
            await container.SetPermissionsAsync(containerPermissions);

            string         blobName = Guid.NewGuid().ToString();
            CloudBlockBlob photo    = container.GetBlockBlobReference(blobName);
            await photo.UploadFromByteArrayAsync(bytes, 0, bytes.Length);

            string id = photo.Uri.ToString();

            //download
            CloudBlockBlob photo1 = container.GetBlockBlobReference(blobName);

            byte[] bytesD = Array.Empty <byte>();
            using (var ms = new MemoryStream())
            {
                await photo1.DownloadToStreamAsync(ms);

                bytesD = ms.ToArray();
            }

            var ctDes = MessagePackSerializer.Deserialize <ComplexType1>(bytesD);

            Assert.Equal(ct.Simple1.First().Id, ctDes.Simple1.First().Id);
        }