public void Can_Apply(string scenario, string globalJson)
        {
            using (ApprovalResults.ForScenario(scenario))
            {
                // arrange

                var upgradeActions         = new List <ISolutionUpgradeAction>();
                var testFileUpgradeContext = new TestSolutionUpgradeContext(globalJson);

                // updates the sdk version in global json.
                var runtimeUpgradeAction = new UpdateSdkVersion("1.0.0-preview1-002702");
                upgradeActions.Add(runtimeUpgradeAction);

                // Apply these actions to the global.json file.
                foreach (var upgradeAction in upgradeActions)
                {
                    upgradeAction.Apply(testFileUpgradeContext);
                }

                // save the changes.
                testFileUpgradeContext.SaveChanges();

                // assert.
                var modifiedContents = testFileUpgradeContext.ModifiedJsonContents;
                Approvals.VerifyJson(modifiedContents);
            }
        }
Example #2
0
        public void TryParseRevision_test(string testName, bool expectedReturn, bool serialThrows = false)
        {
            using (ApprovalResults.ForScenario(testName.Replace(' ', '_')))
            {
                string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData/RevisionReader", testName + ".bin");
                ArraySegment <byte> chunk = File.ReadAllBytes(path);

                RevisionReader.TestAccessor.TryParseRevision(chunk, _getEncodingByGitName, _logOutputEncoding, _sixMonths, out GitRevision rev)
                .Should().Be(expectedReturn);

                // No LocalTime for the time stamps
                JsonSerializerSettings timeZoneSettings = new()
                {
                    DateTimeZoneHandling = DateTimeZoneHandling.Utc
                };

                if (serialThrows)
                {
                    Action act = () => JsonConvert.SerializeObject(rev);
                    act.Should().Throw <JsonSerializationException>();
                }
                else if (expectedReturn)
                {
                    Approvals.VerifyJson(JsonConvert.SerializeObject(rev, timeZoneSettings));
                }
            }
        }
    }
    public void CreateWithCorrelationAndTransitional(BuildSqlVariant sqlVariant)
    {
        var saga = new SagaDefinition(
            tableSuffix: "theSaga",
            name: "theSaga",
            correlationProperty: new CorrelationProperty
            (
                name: "CorrelationProperty",
                type: CorrelationPropertyType.String
            ),
            transitionalCorrelationProperty: new CorrelationProperty
            (
                name: "TransitionalProperty",
                type: CorrelationPropertyType.String
            )
            );

        var builder = new StringBuilder();

        using (var writer = new StringWriter(builder))
        {
            SagaScriptBuilder.BuildCreateScript(saga, sqlVariant, writer);
        }
        var script = builder.ToString();

        if (sqlVariant == BuildSqlVariant.MsSqlServer)
        {
            SqlValidator.Validate(script);
        }

        using (ApprovalResults.ForScenario(sqlVariant))
        {
            Approvals.Verify(script);
        }
    }
Example #4
0
 public void ForScenarioTest()
 {
     using (ApprovalResults.ForScenario("Scenario"))
     {
         Approvals.Verify("ScenarioValue");
     }
 }
    public void BuildDropScript(BuildSqlDialect sqlDialect)
    {
        var builder = new StringBuilder();

        using (var writer = new StringWriter(builder))
        {
            var saga = new SagaDefinition(
                correlationProperty: new CorrelationProperty
                (
                    name: "CorrelationProperty",
                    type: CorrelationPropertyType.String
                ),
                tableSuffix: "theSaga",
                name: "theSaga"
                );
            SagaScriptBuilder.BuildDropScript(saga, sqlDialect, writer);
        }
        var script = builder.ToString();

        if (sqlDialect == BuildSqlDialect.MsSqlServer)
        {
            SqlValidator.Validate(script);
        }

#if NET452
        using (ApprovalResults.ForScenario(sqlDialect))
        {
            Approvals.Verify(script);
        }
#endif
    }
