Exemplo n.º 1
0
        public void Constructor()
        {
            PackageScanner test;
            Exception      ex = Record.Exception(() => test = new PackageScanner(PlatformManagerMock.Object, PackageFactoryMock.Object));

            Assert.Null(ex);
        }
Exemplo n.º 2
0
        public void ScanPackages()
        {
            PackageScanner test = new PackageScanner(PlatformManagerMock.Object, PackageFactoryMock.Object);

            IResult <IList <IPackage> > result = test.ScanPackages();

            Assert.Equal(ResultCode.Success, result.ResultCode);
            Assert.Equal(1, result.ReturnValue.Count);
            Assert.Equal(PackageMock.Object, result.ReturnValue[0]);
        }
Exemplo n.º 3
0
        public void ScanPackagesListFailure()
        {
            PlatformMock.Setup(p => p.ListDirectories(It.IsAny <string>()))
            .Returns(new Result <IList <string> >(ResultCode.Failure));

            PackageScanner test = new PackageScanner(PlatformManagerMock.Object, PackageFactoryMock.Object);

            IResult <IList <IPackage> > result = test.ScanPackages();

            Assert.Equal(ResultCode.Failure, result.ResultCode);
            Assert.Equal(0, result.ReturnValue.Count);
        }
Exemplo n.º 4
0
        public void ScanPackageArchivesInvalidArchive()
        {
            PackageFactoryMock.Setup(p => p.GetPackageArchive(It.IsAny <string>()))
            .Returns(new Result <IPackageArchive>(ResultCode.Failure));

            PackageScanner test = new PackageScanner(PlatformManagerMock.Object, PackageFactoryMock.Object);

            IResult <IList <IPackageArchive> > result = test.ScanPackageArchives();

            Assert.Equal(ResultCode.Warning, result.ResultCode);
            Assert.Equal(0, result.ReturnValue.Count);
        }
Exemplo n.º 5
0
        public PackageContent ExtractPackageInfo(Core.Package package)
        {
            string tempPath = Path.Combine(this.TempFolder, Guid.NewGuid().ToString("N").ToUpper());

            package.Extract(tempPath);
            AppDomain tempDomain = ReflectionHelper.LoadAppDomain(tempPath, new Uri(this.GetType().Assembly.CodeBase).LocalPath);

            try {
                object handle;
                try {
                    handle = tempDomain.CreateInstanceAndUnwrap(typeof(PackageScanner).Assembly.GetName().Name, typeof(PackageScanner).FullName);
                } catch (FileNotFoundException) {
                    throw new AppServerException("Package does not contain required assembly " + typeof(PackageScanner).Assembly.Name());
                }
                PackageScanner scanner = handle as PackageScanner;
                if (scanner == null)
                {
                    throw new Exception("Could not load package scanner");
                }
                PackageContent info = scanner.Run();
                Logger.Info(this, "Scanner found " + info.Bootstrappers.Count + " bootstrapper(s) and " + info.Updaters.Count + " updater(s)");
                string manifestFile = Path.Combine(tempPath, "manifest.xml");
                if (File.Exists(manifestFile))
                {
                    Logger.Debug(this, "Loading package manifest " + manifestFile + "...");
                    try {
                        using (FileStream stream = File.Open(manifestFile, FileMode.Open, FileAccess.Read)) {
                            info.Manifest = XmlSerializer.Deserialize <Manifest>(stream);
                            Logger.Debug(this, "Manifest loaded");
                        }
                    } catch (Exception ex) {
                        Logger.Error("Failed to load manifest: " + ex.Message);
                    }
                }
                else
                {
                    Logger.Debug(this, "Package contains no manifest");
                }
                return(info);
            } finally {
                AppDomain.Unload(tempDomain);
                try {
                    Directory.Delete(tempPath, true);
                } catch (Exception ex) {
                    Logger.Warn(this, "Failed to remove temp folder " + tempPath + ": " + ex.Message);
                }
            }
        }
Exemplo n.º 6
0
        public void ScanPackagesSkipArchiveDirectory()
        {
            IResult <IList <string> > listResult = new Result <IList <string> >()
                                                   .SetReturnValue(new List <string>(new[] { string.Empty, "archives" }));

            PlatformMock.Setup(p => p.ListDirectories(It.IsAny <string>()))
            .Returns(listResult);

            PackageScanner test = new PackageScanner(PlatformManagerMock.Object, PackageFactoryMock.Object);

            IResult <IList <IPackage> > result = test.ScanPackages();

            Assert.Equal(ResultCode.Success, result.ResultCode);
            Assert.Equal(1, result.ReturnValue.Count);
            Assert.Equal(PackageMock.Object, result.ReturnValue[0]);
        }