public void StringRepresentation() { Approvals.Verify( new ApprovalTextWriter(GetBlock().ToString()), new DerivedClassUnitTestFrameworkNamer("BlockScenarioBase", this), Approvals.GetReporter()); }
public static void Verify(string text) { var writer = new ApprovalTextWriter(text); var namer = new ApprovalNamer(); Approvals.Verify(writer, namer, Approvals.GetReporter()); }
public void TestClassLevel() { using (Approvals.SetFrontLoadedReporter(ReportWithoutFrontLoading.INSTANCE)) { Assert.AreEqual(typeof(DiffReporter), Approvals.GetReporter().GetType()); } }
public void TestMultipleReporters() { using (Approvals.SetFrontLoadedReporter(ReportWithoutFrontLoading.INSTANCE)) { Assert.AreEqual(typeof(MultiReporter), Approvals.GetReporter().GetType()); } }
public void TestMethodOverride() { using (Approvals.SetFrontLoadedReporter(ReportWithoutFrontLoading.INSTANCE)) { Assert.AreEqual(typeof(MethodLevelReporter), Approvals.GetReporter().GetType()); } }
private void CommandLogReflectsScript(ExampleAction target) { Approvals.Verify( new ApprovalTextWriter(Scrubbers.ScrubDates(recordingConnection.GetCommandLog())), new CustomUnitTestFrameworkNamer(target.ToString().Replace(" ", string.Empty)), Approvals.GetReporter()); }
public static void ApprovePublicApi(Assembly assembly) { var publicApi = ApiGenerator.GeneratePublicApi(assembly, new ApiGeneratorOptions()); var writer = new ApprovalTextWriter(publicApi, "cs"); var approvalNamer = new AssemblyPathNamer(assembly.Location); Approvals.Verify(writer, approvalNamer, Approvals.GetReporter()); }
public void GeneratePublicApiDescription() { Assembly assembly = typeof(Fail).Assembly; var publicApi = assembly.GeneratePublicApi(); var writer = new ApprovalTextWriter(publicApi, "txt"); var approvalNamer = new AssemblyPathNamer(assembly); Approvals.Verify(writer, approvalNamer, Approvals.GetReporter()); }
public async Task TestAsyncMethodOverride() { await Task.Delay(1); using (Approvals.SetFrontLoadedReporter(ReportWithoutFrontLoading.INSTANCE)) { Assert.AreEqual(typeof(MethodLevelReporter), Approvals.GetReporter().GetType()); } }
public void Assembly_must_not_have_unapproved_API_changes() { // ARRANGE var assembly = typeof(Badge).Assembly; // ACT var publicApi = ApiGenerator.GeneratePublicApi(assembly, options: null); // ASSERT var writer = new ApprovalTextWriter(publicApi); Approvals.Verify(writer, new UnitTestFrameworkNamer(), Approvals.GetReporter()); }
public void ApproveDrawingImage(string resourceName) { var icon = new Image(); var control = CreateDisplayFrame(resourceName, icon); icon.Source = (DrawingImage)control.FindResource(resourceName); PrepareForRender(control); Approvals.Verify( new ImageWriter(f => WpfUtils.ScreenCapture(control, f)), new IconTestsNamer(resourceName), Approvals.GetReporter()); }
public static void DiffWith(this string expected, string actual) { if (expected != actual) { var expectedFile = Path.GetTempPath() + "Expected.Approvals.Temp.txt"; var actualFile = Path.GetTempPath() + "Actual.Approvals.Temp.txt"; File.WriteAllText(expectedFile, expected); File.WriteAllText(actualFile, actual); var reporter = Approvals.GetReporter(); reporter.Report(expectedFile, actualFile); } }
public void Generate() { // ARRANGE var assembly = typeof(Fail).Assembly; // ACT var publicApi = ApiDescription.GenerateFor(assembly); // ASSERT var writer = new MarkdownTextWriter(publicApi); var approvalNamer = new PublicApi.PublicApiGenerator.AssemblyPathNamer(assembly); Approvals.Verify(writer, approvalNamer, Approvals.GetReporter()); }
public void ApproveControlTemplate(string resourceName) { var icon = new ContentControl { Foreground = Brushes.Green }; var control = CreateDisplayFrame(resourceName, icon); icon.Template = (ControlTemplate)control.FindResource(resourceName); PrepareForRender(control); Approvals.Verify( new ImageWriter(f => WpfUtils.ScreenCapture(control, f)), new IconTestsNamer(resourceName), Approvals.GetReporter()); }
public void ApproveGeometry(string resourceName) { var icon = new Path { Fill = Brushes.Black, Stretch = Stretch.Uniform }; var control = CreateDisplayFrame(resourceName, icon); icon.Data = (Geometry)control.FindResource(resourceName); PrepareForRender(control); Approvals.Verify( new ImageWriter(f => WpfUtils.ScreenCapture(control, f)), new IconTestsNamer(resourceName), Approvals.GetReporter()); }
protected void Approve(ApplicationChangeLog changeLog, ChangeLogConfiguration?configuration = null) { var sut = GetTemplateInstance(configuration ?? ChangeLogConfigurationLoader.GetDefaultConfiguration()); using (var temporaryDirectory = new TemporaryDirectory()) { var outputPath = Path.Combine(temporaryDirectory, "changelog.md"); sut.SaveChangeLog(changeLog, outputPath); Assert.True(File.Exists(outputPath)); var output = File.ReadAllText(outputPath); var writer = new ApprovalTextWriter(output); Approvals.Verify(writer, new ApprovalNamer(GetType().Name), Approvals.GetReporter()); } }
public void MakeBadge_returns_expected_svg( BadgeStyle style, [CombinatorialValues("Hello")] string leftText, [CombinatorialValues("World")] string rightText, [CombinatorialValues("yellow", "red")] string color, [CombinatorialValues(null, "", "blue")] string labelColor, [CombinatorialValues(null, "http://example.com")] string leftLink, [CombinatorialValues(null, "http://github.com")] string rightLink) { var testId = GetTestCaseFileName(style, leftText, rightText, color, labelColor, leftLink, rightLink); var leftUri = leftLink != null ? new Uri(leftLink) : null; var rightUri = rightLink != null ? new Uri(rightLink) : null; var badge = Badge.MakeBadge(style, leftText, rightText, color, labelColor, leftUri, rightUri); var writer = new ApprovalTextWriter(GetBadgeHtml(badge, style, leftText, rightText, color, labelColor, leftLink, rightLink), "html"); Approvals.Verify(writer, new ApprovalNamer(testId), Approvals.GetReporter()); }
public static void ApprovePublicApi(string assemblyPath) { var assemblyResolver = new DefaultAssemblyResolver(); assemblyResolver.AddSearchDirectory(Path.GetDirectoryName(assemblyPath)); var readSymbols = File.Exists(Path.ChangeExtension(assemblyPath, ".pdb")); var asm = AssemblyDefinition.ReadAssembly(assemblyPath, new ReaderParameters(ReadingMode.Deferred) { ReadSymbols = readSymbols, AssemblyResolver = assemblyResolver, }); var publicApi = PublicApiGenerator.CreatePublicApiForAssembly(asm); var writer = new ApprovalTextWriter(publicApi, "cs"); var approvalNamer = new AssemblyPathNamer(assemblyPath); Approvals.Verify(writer, approvalNamer, Approvals.GetReporter()); }
public static void AssertIlCode(string assemblyFileName, [CallerMemberName] string callerMemberName = "") { var slug = callerMemberName.GetSlug(); var assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyFileName); var loadAssembliesOnStartupTypeDefinition = assemblyDefinition.MainModule.GetType("LoadAssembliesOnStartup"); var loadAssembliesOnStartupMethodDefinition = loadAssembliesOnStartupTypeDefinition.Methods.First(x => x.Name == "LoadTypesOnStartup"); var methodBody = loadAssembliesOnStartupMethodDefinition.Body; methodBody.SimplifyMacros(); var actualIlBuilder = new StringBuilder(); foreach (var instruction in methodBody.Instructions) { var line = instruction.ToString(); if (instruction.Operand is TypeReference operationTypeReference) { line += $" | {operationTypeReference.Scope}"; } actualIlBuilder.AppendLine(line); } var actualIl = actualIlBuilder.ToString(); // Note: don't dispose, otherwise we can't use approvals var tempFileContext = new TemporaryFilesContext(slug); var actualFile = tempFileContext.GetFile($"actual_il_{_configurationName}.txt", true); File.WriteAllText(actualFile, actualIl); var writer = new ExistingFileWriter(actualFile); var namer = new ApprovalNamer(); Approvals.Verify(writer, namer, Approvals.GetReporter()); //Approvals.VerifyFile(actualFile); }
public void ApproveApi(string frameworkVersion) { string codeBase = Assembly.GetExecutingAssembly().CodeBase !; UriBuilder uri = new UriBuilder(new Uri(codeBase)); string assemblyPath = Uri.UnescapeDataString(uri.Path); var containingDirectory = Path.GetDirectoryName(assemblyPath); var configurationName = new DirectoryInfo(containingDirectory).Parent.Name; var assemblyFile = Path.GetFullPath( Path.Combine( GetSourceDirectory(), $"../../src/{ProjectName}/bin/{configurationName}/{frameworkVersion}/{ProjectName}.dll")); var assembly = Assembly.LoadFile(Path.GetFullPath(assemblyFile)); var publicApi = ApiGenerator.GeneratePublicApi(assembly, options: null); Approvals.Verify( WriterFactory.CreateTextWriter(publicApi), new ApprovalNamer(ProjectName, frameworkVersion), Approvals.GetReporter()); }
private static IApprovalFailureReporter DetermineReporter() { IApprovalFailureReporter approvalFailureReporter = Approvals.GetReporter(); string typeName = Environment.GetEnvironmentVariable("ApiApproval.Reporter"); if (!string.IsNullOrWhiteSpace(typeName)) { if (!typeName.Contains(".")) { typeName = "ApprovalTests.Reporters." + typeName; } if (!typeName.EndsWith("Reporter")) { typeName += "Reporter"; } Type type = typeof(IApprovalFailureReporter).Assembly.GetType(typeName, throwOnError: true, ignoreCase: true); approvalFailureReporter = (IApprovalFailureReporter)Activator.CreateInstance(type); } return(approvalFailureReporter); }
private void WpfApprove(ContentControl control) { using (AddAdditionalInfo()) Approvals.Verify(new ImageWriter(f => WpfUtils.ScreenCapture(control, f)), new DerivedClassUnitTestFrameworkNamer("BlockScenarioBase", this), Approvals.GetReporter()); }
public void TemplateHasCorrectSymbols() { using (ApprovalResults.ForScenario(Suffix)) { var text = Decompiler.Decompile(afterAssemblyPath, "Costura.AssemblyLoader"); Approvals.Verify(WriterFactory.CreateTextWriter(text), new CustomNamer(), Approvals.GetReporter()); } }
public void TestClassLevel() { Assert.AreEqual(typeof(ClassLevelReporter), Approvals.GetReporter().GetType()); }
protected void Approve(string testCaseName) { var writer = new ApprovalTextWriter(LoadOutput(), "html"); Approvals.Verify(writer, new ApprovalNamer(testCaseName), Approvals.GetReporter()); }
protected void Verify(string name, string value) { Approvals.Verify(WriterFactory.CreateTextWriter(value), new Namer(name), Approvals.GetReporter()); }
protected void BasicRoundtripTest(IEdmModel edmModel, bool skipBaseline = false) { IEnumerable <EdmError> errors; var csdlElements = this.GetSerializerResult(edmModel, out errors).ToArray(); ExceptionUtilities.Assert(!errors.Any(), "Did not expect serializer errors: " + string.Join(",", errors.Select(e => e.ErrorMessage))); #if !SILVERLIGHT if (!skipBaseline) { var csdl = PrettyPrintCsdl(csdlElements) + Environment.NewLine; Approvals.Verify(new ApprovalTextWriter(csdl), new CustomSourcePathNamer(this.TestContext.DeploymentDirectory), Approvals.GetReporter()); } #endif IEdmModel resultEdmModel = this.GetParserResult(csdlElements); CsdlToEdmModelComparer.Compare(csdlElements.Select(XElement.Parse), resultEdmModel); }
public void TestMethodOverride() { Assert.AreEqual(typeof(MethodLevelReporter), Approvals.GetReporter().GetType()); }
public void TestMultipleReporters() { Assert.AreEqual(typeof(MultiReporter), Approvals.GetReporter().GetType()); }
private void SubMethod() { Assert.AreEqual(typeof(MethodLevelReporter), Approvals.GetReporter().GetType()); }