Example #6
0
        public void CalculateTotalPriceCorrectly(string input, double expectedTotalPrice, string cultureInput, string testName)
        {
            //Arrange
            var consoleStringInput = ConsoleInputBuilder.Build(input);

            CultureSetter.SetCulture(cultureInput);

            var sut = new OrderPlacer(repository, resource); //sut = System under test.

            //Act
#pragma warning disable S1481                                              // Unused local variables should be removed
            using var consoleInput = new ConsoleInput(consoleStringInput); //Exceptions: Unused locally created resources in a using statement are not reported.
#pragma warning restore S1481                                              // Unused local variables should be removed
            using var consoleOutput = new ConsoleOutput();
            sut.PlaceOrder(OrderItemType.Food);
            sut.PlaceOrder(OrderItemType.Drink);
            sut.GetOrderedList();
            var totalPrice = sut.CalculateTotalPrice();

            //Assert
            totalPrice.Should().BeApproximately(expectedTotalPrice, 0.004); //Fluent assertions: https://app.pluralsight.com/library/courses/fluent-assertions-improving-unit-tests/table-of-contents
            using (ApprovalResults.ForScenario(testName))
            {
                Approvals.Verify(consoleOutput.GetOuput()); //Approval Tests: https://app.pluralsight.com/course-player?clipId=23302914-f8f9-4e93-94af-c9420fa8e031
            }
        }
        public void DoAutoCRLF_should_not_unnecessarily_duplicate_line_ending(AutoCRLFType autoCRLFType, string file)
        {
            using (var testHelper = new GitModuleTestHelper())
            {
                testHelper.Module.LocalConfigFile.SetEnum("core.autocrlf", autoCRLFType);
                testHelper.Module.LocalConfigFile.Save();

                var content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.{file}.bin");

                var uiCommands = new GitUICommands(testHelper.Module);
                _uiCommandsSource.UICommands.Returns(x => uiCommands);
                _fileViewer.UICommandsSource = _uiCommandsSource;

                var fvi = _fileViewer.GetTestAccessor().FileViewerInternal;
                fvi.SetText(content, null, false);
                var doc = fvi.GetTestAccessor().TextEditor.Document;
                var end = doc.OffsetToPosition(content.Length);
                fvi.GetTestAccessor().TextEditor.ActiveTextAreaControl.SelectionManager.SetSelection(new TextLocation(0, 0), end);

                // act - 'copy to selection' menu click will call through to DoAutoCRLF
                _fileViewer.GetTestAccessor().CopyToolStripMenuItem.PerformClick();

                // assert
                var text = Clipboard.GetText();
                using (ApprovalResults.ForScenario(file, autoCRLFType))
                {
                    Approvals.Verify(text);
                }
            }
        }
Example #8
0
 public void TemplateHasCorrectSymbols()
 {
     using (ApprovalResults.ForScenario(Suffix))
     {
         Approvals.Verify(Decompiler.Decompile(afterAssemblyPath, "Costura.AssemblyLoader"));
     }
 }
Example #9
0
 public void MsTestV2DataTestMethod(string s)
 {
     using (ApprovalResults.ForScenario(s))
     {
         Approvals.Verify(s);
     }
 }
        public void Can_Apply(string scenario, string json, string xproj)
        {
            using (ApprovalResults.ForScenario(scenario))
            {
                // arrange

                var upgradeActions = new List <IProjectUpgradeAction>();
                var testXProj      = VsProjectFactory.LoadTestProject(xproj);

                var testFileUpgradeContext = new TestJsonBaseProjectUpgradeContext(json, testXProj, null);

                // updates the sdk version in global json.
                var runtimeUpgradeAction = new MigrateProjectImportsFromDnxToDotNet();
                upgradeActions.Add(runtimeUpgradeAction);

                // Apply these actions to the project.json file.
                foreach (var upgradeAction in upgradeActions)
                {
                    upgradeAction.Apply(testFileUpgradeContext);
                }

                // save the changes.
                testFileUpgradeContext.SaveChanges();

                var projContents = VsProjectHelper.ToString(testFileUpgradeContext.VsProjectFile);
                Approvals.VerifyXml(projContents);


                // assert.
                //var modifiedContents = testFileUpgradeContext.ModifiedJsonContents;
                //Approvals.VerifyJson(modifiedContents);

                // Approvals.VerifyAll();
            }
        }
Example #11
0
 public void TestApprovalNameWithAdditionalInformation(string fileName)
 {
     using (ApprovalResults.ForScenario(fileName))
     {
         var name = new UnitTestFrameworkNamer().Name;
         Assert.Equal("XunitTheoryStackTraceParserTest.TestApprovalNameWithAdditionalInformation.ForScenario." + fileName, name);
     }
 }
Example #12
0
 public void TemplateHasCorrectSymbols()
 {
     using (ApprovalResults.ForScenario(nameof(NativeTests)))
     {
         var text = Ildasm.Decompile(TestResult.AssemblyPath, "Costura.AssemblyLoader");
         Approvals.Verify(text);
     }
 }
 public void TestInvalidCharacters(string fileName)
 {
     using (ApprovalResults.ForScenario(fileName))
     {
         var name = new UnitTestFrameworkNamer().Name;
         Assert.Equal("XunitTheoryStackTraceParserTest.TestInvalidCharacters.ForScenario.File _;___1.txt", name);
     }
 }
Example #14
0
 public void WithMultiplePartScenarioData(string a, string b)
 {
     using (ApprovalResults.ForScenario(a, b))
     {
         var name = Approvals.GetDefaultNamer().Name;
         Assert.AreEqual("AdditionalInformationTests.WithMultiplePartScenarioData.ForScenario.foo.bar", name);
     }
 }
Example #15
0
 public void WithScenarioData()
 {
     using (ApprovalResults.ForScenario("scenarioname"))
     {
         var name = Approvals.GetDefaultNamer().Name;
         Assert.AreEqual("AdditionalInformationTests.WithScenarioData.ForScenario.scenarioname", name);
     }
 }
