コード例 #1
0
        public void TestReadFromIInputStream()
        {
            var command = new AppInstallRequest(new AppInstallInfo()
            {
                AppxPath = "abc", PackageFamilyName = "def", Dependencies = new List <String>()
                {
                    "ghi", "jkl"
                }
            });
            var dataArray     = command.Serialize().GetByteArrayForSerialization();
            var dataSizeArray = BitConverter.GetBytes((UInt32)dataArray.Length);

            var stream = new InMemoryRandomAccessStream();

            stream.WriteAsync(dataSizeArray.AsBuffer()).AsTask().Wait();
            stream.WriteAsync(dataArray.AsBuffer()).AsTask().Wait();

            var result = Blob.ReadFromIInputStreamAsync(stream.GetInputStreamAt(0)).AsTask().Result;

            Assert.AreEqual(result.Tag, DMMessageKind.InstallApp);

            var request = result.MakeIRequest() as AppInstallRequest;

            Assert.AreEqual(request.Tag, DMMessageKind.InstallApp);
            Assert.AreEqual(request.AppInstallInfo.AppxPath, "abc");
            Assert.AreEqual(request.AppInstallInfo.PackageFamilyName, "def");
            Assert.AreEqual(request.AppInstallInfo.Dependencies[0], "ghi");
            Assert.AreEqual(request.AppInstallInfo.Dependencies[1], "jkl");
        }
コード例 #2
0
        public void TestSerializationRoundtripThroughStream()
        {
            var command = new AppInstallRequest(new AppInstallInfo()
            {
                AppxPath = "abc", PackageFamilyName = "def", Dependencies = new List <String>()
                {
                    "ghi", "jkl"
                }
            });
            var blob = command.Serialize();

            var stream = new InMemoryRandomAccessStream();

            blob.WriteToIOutputStreamAsync(stream.GetOutputStreamAt(0)).AsTask().Wait();
            var blob2 = Blob.ReadFromIInputStreamAsync(stream.GetInputStreamAt(0)).AsTask().Result;

            Assert.AreEqual(blob2.Tag, blob.Tag);

            var command2 = blob2.MakeIRequest() as AppInstallRequest;

            Assert.IsNotNull(command2);
            Assert.AreEqual(command2.Tag, DMMessageKind.InstallApp);
            Assert.AreEqual(command2.AppInstallInfo.AppxPath, "abc");
            Assert.AreEqual(command2.AppInstallInfo.PackageFamilyName, "def");
            Assert.AreEqual(command2.AppInstallInfo.Dependencies[0], "ghi");
            Assert.AreEqual(command2.AppInstallInfo.Dependencies[1], "jkl");
        }
コード例 #3
0
        public void TestRequestSerializeDeserialize()
        {
            var appInstallRequest = new AppInstallRequest(new AppInstallInfo()
            {
                AppxPath = "abc", PackageFamilyName = "def", Dependencies = new List <String>()
                {
                    "ghi", "jkl"
                }
            });
            var blob = appInstallRequest.Serialize();
            var appInstallRequestRehydrated = AppInstallRequest.Deserialize(blob) as AppInstallRequest;

            Assert.AreEqual(appInstallRequestRehydrated.Tag, DMMessageKind.InstallApp);
            Assert.AreEqual(appInstallRequestRehydrated.AppInstallInfo.AppxPath, "abc");
            Assert.AreEqual(appInstallRequestRehydrated.AppInstallInfo.PackageFamilyName, "def");
            Assert.AreEqual(appInstallRequestRehydrated.AppInstallInfo.Dependencies[0], "ghi");
            Assert.AreEqual(appInstallRequestRehydrated.AppInstallInfo.Dependencies[1], "jkl");
        }
コード例 #4
0
        public void TestWriteToOutputStream()
        {
            var command = new AppInstallRequest(new AppInstallInfo()
            {
                AppxPath = "abc", PackageFamilyName = "def", Dependencies = new List <String>()
                {
                    "ghi", "jkl"
                }
            });
            var blob = command.Serialize();

            var stream = new InMemoryRandomAccessStream();

            blob.WriteToIOutputStreamAsync(stream.GetOutputStreamAt(0)).AsTask().Wait();

            var reader = new DataReader(stream.GetInputStreamAt(0));

            reader.LoadAsync(4).AsTask().Wait();
            var bytes = new byte[4];

            reader.ReadBytes(bytes);
            var size = BitConverter.ToUInt32(bytes, 0);
            // like I said, too brittle:
            //Assert.AreEqual(size, 44U); // this is somewhat brittle.

            var reader2 = new DataReader(stream.GetInputStreamAt(4));

            reader2.LoadAsync(size).AsTask().Wait();
            var bytes2 = new byte[size];

            reader2.ReadBytes(bytes2);

            var blob2 = Blob.CreateFromByteArray(bytes2);

            Assert.AreEqual(blob.Tag, blob2.Tag);

            var command2 = blob2.MakeIRequest() as AppInstallRequest;

            Assert.AreEqual(command2.Tag, DMMessageKind.InstallApp);
            Assert.AreEqual(command2.AppInstallInfo.AppxPath, "abc");
            Assert.AreEqual(command2.AppInstallInfo.PackageFamilyName, "def");
            Assert.AreEqual(command2.AppInstallInfo.Dependencies[0], "ghi");
            Assert.AreEqual(command2.AppInstallInfo.Dependencies[1], "jkl");
        }