//[Ignore] public void ShouldPersistToHDF5() { // Check and delete the HDF5 file here, NOT in TearDown, because we // want the file to exist after the test run (contrary to everything // unit-testing preaches) so that we can look at the file contents via // h5dump to verify what it looks like; unfortunately, at this time, // unit-testing HDF5 is a PITA (pain in the ass, for those of you // who are acronymatically challenged), so approval testing // is the next-best-thing we can do at the moment. if (File.Exists("..\\..\\..\\ShouldPersistToHDF5.h5")) { File.Delete("..\\..\\..\\ShouldPersistToHDF5.h5"); } var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldPersistToHDF5.h5", null, () => gID)) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary <string, object>(); props["key1"] = "value1"; props["key2"] = 2; exp.BeginEpochGroup("label", "source identifier", new[] { "keyword1", "keyword2" }, props, guid, time); exp.Serialize(testEpoch); exp.EndEpochGroup(); exp.Close(); } H5.Close(); Approvals.VerifyFile("..\\..\\..\\ShouldPersistToHDF5.h5"); }
//[UseReporter(typeof(FileLauncherReporter))] public void SingleEpochHDF5Persistence() { if (File.Exists("SingleEpochHDF5Persistence.h5")) { File.Delete("SingleEpochHDF5Persistence.h5"); } var gID = new Guid("a5839fe9-90ef-4e39-bf26-8f75048306a4"); using (var exp = new EpochHDF5Persistor("SingleEpochHDF5Persistence.h5", null, () => gID)) { var time = new DateTimeOffset(2011, 8, 22, 11, 12, 0, 0, TimeSpan.FromHours(-6)); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); exp.BeginEpochGroup("label1", "source1", new string[0], new Dictionary <string, object>(), guid, time); RunSingleEpoch(5000, 2, exp); exp.EndEpochGroup(); exp.Close(); } Approvals.VerifyFile("SingleEpochHDF5Persistence.h5"); }
public void RenderFromGraphInFileToFile() { string outputFilePath = Path.Combine(Directory.GetCurrentDirectory(), "RenderFromGraphInFile.png"); const string graph = @"digraph G { node [style=filled, shape=rect] # Nodes ""String age"" -> ""Int64.Parse()"" -> {""Int64"", ""Collector""} # Formatting ""String age"" [color=green] ""Int64"" [color=""#9fbff4""] ""Int64.Parse()"" [shape=invhouse] ""Collector"" [color = ""#c361f4""] { rank=same; ""Int64.Parse()"", ""Collector""} }"; string inputFilePath = Path.Combine(Directory.GetCurrentDirectory(), "RenderFromInGraphInFile.dot"); File.WriteAllText(inputFilePath, graph); var graphViz = new GraphViz(); graphViz.LayoutAndRenderDotGraphFromFile(inputFilePath, outputFilePath, "png"); Approvals.VerifyFile(outputFilePath); }
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); }
//[Ignore] public void ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose() { if (File.Exists("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.h5")) { File.Delete("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.h5"); } var gID = new Guid("{FE5B733F-B3FB-4523-BDCC-CECB97D1CB0B}"); using ( var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.h5", null, () => gID)) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var guid2 = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97E"); exp.BeginEpochGroup("label1", "source1", new string[0], new Dictionary <string, object>(), guid, time); exp.BeginEpochGroup("label2", "source2", new string[0], new Dictionary <string, object>(), guid2, time); exp.Serialize(testEpoch); exp.Close(); } Approvals.VerifyFile("..\\..\\..\\ShouldAutomaticallyCloseOpenEpochGroupsOnPersistorClose.h5"); }
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 void SerializingDefaultConfiguration() { var config = new Config(); ConfigSerializer.SaveConfiguration(testDirectory, config); Approvals.VerifyFile(testFile); }
public void WHEN_approved_file_doesnt_exists_THEN_show_only_recived() { File.Copy(imagesDirectory + "testSource1.jpg", fileNameUnderTest, true); SetGeneratedApprovedFilePath(); File.Delete(generatedApprovedFilePath); Approvals.VerifyFile(fileNameUnderTest); }
public void TestExistingFile() { var path = PathUtilities.GetDirectoryForCaller(); var copy = path + "copyOfa.txt"; File.Copy(path + "a.txt", copy, true); Approvals.VerifyFile(copy); }
public void MultipleSeries() { var row1 = new Row <double, int>("Row1", new[] { 0.1, 0.2, 0.3, 0.4 }, new[] { 5, 4, 3, 4 }); var row2 = new Row <double, int>("Row2", new[] { 0.0, 0.2, 0.3, 0.7 }, new[] { 1, 2, 7, 10 }); var outputfile = new GnuPlotScript("Hello World!!!").Render(new[] { row1, row2 }); Approvals.VerifyFile(outputfile.Outputfile); }
public void MapImages() { var service = new MapService(); var filename = @"c:\tmp\image.jpg"; service.GetMapImage(filename, -34.9859652, 138.7019549); Approvals.VerifyFile(filename); }
private void TestTwoFiles(string srcFile, string approvedFile) { string srcApprovedFilePath = imagesDirectory + approvedFile; SetGeneratedApprovedFilePath(); File.Copy(imagesDirectory + srcFile, fileNameUnderTest, true); File.Copy(srcApprovedFilePath, generatedApprovedFilePath, true); Approvals.VerifyFile(fileNameUnderTest); }
public void TestEnsureFileExist() { var imageFile = PathUtilities.GetAdjacentFile("TestImage.png"); if (File.Exists(imageFile)) { File.Delete(imageFile); } GenericDiffReporter.EnsureFileExists(imageFile); Approvals.VerifyFile(imageFile); }
public void LoggingOutputTest() { string filePath = Path.Combine(Environment.CurrentDirectory, "nlog-sample.txt"); using (new TemporaryNLogLogger(filePath)) { var story = new ReportTestData() .CreateOneStoryWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples(); var sut = new ScenarioLoggingProcessor(); sut.Process(story); Approvals.VerifyFile(filePath); } }
public void ShouldAllowMultipleOpenPersistors() { if (File.Exists("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.h5")) { File.Delete("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.h5"); } if (File.Exists("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5")) { File.Delete("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5"); } var gID = new Guid("{FE5B733F-B3FB-4523-BDCC-CECB97D1CB0B}"); using (var p1 = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.h5", null, () => gID) ) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var guid2 = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97E"); p1.BeginEpochGroup("label1", "source1", new string[0], new Dictionary <string, object>(), guid, time); p1.BeginEpochGroup("label2", "source2", new string[0], new Dictionary <string, object>(), guid2, time); using ( var p2 = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5", null, () => gID) ) { p2.BeginEpochGroup("label1", "source1", new string[0], new Dictionary <string, object>(), guid, time); p2.BeginEpochGroup("label2", "source2", new string[0], new Dictionary <string, object>(), guid2, time); p2.Serialize(testEpoch); p2.EndEpochGroup(); p2.EndEpochGroup(); } p1.Serialize(testEpoch); p1.EndEpochGroup(); p1.EndEpochGroup(); } Approvals.VerifyFile("..\\..\\..\\ShouldAllowMultipleOpenPersistors1.h5"); Approvals.VerifyFile("..\\..\\..\\ShouldAllowMultipleOpenPersistors2.h5"); }
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 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); } }
public void SerializingConfigurationWithCustomSettings() { var config = new Config { NextVersion = "0.5.0", Tag = "rc", TypeScopes = new HashSet <TypeScope> { new TypeScope("yes", new Description("Singular", "Plural"), "my scope"), new TypeScope("feature", new Description("Feature", "Features")) } }; ConfigSerializer.SaveConfiguration(testDirectory, config); Approvals.VerifyFile(testFile); }
public void ConvertToTif() { var destination = new FileInfo(Path.GetTempPath() + "test_ConvertToTif.tif"); GhostscriptWrapper.GenerateOutput( inputPath: TEST_FILE_LOCATION, outputPath: destination.FullName, settings: new GhostscriptSettings { Device = GhostscriptDevices.tiffg4, Resolution = new Size(400, 400), Page = GhostscriptPages.All, Size = new GhostscriptPageSize { Native = GhostscriptPageSizes.a4 }, }); Approvals.VerifyFile(destination.FullName); }
public void Verify_All(ApprovalFileInfo approvalFileInfo) { System.Console.WriteLine("Testing {0}", approvalFileInfo.SourcePath); // need to backup the file as the approval test deletes the original file File.Copy(approvalFileInfo.SourcePath, approvalFileInfo.SourcePath + ".bak", true); using (ApprovalResults.ForScenario(approvalFileInfo.Scenario)) { Approvals.VerifyFile(approvalFileInfo.SourcePath); } if (File.Exists(approvalFileInfo.SourcePath + ".bak")) { // restore the backup File.Copy(approvalFileInfo.SourcePath + ".bak", approvalFileInfo.SourcePath, overwrite: true); File.Delete(approvalFileInfo.SourcePath + ".bak"); } }
private void VerifyUpdatedPdb(string outputDirectoryBase, string name, bool verifySrcSrv = false) { var pdbFileName = Path.Combine(outputDirectoryBase, name, string.Format("{0}.pdb", name)); if (verifySrcSrv) { // Required for Approvals var pdbSrcSrvFileName = string.Format("{0}.srcsrv", pdbFileName); var pdbSrcSrvTxtFileName = string.Format("{0}.txt", pdbSrcSrvFileName); File.Copy(pdbSrcSrvFileName, pdbSrcSrvTxtFileName, true); Approvals.VerifyFile(pdbSrcSrvTxtFileName); } var containsVariables = false; var containsControl = false; var containsServer = false; var pdbContents = File.ReadAllLines(pdbFileName); foreach (var pdbContent in pdbContents) { if (pdbContent.Contains("SRCSRV: variables")) { containsVariables = true; } if (pdbContent.Contains("SRCSRVVERCTRL=")) { containsControl = true; } if (pdbContent.Contains("SRCSRVTRG=")) { containsServer = true; } } if (!containsVariables || !containsControl || !containsServer) { throw new Exception("Generated pdb file is invalid"); } }
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 void AllProcessTest() { var builder = new ContainerBuilder(); builder.RegisterModule(new TagsCloudModule()); builder.RegisterType <TestingLayouter>().As <ITagsCloudLayouter>().SingleInstance(); builder.RegisterType <ColoredRenderer>().As <ITagsCloudRenderer>().SingleInstance(); var container = builder.Build(); var inputFileName = Path.ChangeExtension(Path.GetTempFileName(), ".txt"); File.WriteAllText(inputFileName, "Съешь ещё этих мягких французских булок, да выпей же чаю"); var wordsLoader = container.Resolve <WordsLoader>(); var words = wordsLoader.LoadWords(inputFileName); var filters = container.Resolve <IFilter[]>() .Where(f => f.GetType() == typeof(WasteWordsFilter) || f.GetType() == typeof(UpperCaseFilter)) .OrderByDescending(f => f.GetType().Name).ToArray(); var wordsFilterer = container.Resolve <WordsFilterer>(new NamedParameter("filters", filters)); var filteredWords = wordsFilterer.FilterWords(words); var layouter = container.Resolve <ITagsCloudLayouter>(); var renderer = container.Resolve <ITagsCloudRenderer>(); var tagCloud = container.Resolve <TagsCloudGenerator>( new NamedParameter("layouter", layouter as ITagsCloudLayouter), new NamedParameter("renderer", renderer as ITagsCloudRenderer)); var image = tagCloud.GenerateCloud(filteredWords); var filename = Path.ChangeExtension(Path.GetTempFileName(), ".png"); var imageSaveHelper = container.Resolve <ImageSaveHelper>(); imageSaveHelper.SaveTo(image, filename); Approvals.VerifyFile(filename); }
public void ApprovalFunctionalTest_ShouldRenderUsingFormatter() { var formatterMock = new Mock <ITagsCloudFormatter>(); formatterMock.SetupGet(m => m.FontFamily).Returns(FontFamily.GenericMonospace); formatterMock.SetupGet(m => m.BackgroundBrush).Returns(Brushes.Black); formatterMock.SetupGet(m => m.FontBrush).Returns(Brushes.Yellow); formatterMock.SetupGet(m => m.ImageSize).Returns(new Size(700, 700)); var formatter = formatterMock.Object; var layouter = new CircularCloudLayouter(formatter, new Point(300, 300)); var layout = layouter.GetLayout(new[] { "word", "word", "word", "anotherWord", "oneMoreWord" }); var renderer = new DefaultTagsCloudRenderer <Bitmap>(formatter); var bitmap = renderer.Render(layout).GetRenderingResult(); var filename = $"{nameof(ApprovalFunctionalTest_ShouldRenderUsingFormatter)}.png"; var bitmapSaver = new PngTagsCloudSaver(filename); bitmapSaver.Save(bitmap); Approvals.VerifyFile(filename); }
public void Can_set_json_property(string[] keys) { // Arrange using var approver = ApprovalTests.Namers.ApprovalResults.ForScenario(string.Join("__", keys)); var line = string.Concat(Enumerable.Repeat('-', 50)); var sourceFile = Path.Combine(_currentWorkingDirectory, $"secrets-set-test({string.Join(" ", keys)}).json"); // Act foreach (var item in keys) { JsonEditor.SetProperty(sourceFile, item, 123); System.Diagnostics.Debug.WriteLine($"arg: {item}"); var result = File.ReadAllText(sourceFile); System.Diagnostics.Debug.WriteLine(result); System.Diagnostics.Debug.WriteLine(line); System.Diagnostics.Debug.WriteLine(string.Empty); System.Diagnostics.Debug.WriteLine(string.Empty); } // Assert Approvals.VerifyFile(sourceFile); }
public void ShouldAllowNumericEpochParameters() { if (File.Exists("..\\..\\..\\ShouldAllowNumericEpochParameters.h5")) { File.Delete("..\\..\\..\\ShouldAllowNumericEpochParameters.h5"); } var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowNumericEpochParameters.h5", null, () => gID) ) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary <string, object>(); props["int"] = 2; props["float"] = 2.0f; props["double"] = 2.0d; props["decimal"] = 2.0m; props["array"] = new[] { 1.0, 2.0, 3.0 }; props["short"] = (short)2; props["unit16"] = (UInt16)1; props["uint32"] = (UInt32)2; props["byte"] = (byte)1; props["bool"] = true; const string protocolID = "Epoch.Fixture"; Dictionary <string, object> parameters = props; dev1 = new UnitConvertingExternalDevice(dev1Name, "DEVICECO", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice(dev2Name, "DEVICECO", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary <string, object>(); stimParameters[param1] = value1; stimParameters[param2] = value2; var srate = new Measurement(1000, "Hz"); List <Measurement> samples = Enumerable.Range(0, 10000).Select(i => new Measurement((decimal)Math.Sin((double)i / 100), "V")). ToList(); var stimData = new OutputData(samples, srate, false); var stim1 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var stim2 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var e = new Epoch(protocolID, parameters); e.Stimuli[dev1] = stim1; e.Stimuli[dev2] = stim2; DateTimeOffset start = DateTimeOffset.Parse("1/11/2011 6:03:29 PM -08:00"); // Do this to match the XML stored in the EpochXML.txt resource e.StartTime = Maybe <DateTimeOffset> .Yes(start); e.Background[dev1] = new Epoch.EpochBackground(new Measurement(0, "V"), new Measurement(1000, "Hz")); e.Background[dev2] = new Epoch.EpochBackground(new Measurement(1, "V"), new Measurement(1000, "Hz")); e.Responses[dev1] = new Response(); e.Responses[dev2] = new Response(); var streamConfig = new Dictionary <string, object>(); streamConfig[param1] = value1; var devConfig = new Dictionary <string, object>(); devConfig[param2] = value2; IInputData responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); IInputData responseData2 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); e.Responses[dev1].AppendData(responseData1); e.Responses[dev2].AppendData(responseData2); e.Keywords.Add(kw1); e.Keywords.Add(kw2); exp.BeginEpochGroup("label", "source identifier", new[] { "keyword1", "keyword2" }, props, guid, time); exp.Serialize(e); exp.EndEpochGroup(); exp.Close(); } H5.Close(); Approvals.VerifyFile("..\\..\\..\\ShouldAllowNumericEpochParameters.h5"); }
public void TestSuccessVerifyFilePath() { Approvals.VerifyFile(@"..\..\MyFile.error", "My Exception Content"); }
public void TestMethod1() { var outputfile = new GnuPlotScript("Hello World!!!").Render(new Row <double, int>("Hello World!!!", new[] { 0.1, 0.2, 0.3, 0.4 }, new[] { 5, 4, 3, 4 })); Approvals.VerifyFile(outputfile.Outputfile); }