Esempio n. 1
0
        internal static void AddFileInternal(IXapZipArchive xapZipArchive, string fileName, byte[] value)
        {
            if (xapZipArchive == null) throw new ArgumentNullException("xapZipArchive");
            if (fileName == null) throw new ArgumentNullException("fileName");
            if (value == null) throw new ArgumentNullException("value");

            xapZipArchive.AddFile(fileName, value);
        }
Esempio n. 2
0
        public static XElement GetAppManifest(this IXapZipArchive xapZipArchive)
        {
            if (xapZipArchive == null)
            {
                throw new ArgumentNullException("xapZipArchive");
            }
            byte[] appManifestEntry    = xapZipArchive["AppManifest.xaml"];
            string stringFromByteArray = appManifestEntry.ToStringFromByteArray();

            return(XElement.Load(stringFromByteArray.ToStream()));
        }
Esempio n. 3
0
        private static XElement ReadXmlFileFromZip(IXapZipArchive xapZipArchive, string fileName)
        {
            if (xapZipArchive == null)
            {
                throw new ArgumentNullException("xapZipArchive");
            }
            byte[] appManifestEntry    = xapZipArchive[fileName];
            string stringFromByteArray = appManifestEntry.ToStringFromByteArray();

            return(XElement.Load(stringFromByteArray.ToStream()));
        }
Esempio n. 4
0
        private static AssemblyName GetAssemblyName(IXapZipArchive zip1, string testAssemblyName)
        {
            string tempFileName = Path.GetTempFileName();
            var    fileData     = zip1.ReadFileIntoBytes(testAssemblyName);

            if (fileData != null)
            {
                File.WriteAllBytes(tempFileName, fileData);
                return(AssemblyName.GetAssemblyName(tempFileName));
            }
            return(null);
        }
Esempio n. 5
0
        private static string LoadAppManifest(IXapZipArchive zip1)
        {
            var fileData = zip1.ReadFileIntoBytes("AppManifest.xaml");

            if (fileData != null)
            {
                string xaml = Encoding.UTF8.GetString(fileData);
                if (xaml[0] == '<')
                {
                    return(xaml);
                }
                return(xaml.Substring(1));
            }

            return(null);
        }
Esempio n. 6
0
        internal static void AddFileInternal(IXapZipArchive xapZipArchive, string fileName, byte[] value)
        {
            if (xapZipArchive == null)
            {
                throw new ArgumentNullException("xapZipArchive");
            }
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            xapZipArchive.AddFile(fileName, value);
        }
Esempio n. 7
0
        private void AddFile(IXapZipArchive xapZipArchive, ITestFile file, XElement parts)
        {
            AddFileInternal(xapZipArchive, file.FileName, file.File);

            if ((Path.GetExtension(file.FileName) ?? string.Empty).Equals(".dll", StringComparison.OrdinalIgnoreCase))
            {
                var name = Path.GetFileNameWithoutExtension(file.FileName);

                if (string.IsNullOrEmpty(Path.GetDirectoryName(file.FileName)))
                {
                    parts.Add(new XElement("AssemblyPart",
                                           new XAttribute("StatLightTempName", name),
                                           new XAttribute("Source", file.FileName)));

                    _logger.Debug("        updated AppManifest - {0}".FormatWith(name));
                }
                else
                {
                    _logger.Debug("        Assembly not at root - not adding to AppManifest - {0}".FormatWith(name));
                }
            }
        }
Esempio n. 8
0
        private void AddFile(IXapZipArchive xapZipArchive, ITestFile file, XElement parts)
        {
            AddFileInternal(xapZipArchive, file.FileName, file.File);

            if ((Path.GetExtension(file.FileName) ?? string.Empty).Equals(".dll", StringComparison.OrdinalIgnoreCase))
            {
                var name = Path.GetFileNameWithoutExtension(file.FileName);

                if (string.IsNullOrEmpty(Path.GetDirectoryName(file.FileName)))
                {
                    parts.Add(new XElement("AssemblyPart",
                                           new XAttribute("StatLightTempName", name),
                                           new XAttribute("Source", file.FileName)));

                    _logger.Debug("        updated AppManifest - {0}".FormatWith(name));
                }
                else
                {
                    _logger.Debug("        Assembly not at root - not adding to AppManifest - {0}".FormatWith(name));
                }
            }
        }
