Example #1
0
        public void ShouldLoadDownloadedAssemblies()
        {
            // NOTE: This test method uses a resource that is built in a pre-build event when building the project. The resource is a
            // dynamically generated XAP file that is built with the Mocks/Modules/createXap.bat batch file.
            // If this test is failing unexpectedly, it may be that the batch file is not working correctly in the current environment.

            var          mockFileDownloader = new MockFileDownloader();
            const string moduleTypeName     = "Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModule, RemoteModuleA, Version=0.0.0.0";
            var          remoteModuleUri    = "http://MyModule.xap";
            var          moduleInfo         = new ModuleInfo()
            {
                Ref = remoteModuleUri
            };
            XapModuleTypeLoader typeLoader    = new TestableXapModuleTypeLoader(mockFileDownloader);
            ManualResetEvent    callbackEvent = new ManualResetEvent(false);

            typeLoader.LoadModuleCompleted += delegate(object sender, LoadModuleCompletedEventArgs e)
            {
                callbackEvent.Set();
            };

            typeLoader.LoadModuleType(moduleInfo);

            Assert.IsNull(Type.GetType(moduleTypeName));

            Stream xapStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModules.xap");

            mockFileDownloader.InvokeOpenReadCompleted(new DownloadCompletedEventArgs(xapStream, null, false, mockFileDownloader.DownloadAsyncArgumentUserToken));
            Assert.IsTrue(callbackEvent.WaitOne(500));

            Assert.IsNotNull(Type.GetType(moduleTypeName));
        }
Example #2
0
        public void ShouldNotDownloadAgainIfAlreadyDownloaded()
        {
            var mockFileDownloader = new MockFileDownloader();

            const string moduleATypeName = "Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModule, RemoteModuleA, Version=0.0.0.0";
            var          remoteModuleUri = "http://MyModule.xap";
            var          moduleInfoA     = new ModuleInfo()
            {
                Ref = remoteModuleUri, ModuleName = "ModuleA", ModuleType = moduleATypeName
            };

            XapModuleTypeLoader typeLoader = new TestableXapModuleTypeLoader(mockFileDownloader);

            List <ModuleInfo> downloadedModuleInfos = new List <ModuleInfo>();

            typeLoader.LoadModuleCompleted += (o, e) =>
            {
                downloadedModuleInfos.Add(e.ModuleInfo);
            };

            typeLoader.LoadModuleType(moduleInfoA);

            Stream xapStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModules.xap");

            mockFileDownloader.InvokeOpenReadCompleted(new DownloadCompletedEventArgs(xapStream, null, false, mockFileDownloader.DownloadAsyncArgumentUserToken));

            mockFileDownloader.DownloadAsyncCalled = false;

            typeLoader.LoadModuleType(moduleInfoA);

            Assert.AreEqual(2, downloadedModuleInfos.Count);
            Assert.AreEqual(moduleInfoA, downloadedModuleInfos[0]);
            Assert.AreEqual(moduleInfoA, downloadedModuleInfos[1]);
            Assert.IsFalse(mockFileDownloader.DownloadAsyncCalled);
        }
