public void PassesWhenFileInfoExists() { using (var actualTestFile = new TestFile(TEST_FILE, RESOURCE_FILE)) { Assert.That(_constraint.ApplyTo(actualTestFile.File).IsSuccess); Assert.That(actualTestFile.File, Does.Exist); } }
public void PassesWhenFileStringExists() { using (var tf = new TestFile(TEST_FILE, RESOURCE_FILE)) { Assert.That(_constraint.ApplyTo(tf.File.FullName).IsSuccess); Assert.That(tf.File.FullName, Does.Exist); } }
public void ChangeExtensionWithNull() { // Setup var file = new TestFile(@"x:\directory\File.txt"); // Execute var result = file.ChangeExtension(a_extension: null); }
public void AreEqualPassesWithEqualStreams() { using (var tf1 = new TestFile("Test1.jpg", "TestImage1.jpg")) using (var tf2 = new TestFile("Test2.jpg", "TestImage1.jpg")) using (FileStream expected = tf1.File.OpenRead()) using (FileStream actual = tf2.File.OpenRead()) { FileAssert.AreEqual(expected, actual); } }
public void NonReadableStreamGivesException() { using (var tf1 = new TestFile("Test1.jpg", "TestImage1.jpg")) using (var tf2 = new TestFile("Test2.jpg", "TestImage1.jpg")) using (FileStream expected = tf1.File.OpenRead()) using (FileStream actual = tf2.File.OpenWrite()) { var ex = Assert.Throws<ArgumentException>(() => FileAssert.AreEqual(expected, actual)); Assert.That(ex.Message, Does.Contain("not readable")); } }
public void ChangeExtension() { // Setup var file = new TestFile(@"x:\directory\File.txt"); // Execute var result = file.ChangeExtension("jpg"); Assert.AreEqual("File.jpg", result.Name); Assert.AreEqual(@"x:\directory\File.jpg", result.Path); }
public void ConstructTestFile() { // Setup var fileSystem = new TestFileSystem(); // Execute var file = new TestFile(fileSystem, "\\file.dat"); // Assert Assert.AreEqual("\\file.dat", file.Path); Assert.AreSame(fileSystem, file.FileSystem); }
public void CallExistsWithNonexistingFile() { // Setup var fileSystem = new TestFileSystem(); var file = new TestFile(fileSystem, "\\file\\does\\not\\exist.dat"); // Execute var result = file.Exists; // Assert Assert.IsFalse(result); }
public void CallExistsOnExistingFile() { // Setup var path = "\\file\\does\\exist.dat"; var fileSystem = new TestFileSystem(); fileSystem.StageFile(path, new TestFileInstance()); var file = new TestFile(fileSystem, path); // Execute var result = file.Exists; // Assert Assert.IsTrue(result); }
void AddFiles(TreeList<TestFile> tree, Folder testFolder, Folder resultFolder) { foreach (var name in suite.TestNames(testFolder)) { var testFile = new TestFile { FileName = Path.GetFileNameWithoutExtension(name), Path = tree.Value.FullName }; var result = new TestResult(resultFolder, testFile); testFile.TestStatus = result.Status; tree.Add(testFile); } foreach (var subfolder in suite.SubFolders(testFolder)) { var branch = new TreeList<TestFile>(new TestFile {FileName = subfolder.Name(), Path = tree.Value.FullName, IsFolder = true}); tree.Add(branch); AddFiles(branch, subfolder, resultFolder.SubFolder(subfolder.Name())); } }
private async Task <SignatureHelpResponse> GetSignatureHelp(string filename, string source) { var testFile = new TestFile(filename, source); using (var host = CreateOmniSharpHost(testFile)) { var point = testFile.Content.GetPointFromPosition(); var request = new SignatureHelpRequest() { FileName = testFile.FileName, Line = point.Line, Column = point.Offset, Buffer = testFile.Content.Code }; var requestHandler = GetRequestHandler(host); return(await requestHandler.Handle(request)); } }
public async Task CodeCheckSpecifiedFileOnly(string filename) { SharedOmniSharpTestHost.ClearWorkspace(); var testFile = new TestFile(filename, "class C { int n = true; }"); var emitter = new DiagnosticTestEmitter(); var forwarder = new DiagnosticEventForwarder(emitter) { IsEnabled = true }; var service = CreateDiagnosticService(forwarder); SharedOmniSharpTestHost.AddFilesToWorkspace(testFile); var controller = new DiagnosticsService(forwarder, service); var response = await controller.Handle(new DiagnosticsRequest { FileName = testFile.FileName }); await emitter.ExpectForEmitted(msg => msg.Results.Any(m => m.FileName == filename)); }
public async Task CheckAllFiles(string filename1, string filename2) { SharedOmniSharpTestHost.ClearWorkspace(); var testFile1 = new TestFile(filename1, "class C1 { int n = true; }"); var testFile2 = new TestFile(filename2, "class C2 { int n = true; }"); SharedOmniSharpTestHost.AddFilesToWorkspace(testFile1, testFile2); var emitter = new DiagnosticTestEmitter(); var forwarder = new DiagnosticEventForwarder(emitter); var service = CreateDiagnosticService(forwarder); var controller = new DiagnosticsService(forwarder, service); var response = await controller.Handle(new DiagnosticsRequest()); await emitter.ExpectForEmitted(msg => msg.Results .Any(r => r.FileName == filename1 && r.QuickFixes.Count() == 1)); await emitter.ExpectForEmitted(msg => msg.Results .Any(r => r.FileName == filename2 && r.QuickFixes.Count() == 1)); }
public async Task RespectFolderName_InOfferedRefactorings(string expectedNamespace, params string[] relativePath) { var testFile = new TestFile(Path.Combine(TestAssets.Instance.TestFilesFolder, Path.Combine(relativePath)), @"namespace Xx$$x { }"); using (var host = CreateOmniSharpHost(new[] { testFile }, null, path: TestAssets.Instance.TestFilesFolder)) { var point = testFile.Content.GetPointFromPosition(); var getRequestHandler = host.GetRequestHandler <GetCodeActionsService>(OmniSharpEndpoints.V2.GetCodeActions); var getRequest = new GetCodeActionsRequest { Line = point.Line, Column = point.Offset, FileName = testFile.FileName }; var getResponse = await getRequestHandler.Handle(getRequest); Assert.NotNull(getResponse.CodeActions); Assert.Contains(getResponse.CodeActions, f => f.Name == $"Change namespace to '{expectedNamespace}'"); } }
public void SaveAndLoad_Work() { // save findings using new O2AssessmentSave_OunceV7 engine var savedFile = new O2AssessmentSave_OunceV7().save(Findings_Load); // check that it exists Assert.That(TestFile.fileExists(), "Couldn't find O2AssessmentSave_OunceV7 saved file"); // check that we can load the saved file with 7x var o2Assessment = new O2AssessmentLoad_OunceV7_0().loadFile(savedFile); Assert.That(o2Assessment.notNull(), "O2AssessmentLoad_OunceV7_0 failed to load"); // check that we CAN'T load the saved file with 6.1 o2Assessment = new O2AssessmentLoad_OunceV6_1().loadFile(savedFile); Assert.That(o2Assessment.isNull(), "O2AssessmentLoad_OunceV6_1 failed to load"); // check that we CAN'T load the saved file with 6.0 o2Assessment = new O2AssessmentLoad_OunceV6().loadFile(savedFile); Assert.That(o2Assessment.isNull(), "O2AssessmentLoad_OunceV6_0 failed to load"); }
public async Task ReturnsOnListFindResult(string filename) { var testFile = new TestFile(filename, @" using System.Collections.Generic; class Test { public Bar Foo { get; set; } public class |def:Bar| { public int lorem { get; set; } } public static void Main() { var list = new List<Bar>(); list.Add(new Bar()); var out$$put = list.Find(input => _ = input.lorem == 12); } }"); await TestGoToSourceAsync(testFile); }
public void Encode_PreserveQuality(string imagePath, int quality) { var options = new JpegEncoder(); var testFile = TestFile.Create(imagePath); using (Image <Rgba32> input = testFile.CreateImage()) { using (var memStream = new MemoryStream()) { input.Save(memStream, options); memStream.Position = 0; using (var output = Image.Load <Rgba32>(memStream)) { JpegMetaData meta = output.MetaData.GetFormatMetaData(JpegFormat.Instance); Assert.Equal(quality, meta.Quality); } } } }
public void CodeTreeWithUsings() { var syntaxTreeNode = new Mock <Span>(new SpanBuilder()); var language = new CSharpRazorCodeLanguage(); var host = new RazorEngineHost(language); var context = CodeGeneratorContext.Create(host, "TestClass", "TestNamespace", "Foo.cs", shouldGenerateLinePragmas: false); context.CodeTreeBuilder.AddUsingChunk("FakeNamespace1", syntaxTreeNode.Object); context.CodeTreeBuilder.AddUsingChunk("FakeNamespace2.SubNamespace", syntaxTreeNode.Object); var codeBuilder = language.CreateCodeBuilder(context); // Act var result = codeBuilder.Build(); BaselineWriter.WriteBaseline(@"test\Microsoft.AspNet.Razor.Test\TestFiles\CodeGenerator\CS\Output\CSharpCodeBuilder.cs", result.Code); var expectedOutput = TestFile.Create("TestFiles/CodeGenerator/CS/Output/CSharpCodeBuilder.cs").ReadAllText(); // Assert Assert.Equal(expectedOutput, result.Code); }
public void RunTests(string filePath, int lineNumber) { TestFile testFile = GetTestFileByPath(filePath); TestFile newFile = PowerShellTestDiscoverer.DiscoverTestFile(filePath); if (testFile == null) { testFile = newFile; AddTestFile(testFile); } else { testFile.Merge(newFile); } TestModel model = testFile.FindModelByLineNumber(lineNumber); if (model != null) { DoRunCommandAsync(model); } }
public void ImageShouldBeOverlayedByFilledPolygonImage() { string path = this.CreateOutputDirectory("Drawing", "FilledPolygons"); SixLabors.Primitives.PointF[] simplePath = new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) }; using (Image <Rgba32> brushImage = TestFile.Create(TestImages.Bmp.Car).CreateImage()) using (Image <Rgba32> image = new Image <Rgba32>(500, 500)) { ImageBrush <Rgba32> brush = new ImageBrush <Rgba32>(brushImage); image .BackgroundColor(Rgba32.Blue) .FillPolygon(brush, simplePath) .Save($"{path}/Image.png"); } }
public async Task ExtendsTextChangeAtEnd() { var testFile = new TestFile("dummy.cs", "class {\n}"); using (var host = CreateOmniSharpHost(testFile)) { var document = host.Workspace.GetDocument(testFile.FileName); var text = await document.GetTextAsync(); var textChange = new TextChange(TextSpan.FromBounds(5, 7), "\r\n {\r"); var adjustedTextChanges = TextChanges.Convert(text, textChange); var adjustedTextChange = adjustedTextChanges.First(); Assert.Equal("\r\n {\r\n", adjustedTextChange.NewText); Assert.Equal(0, adjustedTextChange.StartLine); Assert.Equal(5, adjustedTextChange.StartColumn); Assert.Equal(1, adjustedTextChange.EndLine); Assert.Equal(0, adjustedTextChange.EndColumn); } }
public static void DetectSeparator() { using (var file = new TestFile(";")) { var tr = new TimetableReader(file.FileName); Assert.Equal(1, tr.Strings.Count); Assert.Equal(2, tr.Strings[0].Length); } using (var file = new TestFile(",")) { var tr = new TimetableReader(file.FileName); Assert.Equal(1, tr.Strings.Count); Assert.Equal(2, tr.Strings[0].Length); } using (var file = new TestFile("\t")) { Assert.Throws(typeof(InvalidDataException), () => { var tr = new TimetableReader(file.FileName); }); } }
protected override StageResult Init() { if (TrainOp) { Contract.Requires(TrainingFile != null && TestFile == null); if (!TrainingFile.CheckExistsAndReportError(L)) { return(StageResult.INPUT_ERROR); } if (!TestFile.CheckExistsAndReportError(L)) { return(StageResult.INPUT_ERROR); } if (!ModelFileName.IsEmpty() && ModelFile.Exists && !OverwriteOutputFile) { Error("The model file {0} exists but the overwrite option was not specified.", ModelFile.FullName); return(StageResult.INPUT_ERROR); } } return(StageResult.SUCCESS); }
public void ImageBlendingMatchesSvgSpecExamples <TPixel>(TestImageProvider <TPixel> provider, PixelColorBlendingMode mode) where TPixel : struct, IPixel <TPixel> { using (Image <TPixel> background = provider.GetImage()) using (var source = Image.Load <TPixel>(TestFile.Create(TestImages.Png.Ducky).Bytes)) { background.Mutate(x => x.DrawImage(source, mode, 1F)); background.DebugSave( provider, new { mode = mode }, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); var comparer = ImageComparer.TolerantPercentage(0.01F); background.CompareToReferenceOutput(comparer, provider, new { mode = mode }, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); } }
public void Encode_IgnoreMetadataIsTrue_CommentsAreNotWritten() { var options = new GifEncoder(); var testFile = TestFile.Create(TestImages.Gif.Rings); using (Image <Rgba32> input = testFile.CreateRgba32Image()) { input.Metadata.Properties.Clear(); using (var memStream = new MemoryStream()) { input.SaveAsGif(memStream, options); memStream.Position = 0; using (var output = Image.Load <Rgba32>(memStream)) { Assert.Equal(0, output.Metadata.Properties.Count); } } } }
public static RazorSourceDocument CreateResource( string path, Assembly assembly, Encoding encoding, RazorSourceDocumentProperties properties, bool normalizeNewLines = false) { var file = TestFile.Create(path, assembly); using (var input = file.OpenRead()) using (var reader = new StreamReader(input)) { var content = reader.ReadToEnd(); if (normalizeNewLines) { content = NormalizeNewLines(content); } return(new StringSourceDocument(content, encoding ?? Encoding.UTF8, properties)); } }
public async Task ReturnsOnImplicitLambdaParam(string filename) { var testFile = new TestFile(filename, @" using System.Collections.Generic; class Test { public Bar Foo { get; set; } public class |def:Bar| { public int lorem { get; set; } } public static void Main() { var list = new List<Bar>(); list.Add(new Bar()); list.ForEach(inp$$ut => _ = input.lorem); } }"); await TestGoToSourceAsync(testFile); }
public void Quality_0_And_1_Are_Identical() { var options = new JpegEncoder { Quality = 0 }; var testFile = TestFile.Create(TestImages.Jpeg.Baseline.Calliphora); using (Image <Rgba32> input = testFile.CreateRgba32Image()) using (var memStream0 = new MemoryStream()) using (var memStream1 = new MemoryStream()) { input.SaveAsJpeg(memStream0, options); options.Quality = 1; input.SaveAsJpeg(memStream1, options); Assert.Equal(memStream0.ToArray(), memStream1.ToArray()); } }
public async Task Returns_only_syntactic_diagnotics() { using (var testProject = await TestAssets.Instance.GetTestProjectAsync("EmptyProject")) { var testfile = new TestFile("a.cs", "class C { b a = new b(); int n }"); using (var host = CreateOmniSharpHost(testProject.Directory)) { var filePath = AddTestFile(testProject, testfile); await WaitForFileUpdate(filePath, host); var request = new CodeCheckRequest() { FileName = filePath }; var actual = await host.GetResponse <CodeCheckRequest, QuickFixResponse>(OmniSharpEndpoints.CodeCheck, request); Assert.Single(actual.QuickFixes); Assert.Equal("; expected", actual.QuickFixes.First().Text); } } }
public async Task Rename_DoesNotDuplicateRenamesWithMultipleFrameworks() { const string fileContent = @" using System; public class Program { public void Main(bool aBool$$ean) { Console.Write(aBoolean); } }"; var testFile = new TestFile("test.cs", fileContent); var result = await PerformRename(testFile, "foo", wantsTextChanges : true); var changes = result.Changes.ToArray(); Assert.Single(changes); Assert.Equal(testFile.FileName, changes[0].FileName); Assert.Equal(2, changes[0].Changes.Count()); }
public TestResult(Folder folder, TestFile file) { this.file = file; if (file.IsFolder) return; var path = file.FileName + ".html"; if (!folder.Pages.Contains(path)) return; using (var input = folder.Pages[path].Reader) { var line = input.ReadLine(); if (line.Length < 8) return; var content = line.Substring(4, line.Length - 7).Split(','); if (content.Length < 5) return; runTime = content[0]; counts = new TestCounts(); counts.SetCount(TestStatus.Right, int.Parse(content[1])); counts.SetCount(TestStatus.Wrong, int.Parse(content[2])); counts.SetCount(TestStatus.Ignore, int.Parse(content[3])); counts.SetCount(TestStatus.Exception, int.Parse(content[4])); } }
public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit) { var testFile = TestFile.Create(imagePath); using (Image <Rgba32> input = testFile.CreateRgba32Image()) { using (var memStream = new MemoryStream()) { input.Save(memStream, JpegEncoder); memStream.Position = 0; using (var output = Image.Load <Rgba32>(memStream)) { ImageMetadata meta = output.Metadata; Assert.Equal(xResolution, meta.HorizontalResolution); Assert.Equal(yResolution, meta.VerticalResolution); Assert.Equal(resolutionUnit, meta.ResolutionUnits); } } } }
public async Task Rename_CanRenameInComments() { const string code = @" using System; namespace ConsoleApplication { /// <summary> /// This program performs an important work and calls Bar. /// </summary> public class Program { static void Ba$$r() {} } }"; const string expectedCode = @" using System; namespace ConsoleApplication { /// <summary> /// This program performs an important work and calls Foo. /// </summary> public class Program { static void Foo() {} } }"; var testFile = new TestFile("test.cs", code); using (var host = CreateOmniSharpHost(new[] { testFile }, new Dictionary <string, string> { ["RenameOptions:RenameInComments"] = "true" })) { await ValidateRename(host, testFile, expectedCode, async() => await PerformRename(host, testFile, "Foo", applyTextChanges: true)); } }
private static async Task <NavigateResponse> SendRequest( OmniSharpTestHost host, TestFile testFile, int startLine, int startColumn, Direction direction) { switch (direction) { case Direction.Up: { var requestHandler = host.GetRequestHandler <NavigateUpService>(OmniSharpEndpoints.NavigateUp); var request = new NavigateUpRequest { Line = startLine, Column = startColumn, FileName = testFile.FileName, Buffer = testFile.Content.Code }; return(await requestHandler.Handle(request)); } case Direction.Down: { var requestHandler = host.GetRequestHandler <NavigateDownService>(OmniSharpEndpoints.NavigateDown); var request = new NavigateDownRequest { Line = startLine, Column = startColumn, FileName = testFile.FileName, Buffer = testFile.Content.Code }; return(await requestHandler.Handle(request)); } } return(null); }
private async Task <CompletionResponse> FindCompletionsAsync(string filename, string source, OmniSharpTestHost host, char?triggerChar = null, TestFile[] additionalFiles = null) { var testFile = new TestFile(filename, source); var files = new[] { testFile }; if (additionalFiles is object) { files = files.Concat(additionalFiles).ToArray(); } host.AddFilesToWorkspace(files); var point = testFile.Content.GetPointFromPosition(); var request = new CompletionRequest { Line = point.Line, Column = point.Offset, FileName = testFile.FileName, Buffer = testFile.Content.Code, CompletionTrigger = triggerChar is object?CompletionTriggerKind.TriggerCharacter : CompletionTriggerKind.Invoked, TriggerCharacter = triggerChar }; var updateBufferRequest = new UpdateBufferRequest { Buffer = request.Buffer, Column = request.Column, FileName = request.FileName, Line = request.Line, FromDisk = false }; await GetUpdateBufferHandler(host).Handle(updateBufferRequest); var requestHandler = GetRequestHandler(host); return(await requestHandler.Handle(request)); }
public async Task UpdateBuffer_TransientDocumentsDisappearWhenProjectAddsThem() { var testFile = new TestFile("test.cs", "class C {}"); using (var host = CreateOmniSharpHost(testFile)) { await host.Workspace.BufferManager.UpdateBufferAsync(new Request() { FileName = "transient.cs", Buffer = "interface I {}" }); var docIds = host.Workspace.CurrentSolution.GetDocumentIdsWithFilePath("transient.cs"); Assert.Equal(2, docIds.Length); // simulate a project system adding the file for real var project1 = host.Workspace.CurrentSolution.Projects.First(); var document = DocumentInfo.Create(DocumentId.CreateNewId(project1.Id), "transient.cs", loader: TextLoader.From(TextAndVersion.Create(SourceText.From("enum E{}"), VersionStamp.Create())), filePath: "transient.cs"); var newSolution = host.Workspace.CurrentSolution.AddDocument(document); host.Workspace.TryApplyChanges(newSolution); docIds = host.Workspace.CurrentSolution.GetDocumentIdsWithFilePath("transient.cs"); Assert.Equal(2, docIds.Length); await host.Workspace.BufferManager.UpdateBufferAsync(new Request() { FileName = "transient.cs", Buffer = "enum E {}" }); var sourceText = await host.Workspace.CurrentSolution.GetDocument(docIds.First()).GetTextAsync(); Assert.Equal("enum E {}", sourceText.ToString()); sourceText = await host.Workspace.CurrentSolution.GetDocument(docIds.Last()).GetTextAsync(); Assert.Equal("enum E {}", sourceText.ToString()); } }
public async Task IncludesContainingTypeFoNestedTypesForRegularCSharpSyntax() { var source = @"namespace Bar { class Foo { class Xyz {} } }"; var testFile = new TestFile("dummy.cs", source); using (var host = CreateOmniSharpHost(testFile)) { var requestHandler = GetRequestHandler(host); var request = new TypeLookupRequest { FileName = testFile.FileName, Line = 2, Column = 27 }; var response = await requestHandler.Handle(request); Assert.Equal("Bar.Foo.Xyz", response.Type); } }
public void GetArgsFromFiles(string commandLine, string files, params string[] expectedArgs) { var filespecs = files.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var testFiles = new TestFile[filespecs.Length]; for (int ix = 0; ix < filespecs.Length; ++ix) { var filespec = filespecs[ix]; var split = filespec.IndexOf(':'); if (split < 0) { throw new Exception("Invalid test data"); } var fileName = filespec.Substring(0, split); var fileContent = filespec.Substring(split + 1); testFiles[ix] = new TestFile(Path.Combine(TestContext.CurrentContext.TestDirectory, fileName), fileContent, true); } var options = new NUnitLiteOptions(); string[] expandedArgs; try { expandedArgs = options.PreParse(CommandLineOptions.GetArgs(commandLine)).ToArray(); } finally { foreach (var tf in testFiles) { tf.Dispose(); } } Assert.AreEqual(expectedArgs, expandedArgs); Assert.Zero(options.ErrorMessages.Count); }
public void Encode_PreserveBits(string imagePath, PngBitDepth pngBitDepth) { var options = new PngEncoder(); var testFile = TestFile.Create(imagePath); using (Image <Rgba32> input = testFile.CreateImage()) { using (var memStream = new MemoryStream()) { input.Save(memStream, options); memStream.Position = 0; using (var output = Image.Load <Rgba32>(memStream)) { PngMetadata meta = output.Metadata.GetFormatMetadata(PngFormat.Instance); Assert.Equal(pngBitDepth, meta.BitDepth); } } } }
public async Task UsesRoslynBlockStructureService() { var testFile = new TestFile("foo.cs", @"class Foo[| { void M()[| { if (false)[| { }|] }|] }|]"); var text = testFile.Content.Text; var lineSpans = (await GetResponseAsync(testFile)).Spans .Select(b => b.Range) .ToArray(); var expected = testFile.Content.GetSpans() .Select(span => testFile.Content.GetRangeFromSpan(span).ToRange()).ToArray(); Assert.Equal(expected, lineSpans); }
public async Task AppendingToDeletedFileThrowsError() { await using var test = await TestFile.CreateAsync(_network); var appendedContent = Encoding.Unicode.GetBytes(Generator.Code(50)); var deleteRecord = await test.Client.DeleteFileAsync(test.Record.File, test.CreateParams.Signatory); Assert.Equal(ResponseCode.Success, deleteRecord.Status); var exception = await Assert.ThrowsAnyAsync <TransactionException>(async() => { await test.Client.AppendFileAsync(new AppendFileParams { File = test.Record.File, Contents = appendedContent, Signatory = test.CreateParams.Signatory }); }); Assert.StartsWith("Unable to append to file, status: FileDeleted", exception.Message); }
public void AreEqualPassesUsingSameFileTwice() { using (var tf1 = new TestFile("Test1.jpg", "TestImage1.jpg")) { FileAssert.AreEqual(tf1.File.FullName, tf1.File.FullName); } }
public void CopyInWithNotExistingFile() { // Setup var fileSystem = new TestFileSystem(); var directory = fileSystem.StageDirectory(@"\directory"); var file = new TestFile(fileSystem, @"\file1.dat"); // Execute directory.CopyIn(file); }
public void DoesNotExistFailsWhenStringExists() { using (var tf1 = new TestFile("Test1.txt", "TestText1.txt")) { var ex = Assert.Throws<AssertionException>(() => FileAssert.DoesNotExist(tf1.File.FullName)); Assert.That(ex.Message, Does.StartWith(" Expected: not file exists")); } }
public void ExistsPassesWhenStringExists() { using (var tf1 = new TestFile("Test1.txt", "TestText1.txt")) { FileAssert.Exists(tf1.File.FullName); } }
public void ExistsPassesWhenFileInfoExists() { using (var actualTestFile = new TestFile("Test1.txt", "TestText1.txt")) { FileAssert.Exists(actualTestFile.File); } }
public void AreNotEqualIteratesOverTheEntireFileAndFails() { using (var tf1 = new TestFile("Test1.txt", "TestText1.txt")) using (var tf2 = new TestFile("Test2.txt", "TestText1.txt")) { var expectedMessage = " Expected: not equal to <System.IO.FileStream>" + Environment.NewLine + " But was: <System.IO.FileStream>" + Environment.NewLine; var ex = Assert.Throws<AssertionException>(() => FileAssert.AreNotEqual(tf1.File.FullName, tf2.File.FullName)); Assert.That(ex.Message, Is.EqualTo(expectedMessage)); } }
public void AreEqualFailsWhenOneIsNull() { using (var tf1 = new TestFile("Test1.jpg", "TestImage1.jpg")) using (FileStream expected = tf1.File.OpenRead()) { var expectedMessage = " Expected: <System.IO.FileStream>" + Environment.NewLine + " But was: null" + Environment.NewLine; var ex = Assert.Throws<AssertionException>(() => FileAssert.AreEqual(expected, null)); Assert.That(ex.Message, Is.EqualTo(expectedMessage)); } }
public void AreNotEqualPassesWithFileInfos() { using (var expectedTestFile = new TestFile("Test1.jpg", "TestImage1.jpg")) using (var actualTestFile = new TestFile("Test2.jpg", "TestImage2.jpg")) { FileAssert.AreNotEqual(expectedTestFile.File, actualTestFile.File); } }
public void AreNotEqualPassesWithFiles() { using (var tf1 = new TestFile("Test1.jpg", "TestImage1.jpg")) using (var tf2 = new TestFile("Test2.jpg", "TestImage2.jpg")) { FileAssert.AreNotEqual(tf1.File.FullName, tf2.File.FullName); } }
public void AreNotEqualPassesIfOneIsNull() { using (var tf1 = new TestFile("Test1.jpg", "TestImage1.jpg")) using (FileStream expected = tf1.File.OpenRead()) { FileAssert.AreNotEqual(expected, null); } }
public void AreEqualFailsWithTextFilesAfterReadingBothFiles() { using (var tf1 = new TestFile("Test1.txt", "TestText1.txt")) using (var tf2 = new TestFile("Test2.txt", "TestText2.txt")) { var expectedMessage = string.Format( " Stream lengths are both {0}. Streams differ at offset {1}." + Environment.NewLine, tf1.FileLength, tf1.OffsetOf('!')); var ex = Assert.Throws<AssertionException>(() => FileAssert.AreEqual(tf1.File.FullName, tf2.File.FullName)); Assert.That(ex.Message, Is.EqualTo(expectedMessage)); } }
public void AreEqualFailsWithFiles() { string expected = "Test1.jpg"; string actual = "Test2.jpg"; using (var expectedTestFile = new TestFile(expected, "TestImage1.jpg")) using (var actualTestFile = new TestFile(actual, "TestImage2.jpg")) { var expectedMessage = string.Format(" Expected Stream length {0} but was {1}." + Environment.NewLine, expectedTestFile.File.Length, actualTestFile.File.Length); var ex = Assert.Throws<AssertionException>(() => FileAssert.AreEqual(expectedTestFile.File.FullName, actualTestFile.File.FullName)); Assert.That(ex.Message, Is.EqualTo(expectedMessage)); } }
public void AreEqualFailsWithStreams() { string expectedFile = "Test1.jpg"; string actualFile = "Test2.jpg"; using (var tf1 = new TestFile(expectedFile, "TestImage1.jpg")) using (var tf2 = new TestFile(actualFile, "TestImage2.jpg")) using (FileStream expected = tf1.File.OpenRead()) using (FileStream actual = tf2.File.OpenRead()) { var expectedMessage = string.Format(" Expected Stream length {0} but was {1}." + Environment.NewLine, tf1.File.Length, tf2.File.Length); var ex = Assert.Throws<AssertionException>(() => FileAssert.AreEqual(expected, actual)); Assert.That(ex.Message, Is.EqualTo(expectedMessage)); } }
static string Show(TestFile file) { return string.Format("{0},{1},{2},{3}", file.Path, file.FileName, file.IsFolder, file.TestStatus); }
public void AreNotEqualFailsWithFiles() { using (var tf1 = new TestFile("Test1.jpg", "TestImage1.jpg")) { var expectedMessage = " Expected: not equal to <System.IO.FileStream>" + Environment.NewLine + " But was: <System.IO.FileStream>" + Environment.NewLine; var ex = Assert.Throws<AssertionException>(() => FileAssert.AreNotEqual(tf1.File.FullName, tf1.File.FullName)); Assert.That(ex.Message, Is.EqualTo(expectedMessage)); } }
public void AreNotEqualIteratesOverTheEntireFile() { using (var tf1 = new TestFile("Test1.txt", "TestText1.txt")) using (var tf2 = new TestFile("Test2.txt", "TestText2.txt")) { FileAssert.AreNotEqual(tf1.File.FullName, tf2.File.FullName); } }
public void AreEqualPassesWithTextFiles() { using (var tf1 = new TestFile("Test1.txt", "TestText1.txt")) using (var tf2 = new TestFile("Test2.txt", "TestText1.txt")) { FileAssert.AreEqual(tf1.File.FullName, tf2.File.FullName); } }
public void AreNotEqualFailsWithStreams() { using (var tf1 = new TestFile("Test1.jpg", "TestImage1.jpg")) using (var tf2 = new TestFile("Test2.jpg", "TestImage1.jpg")) using (FileStream expected = tf1.File.OpenRead()) using (FileStream actual = tf2.File.OpenRead()) { var expectedMessage = " Expected: not equal to <System.IO.FileStream>" + Environment.NewLine + " But was: <System.IO.FileStream>" + Environment.NewLine; var ex = Assert.Throws<AssertionException>(() => FileAssert.AreNotEqual(expected, actual)); Assert.That(ex.Message, Is.EqualTo(expectedMessage)); } }
public FileBase AsFile(string name = "this-is-a-test", string extension = "md") { var content = new StringBuilder(); if (!string.IsNullOrEmpty(_startHeader)) { content.AppendNewLine(_startHeader); } if (!string.IsNullOrEmpty(_title)) { content.AppendNewLine("title: " + _title); } if (!string.IsNullOrEmpty(_summary)) { content.AppendNewLine("summary: " + _summary); } if (!string.IsNullOrEmpty(_date)) { content.AppendNewLine("date: " + _date); } if (!string.IsNullOrEmpty(_tags)) { content.AppendNewLine("tags: " + _tags); } if (!string.IsNullOrEmpty(_endHeader)) { content.AppendNewLine(_endHeader); } if (!string.IsNullOrEmpty(_body.ToString())) { content.Append(_body); } var file = new TestFile(new MemoryStream(Encoding.UTF8.GetBytes(content.ToString()))) { Name = name, Extension = extension }; return file; }