Esempio n. 9
0
        private static void AssertZipsEqual(IXapZipArchive expected, IXapZipArchive actual)
        {
            actual.Count().ShouldEqual(expected.Count(), "zip files contain different counts");

            var allFiles = actual.Select(s => s.FileName).ToArray();

            foreach (var expectedFile in expected)
            {
                string firstOrDefault = allFiles.Where(w => w.Equals(expectedFile.FileName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                firstOrDefault.ShouldNotBeNull("Could not find file {0} in files \n{1}".FormatWith(
                                                   expectedFile.FileName,
                                                   string.Join(Environment.NewLine, allFiles)));
                //allFiles.Contains(expectedFile.FileName).ShouldBeTrue();
            }
            //for (int i = 0; i < expected.Count; i++)
            //{
            //    var expectedFile = expected[i];
            //    var actualFile = actual[i];
            //
            //    actualFile.FileName.ShouldEqual(expectedFile.FileName);
            //    //actualFile.ToByteArray().ShouldEqual(expectedFile.ToByteArray(), "File [{0}] bytes not same.".FormatWith(actualFile.FileName));
            //}
        }
Esempio n. 10
0
        public TestFileCollection LoadXapUnderTest(string archiveFileName)
        {
            var    files = new List <ITestFile>();
            string testAssemblyFullName = null;

            var fileStream = FileReader.ReadAllBytes(archiveFileName);

            using (IXapZipArchive archive = XapZipArchiveFactory.Create(fileStream))
            {
                var appManifest = LoadAppManifest(archive);

                if (appManifest != null)
                {
                    string testAssemblyName = GetTestAssemblyNameFromAppManifest(appManifest);

                    AssemblyName assemblyName = GetAssemblyName(archive, testAssemblyName);
                    if (assemblyName != null)
                    {
                        testAssemblyFullName = assemblyName.ToString();
                    }
                }

                files.AddRange(archive.ToList());

                foreach (var item in files)
                {
                    _logger.Debug("XapItems.FilesContainedWithinXap = {0}".FormatWith(item.FileName));
                }
            }


            var xapItems = new TestFileCollection(_logger, testAssemblyFullName, files);


            return(xapItems);
        }
Esempio n. 11
0
        private static string LoadAppManifest(IXapZipArchive zip1)
        {
            var fileData = zip1.ReadFileIntoBytes("AppManifest.xaml");
            if (fileData != null)
            {
                string xaml = Encoding.UTF8.GetString(fileData);
                if (xaml[0] == '<')
                    return xaml;
                return xaml.Substring(1);
            }

            return null;
        }
Esempio n. 12
0
 private static AssemblyName GetAssemblyName(IXapZipArchive zip1, string testAssemblyName)
 {
     string tempFileName = Path.GetTempFileName();
     var fileData = zip1.ReadFileIntoBytes(testAssemblyName);
     if (fileData != null)
     {
         File.WriteAllBytes(tempFileName, fileData);
         return AssemblyName.GetAssemblyName(tempFileName);
     }
     return null;
 }
Esempio n. 13
0
        private static void AssertZipsEqual(IXapZipArchive expected, IXapZipArchive actual)
        {
            actual.Count().ShouldEqual(expected.Count(), "zip files contain different counts");

            var allFiles = actual.Select(s => s.FileName).ToArray();

            foreach (var expectedFile in expected)
            {
                string firstOrDefault = allFiles.Where(w => w.Equals(expectedFile.FileName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                firstOrDefault.ShouldNotBeNull("Could not find file {0} in files \n{1}".FormatWith(
                    expectedFile.FileName,
                    string.Join(Environment.NewLine, allFiles)));
                //allFiles.Contains(expectedFile.FileName).ShouldBeTrue();
            }
            //for (int i = 0; i < expected.Count; i++)
            //{
            //    var expectedFile = expected[i];
            //    var actualFile = actual[i];
            //
            //    actualFile.FileName.ShouldEqual(expectedFile.FileName);
            //    //actualFile.ToByteArray().ShouldEqual(expectedFile.ToByteArray(), "File [{0}] bytes not same.".FormatWith(actualFile.FileName));
            //}
        }
Esempio n. 14
0
 public static XElement GetAppXaml(this IXapZipArchive xapZipArchive)
 {
     return(ReadXmlFileFromZip(xapZipArchive, "App.xaml"));
 }