Example #3
0
        public void ShouldReturnErrorIfDownloadFails()
        {
            var mockFileDownloader = new MockFileDownloader();
            var remoteModuleUri    = "http://MyModule.xap";
            var moduleInfo         = new ModuleInfo()
            {
                Ref = remoteModuleUri
            };
            XapModuleTypeLoader typeLoader    = new TestableXapModuleTypeLoader(mockFileDownloader);
            ManualResetEvent    callbackEvent = new ManualResetEvent(false);
            Exception           error         = null;

            typeLoader.LoadModuleCompleted += delegate(object sender, LoadModuleCompletedEventArgs e)
            {
                error = e.Error;
                callbackEvent.Set();
            };

            typeLoader.LoadModuleType(moduleInfo);
            mockFileDownloader.InvokeOpenReadCompleted(new DownloadCompletedEventArgs(null, new InvalidOperationException("Mock Ex"), false, mockFileDownloader.DownloadAsyncArgumentUserToken));
            Assert.IsTrue(callbackEvent.WaitOne(500));

            Assert.IsNotNull(error);
            Assert.IsInstanceOfType(error, typeof(InvalidOperationException));
        }
        public void ShouldReturnErrorIfDownloadFails()
        {
            var mockFileDownloader = new MockFileDownloader();
            var remoteModuleUri = "http://MyModule.xap";
            var moduleInfo = new ModuleInfo() { Ref = remoteModuleUri };
            XapModuleTypeLoader typeLoader = new TestableXapModuleTypeLoader(mockFileDownloader);
            ManualResetEvent callbackEvent = new ManualResetEvent(false);
            Exception error = null;

            typeLoader.LoadModuleCompleted += delegate(object sender, LoadModuleCompletedEventArgs e)
            {
                error = e.Error;
                callbackEvent.Set();
            };

            typeLoader.LoadModuleType(moduleInfo);
            mockFileDownloader.InvokeOpenReadCompleted(new DownloadCompletedEventArgs(null, new InvalidOperationException("Mock Ex"), false, mockFileDownloader.DownloadAsyncArgumentUserToken));
            Assert.IsTrue(callbackEvent.WaitOne(500));

            Assert.IsNotNull(error);
            Assert.IsInstanceOfType(error, typeof(InvalidOperationException));
        }
