public void CorrectInputNotActivatesHelp() { var options = new MockOptions(); var writer = new StringWriter(); bool result = base.Parser.ParseArguments( new string[] { "-imath.xml", "-oresult.xml" }, options, writer); base.AssertParserSuccess(result); Assert.AreEqual(0, writer.ToString(System.Globalization.CultureInfo.InvariantCulture).Length); }
public void CorrectInputNotActivatesHelp() { var options = new MockOptions(); var writer = new StringWriter(); Result = base.Parser.ParseArguments( new string[] { "-imath.xml", "-oresult.xml" }, options, writer); ResultShouldBeTrue();; writer.ToString().Length.Should().Equal(0); }
public void Correct_input_not_activates_help() { var options = new MockOptions(); var writer = new StringWriter(); var parser = new CommandLine.Parser(with => with.HelpWriter = writer); var result = parser.ParseArguments( new string[] { "-imath.xml", "-oresult.xml" }, options); result.Should().BeTrue();; writer.ToString().Length.Should().Be(0); }
public void GetTestResults_FileWithInvalidStatusAttribute_WarningAndEmptyResult() { IEnumerable <Model.TestCase> testCases = CreateDummyTestCases("GoogleTestSuiteName1.TestMethod_001", "GoogleTestSuiteName1.TestMethod_002"); MockOptions.Setup(o => o.DebugMode).Returns(true); XmlTestResultParser parser = new XmlTestResultParser(testCases, XmlFileBroken_InvalidStatusAttibute, TestEnvironment, ""); List <Model.TestResult> results = parser.GetTestResults(); Assert.AreEqual(0, results.Count); MockLogger.Verify(l => l.LogWarning(It.IsAny <string>()), Times.Exactly(1)); }
public void ExplicitHelpActivation() { MockOptions options = new MockOptions(); TextWriter writer = new StringWriter(); bool success = Parser.ParseArguments( new string[] { "--help" }, options, writer); Assert.IsFalse(success); string helpText = writer.ToString(); Assert.IsTrue(helpText.Length > 0); }
public virtual void GetTestsFromExecutable_RegexAfterFromOptionsOneEqualTrait_FindsTestTestWithOneEqualTrait() { string testname = "Traits.WithEqualTraits"; MockOptions.Setup(o => o.TraitsRegexesAfter).Returns( new List <RegexTraitPair> { new RegexTraitPair(Regex.Escape(testname), "Author", "Foo") }); Trait[] traits = { new Trait("Author", "Foo") }; AssertFindsTestWithTraits(testname, traits); }
public void ExplicitHelpActivation() { var options = new MockOptions(); var writer = new StringWriter(); bool result = base.Parser.ParseArguments( new string[] { "--help" }, options, writer); base.AssertParserFailure(result); string helpText = writer.ToString(); Assert.IsTrue(helpText.Length > 0); }
public void CreateTestCases_AdditionalTestDiscoveryParam_TestDiscoveryUsesAdditionalTestDiscoveryParams() { MockOptions.Setup(o => o.AdditionalTestDiscoveryParam).Returns("-testDiscoveryFlag"); MockOptions.Setup(o => o.ParseSymbolInformation).Returns(false); var reportedTestCases = new List <TestCase>(); var factory = new TestCaseFactory(TestResources.TestDiscoveryParamExe, MockLogger.Object, TestEnvironment.Options, null); var returnedTestCases = factory.CreateTestCases(testCase => reportedTestCases.Add(testCase)); reportedTestCases.Count.Should().Be(2); reportedTestCases.Should().Contain(t => t.FullyQualifiedName == "TestDiscovery.TestFails"); reportedTestCases.Should().Contain(t => t.FullyQualifiedName == "TestDiscovery.TestPasses"); }
public void SplitTestcases_MoreThreadsThanTests_TestsAreDistributedEvenly() { IEnumerable <Model.TestCase> testCasesWithCommonSuite = TestDataCreator.CreateDummyTestCases("FooSuite.BarTest", "FooSuite.BazTest"); MockOptions.Setup(o => o.MaxNrOfThreads).Returns(8); ITestsSplitter splitter = new NumberBasedTestsSplitter(testCasesWithCommonSuite, TestEnvironment.Options); List <List <Model.TestCase> > result = splitter.SplitTestcases(); result.Should().HaveCount(2); result[0].Should().ContainSingle(); result[1].Should().ContainSingle(); }
public MockContent(byte[] mockData, MockOptions options) { _options = options; if (mockData == null) { _mockData = Encoding.UTF8.GetBytes("data"); } else { _mockData = mockData; } }
public void ExplicitHelpActivation() { var options = new MockOptions(); var writer = new StringWriter(); Result = base.Parser.ParseArguments( new string[] { "--help" }, options, writer); ResultShouldBeFalse(); string helpText = writer.ToString(); (helpText.Length > 0).Should().Be.True(); }
internal bool ConfirmSameCallsWereMade(MockOptions options = MockOptions.Default_SameCallsSameNumberOfTimesInAnyOrder) { var previous = _interceptor.PreviousRunLog.Calls; var current = _interceptor.ThisRunLog.Calls; MockOptions failedRules = MockOptions.None; failedRules |= EveryCallInFirstListExistsInSecond(MockOptions.AllExpectedCallsMustBeObserved, previous, current, sameNumber: options.HasFlag(MockOptions.ExpectedCallsMustBeObservedTheExactNumberOfTimes)); failedRules |= MockOptions.OnlyExpectedCallsAreAllowed & EveryCallInFirstListExistsInSecond(MockOptions.OnlyExpectedCallsAreAllowed, current, previous, sameNumber: options.HasFlag(MockOptions.ExpectedCallsMustBeObservedTheExactNumberOfTimes)); return((failedRules & options) == MockOptions.None); }
public void GetTestResults_InvalidFile_WarningAndEmptyResult() { IEnumerable <Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("GoogleTestSuiteName1.TestMethod_001", "GoogleTestSuiteName1.TestMethod_002"); MockOptions.Setup(o => o.DebugMode).Returns(true); var parser = new XmlTestResultParser(testCases, TestResources.XmlFileBroken, TestEnvironment, ""); List <Model.TestResult> results = parser.GetTestResults(); results.Count.Should().Be(0); MockLogger.Verify(l => l.LogWarning(It.IsAny <string>()), Times.Exactly(1)); }
public void GetTestResults_FileWithInvalidStatusAttribute_WarningAndEmptyResult() { IEnumerable <Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("GoogleTestSuiteName1.TestMethod_001", "GoogleTestSuiteName1.TestMethod_002"); MockOptions.Setup(o => o.OutputMode).Returns(OutputMode.Verbose); var parser = new XmlTestResultParser(testCases, "someexecutable", TestResources.XmlFileBroken_InvalidStatusAttibute, TestEnvironment.Logger); List <Model.TestResult> results = parser.GetTestResults(); results.Should().ContainSingle(); MockLogger.Verify(l => l.DebugWarning(It.IsAny <string>()), Times.Exactly(1)); }
public void Explicit_help_activation() { var options = new MockOptions(); var writer = new StringWriter(); var parser = new CommandLine.Parser(with => with.HelpWriter = writer); var result = parser.ParseArguments( new string[] { "--help" }, options); result.Should().BeFalse(); string helpText = writer.ToString(); (helpText.Length > 0).Should().BeTrue(); }
public void SplitTestcases_SameNumberOfTestsAsThreads_TestsAreDistributedEvenly() { IEnumerable <Model.TestCase> testCasesWithCommonSuite = CreateDummyTestCases("FooSuite.BarTest", "FooSuite.BazTest"); MockOptions.Setup(o => o.MaxNrOfThreads).Returns(2); ITestsSplitter splitter = new NumberBasedTestsSplitter(testCasesWithCommonSuite, TestEnvironment); List <List <Model.TestCase> > result = splitter.SplitTestcases(); Assert.AreEqual(2, result.Count); Assert.AreEqual(1, result[0].Count); Assert.AreEqual(1, result[1].Count); }
public void GetCommandLines_ShuffleTestsWithCustomSeed_IsAppendedCorrectly() { MockOptions.Setup(o => o.ShuffleTests).Returns(true); MockOptions.Setup(o => o.ShuffleTestsSeed).Returns(4711); IEnumerable <Model.TestCase> testCases = CreateDummyTestCases("Suite1.Test1", "Suite2.Test2"); string commandLine = new CommandLineGenerator(testCases, testCases, DummyExecutable.Length, "", "", TestEnvironment).GetCommandLines().First().CommandLine; string shuffleTestsOption = GoogleTestConstants.ShuffleTestsOption + GoogleTestConstants.ShuffleTestsSeedOption + "=4711"; Assert.AreEqual($"--gtest_output=\"xml:\"{DefaultArgs}{shuffleTestsOption}", commandLine); }
public virtual void RunTests_WorkingDir_IsSetCorrectly() { TestCase testCase = TestDataCreator.GetTestCases("WorkingDir.IsSolutionDirectory").First(); MockOptions.Setup(o => o.WorkingDir).Returns(SettingsWrapper.ExecutableDirPlaceholder); RunAndVerifySingleTest(testCase, VsTestOutcome.Failed); MockFrameworkHandle.Reset(); SetUpMockFrameworkHandle(); MockOptions.Setup(o => o.WorkingDir).Returns(SettingsWrapper.SolutionDirPlaceholder); RunAndVerifySingleTest(testCase, VsTestOutcome.Passed); }
public void ReportExitCodeTestCases_FailButNoOutput_WarningIsLogged() { MockOptions.Setup(o => o.UseNewTestExecutionFramework).Returns(false); _mockAggregator.Setup(a => a.ComputeAggregatedResults(It.IsAny <IEnumerable <ExecutableResult> >())).Returns( new List <ExecutableResult> { new ExecutableResult("Foo", 1) }); _reporter.ReportExitCodeTestCases(null, true); MockLogger.Verify(l => l.LogWarning(It.Is <string>(msg => msg.Contains("collected") && msg.Contains(SettingsWrapper.OptionUseNewTestExecutionFramework))), Times.Once); }
public void UseGenericListOfStringInterfaceReference() { MockOptions options = new MockOptions(); IList <string> values = ValueListAttribute.GetReference(options); values.Add("value0"); values.Add("value1"); values.Add("value2"); Assert.AreEqual("value0", options.Values[0]); Assert.AreEqual("value1", options.Values[1]); Assert.AreEqual("value2", options.Values[2]); }
public virtual void RunTests_WithSetupAndTeardownBatchesWhereSetupFails_LogsWarning() { MockOptions.Setup(o => o.BatchForTestSetup).Returns(TestResources.Results1Batch); MockOptions.Setup(o => o.BatchForTestTeardown).Returns(TestResources.Results0Batch); RunAndVerifyTests(TestResources.X64ExternallyLinkedTests, 2, 0, 0); MockLogger.Verify(l => l.LogWarning( It.Is <string>(s => s.Contains(PreparingTestRunner.TestSetup))), Times.AtLeastOnce()); MockLogger.Verify(l => l.LogWarning( It.Is <string>(s => s.Contains(PreparingTestRunner.TestTeardown))), Times.Never); }
public void TestOperatorViewStartStop() { const int TalkIdStart = 500; const int NumTalks = 3; Mock <IOptionsService> optionsService = new Mock <IOptionsService>(); optionsService.Setup(o => o.Options).Returns(MockOptions.Create()); Mock <ITalkTimerService> timerService = new Mock <ITalkTimerService>(); Mock <IAdaptiveTimerService> adaptiveTimerService = new Mock <IAdaptiveTimerService>(); ITalkScheduleService scheduleService = new MockTalksScheduleService(TalkIdStart, NumTalks); Mock <IBellService> bellService = new Mock <IBellService>(); Mock <ICommandLineService> commandLineService = new Mock <ICommandLineService>(); Mock <ILocalTimingDataStoreService> timingDataService = new Mock <ILocalTimingDataStoreService>(); Mock <ISnackbarService> snackbarService = new Mock <ISnackbarService>(); var vm = new OperatorPageViewModel( timerService.Object, scheduleService, adaptiveTimerService.Object, optionsService.Object, commandLineService.Object, bellService.Object, timingDataService.Object, snackbarService.Object); Assert.IsFalse(vm.IsRunning); Assert.IsFalse(vm.IsManualMode); for (int n = 0; n < NumTalks; ++n) { int talkId = TalkIdStart + n; Assert.IsTrue(vm.TalkId == talkId); var talk = scheduleService.GetTalkScheduleItem(talkId); Assert.IsNotNull(talk); Assert.AreEqual(vm.CurrentTimerValueString, TimeFormatter.FormatTimerDisplayString(talk.GetPlannedDurationSeconds())); vm.StartCommand.Execute(null); Assert.IsTrue(vm.IsRunning); Assert.IsTrue(vm.TalkId == TalkIdStart + n); vm.StopCommand.Execute(null); Assert.IsFalse(vm.IsRunning); Assert.IsTrue(vm.TalkId == (n == NumTalks - 1 ? 0 : TalkIdStart + n + 1)); } }
public void ReportExitCodeTestCases_EmptyInput_EmptyResult() { MockOptions.Setup(o => o.ExitCodeTestCase).Returns(""); _mockAggregator.Setup(a => a.ComputeAggregatedResults(It.IsAny <IEnumerable <ExecutableResult> >())).Returns( new List <ExecutableResult> { new ExecutableResult("Foo") }); _reporter.ReportExitCodeTestCases(null, false); MockFrameworkReporter .Verify(r => r.ReportTestResults(It.IsAny <IEnumerable <TestResult> >()), Times.Never); }
private void CheckForDiscoverySinkCalls(int expectedNrOfTests, string customRegex = null) { Mock <IDiscoveryContext> mockDiscoveryContext = new Mock <IDiscoveryContext>(); Mock <ITestCaseDiscoverySink> mockDiscoverySink = new Mock <ITestCaseDiscoverySink>(); MockOptions.Setup(o => o.TestDiscoveryRegex).Returns(() => customRegex); TestDiscoverer discoverer = new TestDiscoverer(TestEnvironment); Mock <IMessageLogger> MockVsLogger = new Mock <IMessageLogger>(); discoverer.DiscoverTests(X86StaticallyLinkedTests.Yield(), mockDiscoveryContext.Object, MockVsLogger.Object, mockDiscoverySink.Object); mockDiscoverySink.Verify(h => h.SendTestCase(It.IsAny <Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase>()), Times.Exactly(expectedNrOfTests)); }
public virtual void RunTests_WithSetupAndTeardownBatchesWhereSetupFails_LogsWarning() { MockOptions.Setup(o => o.BatchForTestSetup).Returns(TestResources.FailingBatch); MockOptions.Setup(o => o.BatchForTestTeardown).Returns(TestResources.SucceedingBatch); RunAndVerifyTests(TestResources.DllTests_ReleaseX86, 1, 1, 0); MockLogger.Verify(l => l.LogWarning( It.Is <string>(s => s.Contains(PreparingTestRunner.TestSetup))), Times.AtLeastOnce()); MockLogger.Verify(l => l.LogWarning( It.Is <string>(s => s.Contains(PreparingTestRunner.TestTeardown))), Times.Never); }
public void GetCommandLines_BreakOnFailureOption_IsAppendedCorrectly() { IEnumerable <Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("Suite1.Test1", "Suite2.Test2"); string commandLine = new CommandLineGenerator(testCases, TestDataCreator.DummyExecutable.Length, "", "", TestEnvironment.Options).GetCommandLines().First().CommandLine; string breakOnFailureOption = GoogleTestConstants.GetBreakOnFailureOption(false); commandLine.Should().Contain(breakOnFailureOption); MockOptions.Setup(o => o.BreakOnFailure).Returns(true); commandLine = new CommandLineGenerator(testCases, TestDataCreator.DummyExecutable.Length, "", "", TestEnvironment.Options).GetCommandLines().First().CommandLine; breakOnFailureOption = GoogleTestConstants.GetBreakOnFailureOption(true); commandLine.Should().Contain(breakOnFailureOption); }
public void GetCommandLines_OnlyExitCodeTestCase_DummyFilter() { var exitCodeTestName = "ExitCodeTest"; MockOptions.Setup(o => o.ExitCodeTestCase).Returns(exitCodeTestName); var exitCodeTestCase = ExitCodeTestsReporter.CreateExitCodeTestCase(MockOptions.Object, TestDataCreator.DummyExecutable); string commandLine = new CommandLineGenerator(new List <Model.TestCase> { exitCodeTestCase }, TestDataCreator.DummyExecutable.Length, "", "", TestEnvironment.Options).GetCommandLines().First().CommandLine; commandLine.Should().Contain($"{GoogleTestConstants.FilterOption}GTA_NOT_EXISTING_DUMMY_TEST_CASE"); }
public void GetCommandLines_CatchExceptionsOption_IsAppendedCorrectly() { IEnumerable <Model.TestCase> testCases = CreateDummyTestCases("Suite1.Test1", "Suite2.Test2"); string commandLine = new CommandLineGenerator(testCases, testCases, DummyExecutable.Length, "", "", TestEnvironment).GetCommandLines().First().CommandLine; string catchExceptionsOption = GoogleTestConstants.GetCatchExceptionsOption(true); Assert.IsTrue(commandLine.Contains(catchExceptionsOption), commandLine); MockOptions.Setup(o => o.CatchExceptions).Returns(false); commandLine = new CommandLineGenerator(testCases, testCases, DummyExecutable.Length, "", "", TestEnvironment).GetCommandLines().First().CommandLine; catchExceptionsOption = GoogleTestConstants.GetCatchExceptionsOption(false); Assert.IsTrue(commandLine.Contains(catchExceptionsOption), commandLine); }
private void RunExecutableAndCheckLogging(string executable, Action verify) { var mockDiscoveryContext = new Mock <IDiscoveryContext>(); var mockDiscoverySink = new Mock <ITestCaseDiscoverySink>(); var mockVsLogger = new Mock <IMessageLogger>(); MockOptions.Setup(o => o.TestDiscoveryRegex).Returns(() => ".*"); var discoverer = new TestDiscoverer(TestEnvironment.Logger, TestEnvironment.Options); discoverer.DiscoverTests(executable.Yield(), mockDiscoveryContext.Object, mockVsLogger.Object, mockDiscoverySink.Object); verify(); }
public virtual void GetTestsFromExecutable_RegexBeforeFromOptionsThreeEqualTraits_FindsTestWithTwoEqualTraits() { string testname = "Traits.WithEqualTraits"; MockOptions.Setup(o => o.TraitsRegexesBefore).Returns( new List <RegexTraitPair> { new RegexTraitPair(Regex.Escape(testname), "Author", "Foo"), new RegexTraitPair(Regex.Escape(testname), "Author", "Bar"), new RegexTraitPair(Regex.Escape(testname), "Author", "Baz") }); Trait[] traits = { new Trait("Author", "JOG"), new Trait("Author", "CSO") }; AssertFindsTestWithTraits(testname, traits); }
public void BadInputActivatesHelp() { var options = new MockOptions(); var writer = new StringWriter(); bool result = base.Parser.ParseArguments( new string[] { "math.xml", "-oresult.xml" }, options, writer); base.AssertParserFailure(result); string helpText = writer.ToString(); Assert.IsTrue(helpText.Length > 0); Console.Write(helpText); }
public void UseGenericListOfStringInterfaceReference() { var options = new MockOptions(); var values = ValueListAttribute.GetReference(options); values.Add("value0"); values.Add("value1"); values.Add("value2"); //Assert.AreEqual("value0", options.Values[0]); //Assert.AreEqual("value1", options.Values[1]); //Assert.AreEqual("value2", options.Values[2]); base.AssertArrayItemEqual(new string[] { "value0", "value1", "value2" }, options.Values); }
public void Bad_input_activates_help() { var options = new MockOptions(); var writer = new StringWriter(); var parser = new CommandLine.Parser(with => with.HelpWriter = writer); var result = parser.ParseArguments( new string[] { "math.xml", "-oresult.xml" }, options); result.Should().BeFalse(); string helpText = writer.ToString(); (helpText.Length > 0).Should().BeTrue(); Console.Write(helpText); }
private void CheckEffectOfDiscoveryParam() { GoogleTestDiscoverer discoverer = new GoogleTestDiscoverer(TestEnvironment.Logger, TestEnvironment.Options); var tests = discoverer.GetTestsFromExecutable(SampleTestToUse); tests.Should().NotBeEmpty(); MockOptions.Setup(o => o.AdditionalTestExecutionParam).Returns("-justfail"); discoverer = new GoogleTestDiscoverer(TestEnvironment.Logger, TestEnvironment.Options); tests = discoverer.GetTestsFromExecutable(SampleTestToUse); tests.Should().BeEmpty(); MockLogger.Verify(l => l.LogError(It.Is <string>(s => s.Contains("failed intentionally"))), Times.AtLeastOnce); }
public void BadInputActivatesHelp() { MockOptions options = new MockOptions(); TextWriter writer = new StringWriter(); bool success = Parser.ParseArguments( new string[] { "math.xml", "-oresult.xml" }, options, writer); Assert.IsFalse(success); string helpText = writer.ToString(); Assert.IsTrue(helpText.Length > 0); Console.Write(helpText); }
public void BadInputActivatesHelp() { var options = new MockOptions(); var writer = new StringWriter(); Result = base.Parser.ParseArguments( new string[] { "math.xml", "-oresult.xml" }, options, writer); ResultShouldBeFalse(); string helpText = writer.ToString(); (helpText.Length > 0).Should().Be.True(); Console.Write(helpText); }
public void Initialize() { var mockOptions = MockOptions <WolkConfiguration> .Create(_configuration); _handler = new GetAttachmentQueryHandler( _mockDateTime.Object, _mockFileService.Object, _mapper, _wolkDbContext, mockOptions); _mockDateTime .Setup(m => m.Now) .Returns(DateTimeOffset.Now); }
public MockContent(Exception customException, MockOptions options) : this((byte[])null, options) { _customException = customException; }
public MockContent(MockOptions options) : this((byte[])null, options) { }