public async Task ReturnsBytesForUpdatedSnapshotAsync() { using (var fileContext = new TemporaryFilesContext("ReturnsBytesForUpdatedSnapshotAsync", false)) { var snapshot = new Snapshot(); snapshot.SetData("Data A", Encoding.UTF8.GetBytes("123")); snapshot.SetData("Large Data", LargeStringBytes); var bytes1 = await snapshot.GetAllBytesAsync(); // Now we update and we should have an updated byte array snapshot.SetData("Data A", Encoding.UTF8.GetBytes("123")); snapshot.SetData("Data B", Encoding.UTF8.GetBytes("456")); snapshot.SetData("Data C", Encoding.UTF8.GetBytes("789")); snapshot.SetData("Large Data", LargeStringBytes); var bytes2 = await snapshot.GetAllBytesAsync(); Assert.AreNotEqual(bytes1, bytes2); var outputFileName = fileContext.GetFile("snapshot.zip"); await File.WriteAllBytesAsync(outputFileName, bytes2); //Approvals.VerifyBinaryFile(bytes2, "zip"); Approvals.VerifyFile(outputFileName); } }
public async Task WritesWithCustomAttributeConvertersAsync() { var writerService = new CsvWriterService(); var attributes = new List <CustomAttribute>(); for (var i = 0; i < 3; i++) { attributes.Add(new CustomAttribute { Value = $"Attribute{i + 1}" }); } var operations = new List <Operation>(); for (var i = 0; i < 5; i++) { var operation = new Operation { Id = i + 1, Name = $"Operation {i + 1}", Enabled = true }; for (var j = 0; j < 5; j++) { operation.Attributes[$"Attribute{j + 1}"] = $"Value {j + 1}"; } operations.Add(operation); } var temporaryFileContext = new TemporaryFilesContext($"{nameof(CsvWriterServiceFacts)}_{nameof(WritesWithCustomAttributeConvertersAsync)}"); var fileName = temporaryFileContext.GetFile("operations.csv"); var classMap = new OperationMap(); classMap.Initialize(attributes.Select(x => x.Value)); var csvContext = new CsvContext <Operation> { ClassMap = classMap }; using (var stream = File.Create(fileName)) { using (var textWriter = new StreamWriter(stream)) { var csvWriter = new CsvWriter(textWriter); csvWriter.Configuration.RegisterClassMap(classMap); csvWriter.WriteRecords(operations); } } await writerService.WriteRecordsAsync(operations, fileName, csvContext); Approvals.VerifyFile(fileName); }
public async Task ReturnsBytesForEmptySnapshotAsync() { using (var fileContext = new TemporaryFilesContext("ReturnsBytesForEmptySnapshotAsync", false)) { var snapshot = new Snapshot(); var bytes = await snapshot.GetAllBytesAsync(); var outputFileName = fileContext.GetFile("snapshot.zip"); await File.WriteAllBytesAsync(outputFileName, bytes); //Approvals.VerifyBinaryFile(bytes, "zip"); Approvals.VerifyFile(outputFileName); } }
private void TestSerializationWithExpectedFormat(ISerializer serializer, string name, object obj) { // Note: not in using since we need the file to be available for comparison var context = new TemporaryFilesContext(name); var fileName = context.GetFile($"{serializer.GetType().Name}.dat", true); using (var fileStream = File.Create(fileName)) { serializer.Serialize(obj, fileStream); fileStream.Flush(); } Approvals.VerifyFile(fileName); }
public async Task ReturnsBytesForSnapshotAsync() { using (var fileContext = new TemporaryFilesContext("ReturnsBytesForSnapshotAsync", false)) { var snapshot = new Snapshot(); snapshot.SetData("Data A", Encoding.UTF8.GetBytes("123")); snapshot.SetData("Data B", Encoding.UTF8.GetBytes("456")); snapshot.SetData("Data C", Encoding.UTF8.GetBytes("789")); snapshot.SetData("Large Data", LargeStringBytes); var bytes = await snapshot.GetAllBytesAsync(); var outputFileName = fileContext.GetFile("snapshot.zip"); await File.WriteAllBytesAsync(outputFileName, bytes); //Approvals.VerifyFile(bytes, "zip"); Approvals.VerifyFile(outputFileName); } }
public static int Link(Context context) { int?exitCode = null; var stopWatch = new Stopwatch(); stopWatch.Start(); context.ValidateContext(); if (!string.IsNullOrEmpty(context.LogFile)) { var fileLogListener = new FileLogListener(context.LogFile, 25 * 1024); fileLogListener.IsDebugEnabled = context.IsDebug; fileLogListener.IgnoreCatelLogging = true; LogManager.AddListener(fileLogListener); } using (var temporaryFilesContext = new TemporaryFilesContext()) { Log.Info("Extracting embedded pdbstr.exe"); var pdbStrFile = temporaryFilesContext.GetFile("pdbstr.exe"); ResourceHelper.ExtractEmbeddedResource("GitLink.Resources.Files.pdbstr.exe", pdbStrFile); try { var projects = new List <Project>(); string[] solutionFiles; if (string.IsNullOrEmpty(context.SolutionFile)) { solutionFiles = Directory.GetFiles(context.SolutionDirectory, "*.sln", SearchOption.AllDirectories); } else { var pathToSolutionFile = Path.Combine(context.SolutionDirectory, context.SolutionFile); if (!File.Exists(pathToSolutionFile)) { Log.Error("Could not find solution file: {0}", pathToSolutionFile); return(-1); } solutionFiles = new[] { pathToSolutionFile }; } foreach (var solutionFile in solutionFiles) { var solutionProjects = ProjectHelper.GetProjects(solutionFile, context.ConfigurationName, context.PlatformName); projects.AddRange(solutionProjects); } var provider = context.Provider; if (provider == null) { throw Log.ErrorAndCreateException <GitLinkException>("Cannot find a matching provider for '{0}'", context.TargetUrl); } Log.Info("Using provider '{0}'", provider.GetType().Name); var shaHash = context.Provider.GetShaHashOfCurrentBranch(context, temporaryFilesContext); Log.Info("Using commit sha '{0}' as version stamp", shaHash); var projectCount = projects.Count(); var failedProjects = new List <Project>(); Log.Info("Found '{0}' project(s)", projectCount); Log.Info(string.Empty); foreach (var project in projects) { try { var projectName = project.GetProjectName(); if (ProjectHelper.ShouldBeIgnored(projectName, context.IncludedProjects, context.IgnoredProjects)) { Log.Info("Ignoring '{0}'", project.GetProjectName()); Log.Info(string.Empty); continue; } if (context.IsDebug) { project.DumpProperties(); } if (!LinkProject(context, project, pdbStrFile, shaHash, context.PdbFilesDirectory)) { failedProjects.Add(project); } } catch (Exception) { failedProjects.Add(project); } } Log.Info("All projects are done. {0} of {1} succeeded", projectCount - failedProjects.Count, projectCount); if (failedProjects.Count > 0) { Log.Info(string.Empty); Log.Info("The following projects have failed:"); Log.Indent(); foreach (var failedProject in failedProjects) { Log.Info("* {0}", context.GetRelativePath(failedProject.GetProjectName())); } Log.Unindent(); } exitCode = (failedProjects.Count == 0) ? 0 : -1; } catch (GitLinkException ex) { Log.Error(ex, "An error occurred"); } catch (Exception ex) { Log.Error(ex, "An unexpected error occurred"); } stopWatch.Stop(); } Log.Info(string.Empty); Log.Info("Completed in '{0}'", stopWatch.Elapsed); exitCode = exitCode ?? -1; if (context.ErrorsAsWarnings && exitCode != 0) { Log.Info("One or more errors occurred, but treating it as warning instead"); exitCode = 0; } return(exitCode.Value); }