Example #16
0
 public void TemplateHasCorrectSymbols()
 {
     using (ApprovalResults.ForScenario(Suffix))
     {
         var text = Decompiler.Decompile(afterAssemblyPath, "Costura.AssemblyLoader");
         Approvals.Verify(WriterFactory.CreateTextWriter(text), new CustomNamer(), Approvals.GetReporter());
     }
 }
Example #17
0
        public void DoAutoCRLF_should_not_unnecessarily_duplicate_line_ending(AutoCRLFType autoCRLFType, string file)
        {
            var content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.{file}.bin");

            using (ApprovalResults.ForScenario(file, autoCRLFType))
            {
                Approvals.Verify(content.AdjustLineEndings(autoCRLFType));
            }
        }
Example #18
0
        public static void ApproveForScenario(this Xml xml, string scenario)
        {
            Fail.IfArgumentNull(scenario, nameof(scenario));

            using (ApprovalResults.ForScenario(scenario))
            {
                xml.Approve();
            }
        }
Example #19
0
 public void WithScenarioDataScrubsInvalidChars()
 {
     using (ApprovalResults.ForScenario("invalid/chars"))
     {
         var name = Approvals.GetDefaultNamer().Name;
         Assert.AreEqual(
             "AdditionalInformationTests.WithScenarioDataScrubsInvalidChars.ForScenario.invalid_chars", name);
     }
 }
Example #20
0
        public static void ApproveForScenario <T>(this Json <T> json, string scenario)
        {
            Fail.IfArgumentWhiteSpace(scenario, nameof(scenario));

            using (ApprovalResults.ForScenario(scenario))
            {
                json.Approve();
            }
        }
        public void Should_do_ellipsis(string testName)
        {
            var content = EmbeddedResourceLoader.Load(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MockData.{testName}.txt");

            using (ApprovalResults.ForScenario(testName))
            {
                Approvals.Verify(new GitRevisionSummaryBuilder().BuildSummary(content));
            }
        }
 public void CharacterizationTest(ProviderData receivedData, ProviderData existedData)
 {
     using (ApprovalResults.ForScenario(TestContext.CurrentContext.Test.Name))
     {
         var res = processor.ProcessProviderData(receivedData, existedData);
         var s   = res + "\n" + string.Join("\n", memoryAppender.GetEvents().Select(e => e.RenderedMessage));
         Approvals.Verify(s);
     }
 }
 public void Print(ValidationResult validationResult, string scenarioName)
 {
     using (ApprovalResults.ForScenario(scenarioName))
     {
         var printer = new ValidationResultPrinter();
         var sb      = new StringBuilder();
         printer.Print(validationResult, new StringBuilderWriter(sb));
         Approvals.Verify(sb.ToString());
     }
 }
Example #24
0
 public void Validate(List <string> warmup, List <string> movements, Lesson lesson, string scenarioName)
 {
     using (ApprovalResults.ForScenario(scenarioName))
     {
         var validator        = new LessonValidator();
         var validationResult = validator.Validate(warmup, movements, lesson);
         var json             = JsonConvert.SerializeObject(validationResult, Formatting.Indented);
         Approvals.VerifyJson(json);
     }
 }
 public void Print(List <string> warmupMovements, List <string> movements, string scenarioName)
 {
     using (ApprovalResults.ForScenario(scenarioName))
     {
         var printer = new LessonPrinter();
         var sb      = new StringBuilder();
         printer.Print(warmupMovements, movements, new StringBuilderWriter(sb));
         Approvals.Verify(sb.ToString());
     }
 }
Example #26
0
 public void Convert(FileInfo xlsxFile)
 {
     using (ApprovalResults.ForScenario(xlsxFile.Name))
     {
         var sb           = new StringBuilder();
         var xlsxDocument = new XlsxDocumentReader().Read(xlsxFile);
         new XlsxDocumentPrinter(new CenterAlignmentTextFormatter(), new StringBuilderWriter(sb)).Print(xlsxDocument);
         Approvals.Verify(sb.ToString());
     }
 }
Example #27
0
        public void ParseReadableTests([ValueSource("_files")] string file)
        {
            var html = ReadFile(file);

            using (ApprovalResults.ForScenario(file))
            {
                var output = HackerNewsParser.MapResults(html);
                Approvals.Verify(output.String);
            }
        }
Example #28
0
 public void PairwiseApprovals(
     [Values("a", "b", "c")] string a,
     [Values("+", "-")] string b,
     [Values("x", "y")] string c)
 {
     using (ApprovalResults.ForScenario(a, b, c))
     {
         Approvals.Verify($"{a} {b} {c}");
     }
 }
Example #29
0
    public void TemplateHasCorrectSymbols()
    {
        var dataPoints = GetScenarioName();

        using (ApprovalResults.ForScenario(dataPoints))
        {
            var text = Ildasm.Decompile(TestResult.AssemblyPath, "Costura.AssemblyLoader");
            Approvals.Verify(text);
        }
    }
Example #30
0
        public void ParseJsonTests([ValueSource("_files")] string file)
        {
            var html = ReadFile(file);

            using (ApprovalResults.ForScenario(file))
            {
                var output = TwitterParser.MapResults(html);
                Approvals.Verify(output.Json);
            }
        }