// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 using System; using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using AWS.Deploy.Common.IO; namespace AWS.Deploy.Orchestration.UnitTests { public class TestFileManager : IFileManager { public readonly Dictionary InMemoryStore = new Dictionary(); public bool Exists(string path) { return InMemoryStore.ContainsKey(path); } public bool Exists(string path, string directory) => throw new NotImplementedException(); public Task ReadAllTextAsync(string path) { var text = InMemoryStore[path]; return Task.FromResult(text); } public async Task ReadAllLinesAsync(string path) { return (await ReadAllTextAsync(path)).Split(Environment.NewLine); } public Task WriteAllTextAsync(string filePath, string contents, CancellationToken cancellationToken = default) { InMemoryStore[filePath] = contents; return Task.CompletedTask; } public FileStream OpenRead(string filePath) => throw new NotImplementedException(); public string GetExtension(string filePath) => throw new NotImplementedException(); public long GetSizeInBytes(string filePath) => throw new NotImplementedException(); public bool IsFileValidPath(string filePath) => throw new NotImplementedException(); } public static class TestFileManagerExtensions { /// /// Adds a virtual csproj file with valid xml contents /// /// /// Returns the correct full path for /// public static string AddEmptyProjectFile(this TestFileManager fileManager, string relativePath) { relativePath = relativePath.Replace('\\', Path.DirectorySeparatorChar); var fullPath = Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\" : "/", relativePath); fileManager.InMemoryStore.Add(fullPath, ""); return fullPath; } } }