Example #5
0
        public void ShouldRaiseDownloadCompletedForEachModuleInfoWhenDownloadedFromSameUri()
        {
            var mockFileDownloader = new MockFileDownloader();

            const string moduleATypeName = "Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModule, RemoteModuleA, Version=0.0.0.0";
            var          remoteModuleUri = "http://MyModule.xap";
            var          moduleInfoA     = new ModuleInfo()
            {
                Ref = remoteModuleUri, ModuleName = "ModuleA", ModuleType = moduleATypeName
            };

            const string moduleBTypeName = "Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModule, RemoteModuleB, Version=0.0.0.0";
            var          moduleInfoB     = new ModuleInfo()
            {
                Ref = remoteModuleUri, ModuleName = "ModuleB", ModuleType = moduleBTypeName
            };

            XapModuleTypeLoader typeLoader = new TestableXapModuleTypeLoader(mockFileDownloader);

            List <ModuleInfo> downloadedModuleInfos = new List <ModuleInfo>();

            typeLoader.LoadModuleCompleted += (o, e) =>
            {
                downloadedModuleInfos.Add(e.ModuleInfo);
            };

            typeLoader.LoadModuleType(moduleInfoA);
            typeLoader.LoadModuleType(moduleInfoB);

            Stream xapStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModules.xap");

            mockFileDownloader.InvokeOpenReadCompleted(new DownloadCompletedEventArgs(xapStream, null, false, mockFileDownloader.DownloadAsyncArgumentUserToken));


            Assert.IsTrue(downloadedModuleInfos.Contains(moduleInfoA));
            Assert.IsTrue(downloadedModuleInfos.Contains(moduleInfoB));
        }
        public void ShouldLoadDownloadedAssemblies()
        {
            // NOTE: This test method uses a resource that is built in a pre-build event when building the project. The resource is a
            // dynamically generated XAP file that is built with the Mocks/Modules/createXap.bat batch file.
            // If this test is failing unexpectedly, it may be that the batch file is not working correctly in the current environment.

            var mockFileDownloader = new MockFileDownloader();
            const string moduleTypeName = "Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModule, RemoteModuleA, Version=0.0.0.0";
            var remoteModuleUri = "http://MyModule.xap";
            var moduleInfo = new ModuleInfo() { Ref = remoteModuleUri };
            XapModuleTypeLoader typeLoader = new TestableXapModuleTypeLoader(mockFileDownloader);
            ManualResetEvent callbackEvent = new ManualResetEvent(false);

            typeLoader.LoadModuleCompleted += delegate(object sender, LoadModuleCompletedEventArgs e)
            {
                callbackEvent.Set();
            };

            typeLoader.LoadModuleType(moduleInfo);

            Assert.IsNull(Type.GetType(moduleTypeName));

            Stream xapStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModules.xap");
            mockFileDownloader.InvokeOpenReadCompleted(new DownloadCompletedEventArgs(xapStream, null, false, mockFileDownloader.DownloadAsyncArgumentUserToken));
            Assert.IsTrue(callbackEvent.WaitOne(500));

            Assert.IsNotNull(Type.GetType(moduleTypeName));
        }
        public void ShouldNotDownloadAgainIfAlreadyDownloaded()
        {
            var mockFileDownloader = new MockFileDownloader();

            const string moduleATypeName = "Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModule, RemoteModuleA, Version=0.0.0.0";
            var remoteModuleUri = "http://MyModule.xap";
            var moduleInfoA = new ModuleInfo() { Ref = remoteModuleUri, ModuleName = "ModuleA", ModuleType = moduleATypeName };

            XapModuleTypeLoader typeLoader = new TestableXapModuleTypeLoader(mockFileDownloader);

            List<ModuleInfo> downloadedModuleInfos = new List<ModuleInfo>();
            typeLoader.LoadModuleCompleted += (o, e) =>
            {
                downloadedModuleInfos.Add(e.ModuleInfo);
            };

            typeLoader.LoadModuleType(moduleInfoA);

            Stream xapStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModules.xap");
            mockFileDownloader.InvokeOpenReadCompleted(new DownloadCompletedEventArgs(xapStream, null, false, mockFileDownloader.DownloadAsyncArgumentUserToken));

            mockFileDownloader.DownloadAsyncCalled = false;

            typeLoader.LoadModuleType(moduleInfoA);

            Assert.AreEqual(2, downloadedModuleInfos.Count);
            Assert.AreEqual(moduleInfoA, downloadedModuleInfos[0]);
            Assert.AreEqual(moduleInfoA, downloadedModuleInfos[1]);
            Assert.IsFalse(mockFileDownloader.DownloadAsyncCalled);            
        }
        public void ShouldRaiseDownloadCompletedForEachModuleInfoWhenDownloadedFromSameUri()
        {
            var mockFileDownloader = new MockFileDownloader();

            const string moduleATypeName = "Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModule, RemoteModuleA, Version=0.0.0.0";
            var remoteModuleUri = "http://MyModule.xap";
            var moduleInfoA = new ModuleInfo() { Ref = remoteModuleUri, ModuleName = "ModuleA", ModuleType = moduleATypeName };

            const string moduleBTypeName = "Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModule, RemoteModuleB, Version=0.0.0.0";
            var moduleInfoB = new ModuleInfo() { Ref = remoteModuleUri, ModuleName = "ModuleB", ModuleType = moduleBTypeName };

            XapModuleTypeLoader typeLoader = new TestableXapModuleTypeLoader(mockFileDownloader);

            List<ModuleInfo> downloadedModuleInfos = new List<ModuleInfo>();
            typeLoader.LoadModuleCompleted += (o, e) =>
                {
                    downloadedModuleInfos.Add(e.ModuleInfo);
                };

            typeLoader.LoadModuleType(moduleInfoA);
            typeLoader.LoadModuleType(moduleInfoB);

            Stream xapStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Practices.Prism.Tests.Mocks.Modules.RemoteModules.xap");
            mockFileDownloader.InvokeOpenReadCompleted(new DownloadCompletedEventArgs(xapStream, null, false, mockFileDownloader.DownloadAsyncArgumentUserToken));


            Assert.IsTrue(downloadedModuleInfos.Contains(moduleInfoA));
            Assert.IsTrue(downloadedModuleInfos.Contains(moduleInfoB));
        }