public void TestEmbeddTextFileInConsoleApplication() { var fileToEmbed = Path.Combine(RepositoryLocator.Locate(RepositoryDirectory.TestFiles), "test.txt"); var resources = new[] { new ResourceInfo(fileToEmbed, "ConsoleTest.subfolder.test.txt"), new ResourceInfo(fileToEmbed, "TotallyDifferentName.test.txt") }; using (var helper = EmbedHelper(Path.Combine(AssemblyDirectory(), "ConsoleTest.exe"), resources)) { var names = helper.Assembly.GetManifestResourceNames(); names.Should().Contain(new[] { "ConsoleTest.subfolder.test.txt", "TotallyDifferentName.test.txt" }); var tempFile2 = Path.GetTempFileName(); using (var extractedFile = helper.Assembly.GetManifestResourceStream("ConsoleTest.subfolder.test.txt")) using (var fs = new FileStream(tempFile2, FileMode.Truncate)) { extractedFile.Should().NotBeNull(); extractedFile.CopyTo(fs); } File.ReadAllText(tempFile2).Should().Be("Hello world!"); File.Delete(tempFile2); } }
public void TestEmbedTextFileInConsoleExe() { var file = Path.Combine(RepositoryLocator.Locate(RepositoryDirectory.TestFiles), "test.txt"); var command = string.Format("\"/input:{0}\" \"/output:{1}\" {2}>ConsoleTestWithResource.exe.test.txt", Path.Combine(AssemblyDirectory(), "ConsoleTest.exe"), Path.Combine(AssemblyDirectory(), "ConsoleTestWithResource.exe"), file); // embed file into exe var r = Process.Start(Path.Combine(AssemblyDirectory(), "ResourceEmbedderSample.exe"), command); r.WaitForExit(5000).Should().BeTrue(); r.ExitCode.Should().Be(0); // new file should now exist File.Exists(Path.Combine(AssemblyDirectory(), "ConsoleTestWithResource.exe")).Should().BeTrue(); var path = Path.GetTempFileName(); File.Delete(path); // run new file with command line that will extract the resource var r2 = Process.Start(Path.Combine(AssemblyDirectory(), "ConsoleTestWithResource.exe"), string.Format("ConsoleTestWithResource.exe.test.txt {0}", path)); r2.WaitForExit(5000).Should().BeTrue(); r2.ExitCode.Should().Be(0); // since we embedded a text file the file that was extracted should be that same file File.ReadAllText(path).Should().Be("Hello world!"); }
public void TestCopyLocalProjectReference() { // test for https://github.com/MarcStan/Resource.Embedder/issues/5 /* specifically: * * if a project reference is set to CopyLocal: false (and then e.g. copied manually via xcopy script or similar) the resource embedder may fail * it will only fail if the project containing the reference fullfills this requirement: https://github.com/jbevain/cecil/issues/236 * 1. either you have a const field with a TypeRef to an enum or * 2. you have a custom attribute instantiated with a TypeRef to an enum. * * The ProjectForcingCecilAssemblyResolve contains a const reference to an enum from ProjectWithEnum which is a project reference that is marked CopyLocal: False * This enum now forces cecil to actually look for the ProjectWithEnum assembly. Resource.Embeder v1.1.1 and prior used to wrongly look in only the target directory of ProjectForcingCecilAssemblyResolve * Since copy local is false, the ProjectWithEnum reference is not yet found there; crashing Resource.Embedder */ // technically this test never ran with Resource.Embedder v1.1.1 or prior because a clean build always resulted in a crash and no compiled exe // we now use this test to assert that the exe is actually compiled which means that reference bug must now be fixed (otherwise we would get a compile error) var fi = new DirectoryInfo(AssemblyDirectory()); // e.g. net46\Debug var config = Path.Combine(fi.Parent.Name, fi.Name); // locate the exe var file = Path.Combine(RepositoryLocator.Locate(RepositoryDirectory.SourceCode), @"testmodules\ProjectForcingCecilAssemblyResolve\bin\" + config + "\\ProjectForcingCecilAssemblyResolve.exe"); File.Exists(file).Should().BeTrue(); // execute it and capture the output var pi = new ProcessStartInfo(file, "de") { RedirectStandardOutput = true, UseShellExecute = false }; var r2 = new Process { StartInfo = pi }; var lines = new List <string>(); r2.OutputDataReceived += (sender, args) => { if (args.Data != null) { lines.Add(args.Data); } }; r2.Start(); r2.BeginOutputReadLine(); r2.WaitForExit(1000).Should().BeTrue(); r2.ExitCode.Should().Be(0); // verify the output lines.Should().HaveCount(2); lines[0].Should().Be("Language: German"); lines[1].Should().Be("Const enum value is: One"); }
private AccountEnumsDto GetAccountEnumsByTypeCommand(RepositoryLocator locator, string type) { List <AccountEnum> codes = locator.AccountRepository.GetAccountEnumsByType(type); AccountEnumsDto result = new AccountEnumsDto(); foreach (AccountEnum code in codes) { result.AccountEnums.Add(code.ToDto()); } return(result); }
public void TryGetRepositoryPath_fails_when_starting_path_is_not_a_git_repository() { // ARRANGE using var temporaryDirectory = new TemporaryDirectory(); // ACT var success = RepositoryLocator.TryGetRepositoryPath(temporaryDirectory, out var actualRepositoryPath); // ASSERT Assert.False(success); Assert.Null(actualRepositoryPath); }
/// <inheritdoc/> public IRepository GetRepositoryFor(Type type) { foreach (var repo in RepositoryLocator.GetAllRepositories()) { if (repo.SupportsObjectType(type)) { return(repo); } } throw new ArgumentException("Did not know what repository to use to fetch objects of Type '" + type + "'"); }
private void IdentifyAndRemoveOldExtractionResults(ICheckNotifier checkNotifier, IExtractionConfiguration configuration) { var oldResults = configuration.CumulativeExtractionResults .Where(cer => !configuration.GetAllExtractableDataSets().Contains(cer.ExtractableDataSet)) .ToArray(); if (oldResults.Any()) { string message = "In Configuration " + configuration + ":" + Environment.NewLine + Environment.NewLine + "The following CumulativeExtractionResults reflect datasets that were previously extracted under the existing Configuration but are no longer in the CURRENT configuration:"; message = oldResults.Aggregate(message, (s, n) => s + Environment.NewLine + n); if ( checkNotifier.OnCheckPerformed(new CheckEventArgs(message, CheckResult.Fail, null, "Delete expired CumulativeExtractionResults for configuration." + Environment.NewLine + "Not doing so may result in failures at Release time."))) { foreach (var result in oldResults) { result.DeleteInDatabase(); } } } var oldLostSupplemental = configuration.CumulativeExtractionResults .SelectMany(c => c.SupplementalExtractionResults) .Union(configuration.SupplementalExtractionResults) .Where(s => !RepositoryLocator.ArbitraryDatabaseObjectExists(s.ReferencedObjectRepositoryType, s.ReferencedObjectType, s.ReferencedObjectID)) .ToArray(); if (oldLostSupplemental.Any()) { string message = "In Configuration " + configuration + ":" + Environment.NewLine + Environment.NewLine + "The following list reflect objects (supporting sql, lookups or documents) " + "that were previously extracted but have since been deleted:"; message = oldLostSupplemental.Aggregate(message, (s, n) => s + Environment.NewLine + n.DestinationDescription); if ( checkNotifier.OnCheckPerformed(new CheckEventArgs(message, CheckResult.Fail, null, "Delete expired Extraction Results for configuration." + Environment.NewLine + "Not doing so may result in failures at Release time."))) { foreach (var result in oldLostSupplemental) { result.DeleteInDatabase(); } } } }
public async Task TryGetRepositoryPath_fails_when_starting_path_is_a_bare_repository() { // ARRANGE using var temporaryDirectory = new TemporaryDirectory(); var git = new GitWrapper(temporaryDirectory, m_TestOutputHelper); await git.InitAsync(createBareRepository : true); // ACT var success = RepositoryLocator.TryGetRepositoryPath(temporaryDirectory, out var actualRepositoryPath); // ASSERT Assert.False(success); Assert.Null(actualRepositoryPath); }
public async Task TryGetRepositoryPath_succeeds_when_starting_path_is_a_git_repository() { // ARRANGE using var temporaryDirectory = new TemporaryDirectory(); var git = new GitWrapper(temporaryDirectory, m_TestOutputHelper); await git.InitAsync(); // ACT var success = RepositoryLocator.TryGetRepositoryPath(temporaryDirectory, out var actualRepositoryPath); // ASSERT Assert.True(success); Assert.Equal(temporaryDirectory, actualRepositoryPath?.TrimEnd(Path.DirectorySeparatorChar)); }
public void MsBuildBasedEmbeddingWithPortableSymbolsWorksInNetCore() { // copy elsewhere and ensure localization works var copyDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())).FullName; var configuration = #if DEBUG "Debug"; #else "Release"; #endif // must copy from original dir as .Net Core 2.2. can't be referenced from full framework.. // not ideal as it doesn't ensure build is up to date.. // also must copy multiple files for .net core var originalDir = $"{RepositoryLocator.Locate(RepositoryDirectory.SourceCode)}\\testmodules\\Symbols\\NetCorePortable\\bin\\{configuration}\\netcoreapp3.1"; var output = Path.Combine(copyDir, "NetCorePortable.dll"); var outputPdb = Path.Combine(copyDir, "NetCorePortable.pdb"); var toCopy = Directory.GetFiles(originalDir, "*.*", SearchOption.AllDirectories); foreach (var srcFile in toCopy) { var target = srcFile.Substring(originalDir.Length + 1); if (target.Contains("\\")) { Directory.CreateDirectory(Path.Combine(copyDir, target.Substring(0, target.LastIndexOf("\\")))); } File.Copy(srcFile, Path.Combine(copyDir, target)); } var fakeEngine = NSubstitute.Substitute.For <IBuildEngine>(); var task = new SatelliteAssemblyEmbedderTask { ProjectDirectory = ".", AssemblyPath = output, TargetPath = output, BuildEngine = fakeEngine, References = ".", DebugSymbols = true, DebugType = "portable" }; task.Execute().Should().BeTrue(); File.Exists(output).Should().BeTrue(); File.Exists(outputPdb).Should().BeTrue(); var p = Process.Start("dotnet", output); p.WaitForExit(3000).Should().BeTrue(); p.ExitCode.Should().Be(0); Directory.Delete(copyDir, true); }
private AccountEnumsDto InsertUpdateAccountEnumCommand(RepositoryLocator locator, AccountEnumsDto accEnums) { AccountEnumsDto result = new AccountEnumsDto(); List <AccountEnum> accountEnums = new List <AccountEnum>(); foreach (AccountEnumDto accountEnumDto in accEnums.AccountEnums) { accountEnums.Add(accountEnumDto.ToDbEntity()); } List <AccountEnum> listAccountEnum = locator.AccountRepository.InsertUpdateAccountEnum(accountEnums); foreach (AccountEnum accountEnum in listAccountEnum) { result.AccountEnums.Add(accountEnum.ToDto()); } return(result); }
private static bool TryGetRepositoryPath(CommandLineParameters parameters, ILogger logger, [NotNullWhen(true)] out string?repositoryPath) { if (!String.IsNullOrEmpty(parameters.RepositoryPath)) { repositoryPath = Path.GetFullPath(parameters.RepositoryPath); return(true); } if (RepositoryLocator.TryGetRepositoryPath(Environment.CurrentDirectory, out repositoryPath)) { logger.LogInformation($"Found git repository at '{repositoryPath}'"); return(true); } else { logger.LogError($"No git repository found in '{Environment.CurrentDirectory}' or any of its parent directories"); repositoryPath = default; return(false); } }
public FilesController() { _rep = RepositoryLocator.Get <IMessageFileRepository>(); }
public UsersController() { _rep = RepositoryLocator.Get <IUserRepository>(); }
public ChatHub() { _usersRep = RepositoryLocator.Get <IUserRepository>(); }
private static IAccountRepository Handler(RepositoryLocator arg) { var accounts = arg.AccountRepository.FindAllAccounts(); return(arg.AccountRepository); }