-
Notifications
You must be signed in to change notification settings - Fork 377
Add unit tests for Helix SDK XHarness tasks #7358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
premun
merged 23 commits into
dotnet:main
from
premun:prvysoky/xharness-helix-sdk-tests
May 11, 2021
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ed096c6
Minor fixes in README
premun 869aa78
Switch to TimeSpan
premun 5b24365
Create ProvisioningProfileProvider
premun 9f91a35
Register ProvisioningProfileProvider
premun 18c4b1c
Add the ZipArchiveManager
premun 6af8910
Move test projects to Tests directory
premun eb480ff
Clean up
premun 61ec17e
Move IsPosixShell to Android only
premun 37eb4ed
Add FileSystem
premun a296e8a
Revert System.Index
premun 34688fd
Move FakeHttpClient
premun 96a6489
Add mock file system and write first tests for provisioning profile p…
premun dfa6f25
Add more complex ProvisioningProfileProvider test
premun 02ba6cd
Add tests for ProvisioningProfileProvider
premun f820aac
Add first successful CreateAppleWorkItem test
premun f93e9e5
Add tests for AppleWorkItems
premun ad16487
Add Android unit tests
premun cbace5b
Merge remote-tracking branch 'dotnet/main' into prvysoky/xharness-hel…
premun c8e4159
Add license headers
premun c6d4915
Fix doc
premun 15f7bfb
Revert FakeHttpClient changes
premun 4db9218
Fix payload script name
premun 7082a9e
Remove Task.Yield()
premun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Threading.Tasks; | ||
premun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| namespace Microsoft.Arcade.Common | ||
| { | ||
| public interface IZipArchiveManager | ||
| { | ||
| /// <summary> | ||
| /// Loads an embedded resource and adds it to a target archive. | ||
| /// </summary> | ||
| /// <typeparam name="TAssembly">Type from the assembly where the resource is embedded (usually the caller)</typeparam> | ||
| /// <param name="archivePath">Path to the archive where the file will be added</param> | ||
| /// <param name="resourceName">Name of the embedded resource</param> | ||
| /// <param name="targetFileName">New name of the file in the archive</param> | ||
| Task AddResourceFileToArchive<TAssembly>(string archivePath, string resourceName, string targetFileName = null); | ||
|
|
||
| /// <summary> | ||
| /// Compresses a directory into an archive on a given path. | ||
| /// </summary> | ||
| /// <param name="directoryPath">The directory to archive</param> | ||
| /// <param name="archivePath">Path where to create the archive</param> | ||
| /// <param name="includeBaseDirectory">When true, includes top-level directory in the archive</param> | ||
| void ArchiveDirectory(string directoryPath, string archivePath, bool includeBaseDirectory); | ||
|
|
||
| /// <summary> | ||
| /// Creates a new archive containing given file. | ||
| /// </summary> | ||
| /// <param name="filePath">File to archive</param> | ||
| /// <param name="archivePath">Path where to create the archive</param> | ||
| void ArchiveFile(string filePath, string archivePath); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.IO; | ||
premun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using System.IO.Compression; | ||
| using System.Reflection; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Microsoft.Arcade.Common | ||
| { | ||
| public class ZipArchiveManager : IZipArchiveManager | ||
| { | ||
| public async Task AddResourceFileToArchive<TAssembly>(string archivePath, string resourceName, string targetFileName = null) | ||
| { | ||
| using Stream fileStream = GetResourceFileContent<TAssembly>(resourceName); | ||
| await AddContentToArchive(archivePath, targetFileName ?? resourceName, fileStream); | ||
| } | ||
|
|
||
| public void ArchiveDirectory(string directoryPath, string archivePath, bool includeBaseDirectory) | ||
| { | ||
| ZipFile.CreateFromDirectory(directoryPath, archivePath, CompressionLevel.Fastest, includeBaseDirectory); | ||
| } | ||
|
|
||
| public void ArchiveFile(string filePath, string archivePath) | ||
| { | ||
| using (FileStream fs = File.OpenWrite(archivePath)) | ||
| using (var zip = new ZipArchive(fs, ZipArchiveMode.Create, false)) | ||
| { | ||
| zip.CreateEntryFromFile(filePath, Path.GetFileName(filePath)); | ||
| } | ||
| } | ||
|
|
||
| private async Task AddContentToArchive(string archivePath, string targetFilename, Stream content) | ||
| { | ||
| using FileStream archiveStream = new FileStream(archivePath, FileMode.Open); | ||
| using ZipArchive archive = new ZipArchive(archiveStream, ZipArchiveMode.Update); | ||
| ZipArchiveEntry entry = archive.CreateEntry(targetFilename); | ||
| using Stream targetStream = entry.Open(); | ||
| await content.CopyToAsync(targetStream); | ||
| } | ||
|
|
||
| private static Stream GetResourceFileContent<TAssembly>(string resourceFileName) | ||
| { | ||
| Assembly assembly = typeof(TAssembly).Assembly; | ||
| return assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{resourceFileName}"); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using Microsoft.Arcade.Common; | ||
|
|
||
| #nullable enable | ||
| namespace Microsoft.Arcade.Test.Common | ||
| { | ||
| public class MockFileSystem : IFileSystem | ||
| { | ||
| #region File system state | ||
|
|
||
| public HashSet<string> Directories { get; } | ||
|
|
||
| public Dictionary<string, string> Files { get; } | ||
|
|
||
| public List<string> RemovedFiles { get; } = new(); | ||
|
|
||
| #endregion | ||
|
|
||
| public MockFileSystem( | ||
| Dictionary<string, string>? files = null, | ||
| IEnumerable<string>? directories = null) | ||
| { | ||
| Directories = new(directories ?? new string[0]); | ||
| Files = files ?? new(); | ||
| } | ||
|
|
||
| #region IFileSystem implementation | ||
|
|
||
| public void CreateDirectory(string path) => Directories.Add(path); | ||
|
|
||
| public bool DirectoryExists(string path) => Directories.Contains(path); | ||
|
|
||
| public bool FileExists(string path) => Files.ContainsKey(path); | ||
|
|
||
| public void DeleteFile(string path) | ||
| { | ||
| Files.Remove(path); | ||
| RemovedFiles.Add(path); | ||
| } | ||
|
|
||
| public string? GetDirectoryName(string? path) => Path.GetDirectoryName(path); | ||
|
|
||
| public string? GetFileName(string? path) => Path.GetFileName(path); | ||
|
|
||
| public string? GetFileNameWithoutExtension(string? path) => Path.GetFileNameWithoutExtension(path); | ||
|
|
||
| public string? GetExtension(string? path) => Path.GetExtension(path); | ||
|
|
||
| public string PathCombine(string path1, string path2) => path1 + "/" + path2; | ||
|
|
||
| public void WriteToFile(string path, string content) => Files[path] = content; | ||
|
|
||
| public void FileCopy(string sourceFileName, string destFileName) => Files[destFileName] = Files[sourceFileName]; | ||
|
|
||
| public Stream GetFileStream(string path, FileMode mode, FileAccess access) | ||
| => FileExists(path) ? new MemoryStream() : new MockFileStream(this, path); | ||
|
|
||
| #endregion | ||
|
|
||
| /// <summary> | ||
| /// Allows to write to a stream that will end up in the MockFileSystem. | ||
| /// </summary> | ||
| private class MockFileStream : MemoryStream | ||
| { | ||
| private readonly MockFileSystem _fileSystem; | ||
| private readonly string _path; | ||
| private bool _disposed = false; | ||
|
|
||
| public MockFileStream(MockFileSystem fileSystem, string path) | ||
| : base(fileSystem.FileExists(path) ? System.Text.Encoding.UTF8.GetBytes(fileSystem.Files[path]) : new byte[2048]) | ||
| { | ||
| _fileSystem = fileSystem; | ||
| _path = path; | ||
| } | ||
|
|
||
| protected override void Dispose(bool disposing) | ||
| { | ||
| // flush file to our system | ||
| if (!_disposed) | ||
| { | ||
| _disposed = true; | ||
| using var sr = new StreamReader(this); | ||
| Seek(0, SeekOrigin.Begin); | ||
| _fileSystem.WriteToFile(_path, sr.ReadToEnd().Replace("\0", "")); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.