Esempio n. 1
0
        public void UpdateTestDurations_SimpleTests_DurationsAreWrittenAndReadCorrectly()
        {
            string tempFile = Path.GetTempFileName();
            List <Model.TestResult> testResults = new List <Model.TestResult>
            {
                TestDataCreator.ToTestResult("TestSuite1.Test1", Model.TestOutcome.Passed, 3, tempFile),
                TestDataCreator.ToTestResult("TestSuite1.SkippedTest", Model.TestOutcome.Skipped, 1, tempFile)
            };

            var serializer = new TestDurationSerializer();

            serializer.UpdateTestDurations(testResults);

            string durationsFile = GetDurationsFile(serializer, tempFile);

            durationsFile.AsFileInfo().Should().Exist();

            IDictionary <Model.TestCase, int> durations = serializer.ReadTestDurations(testResults.Select(tr => tr.TestCase));

            durations.Count.Should().Be(1);
            durations.Should().ContainKey(testResults[0].TestCase);
            durations[testResults[0].TestCase].Should().Be(3);
            durations.Should().NotContainKey(testResults[1].TestCase);

            File.Delete(durationsFile);
        }
Esempio n. 2
0
        public void GetCommandLines_AllTests_ProducesCorrectArguments()
        {
            IEnumerable <Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("Suite1.Test1 param", "Suite2.Test2");
            string commandLine = new CommandLineGenerator(testCases, TestDataCreator.DummyExecutable.Length, "", "", TestEnvironment.Options).GetCommandLines().First().CommandLine;

            commandLine.Should().Be($"--gtest_output=\"xml:\"{DefaultArgs}");
        }
Esempio n. 3
0
        public void PeekTwiceOutgoingMessageTest()
        {
            var messagingOperations = Substitute.For <IMessagingOperations>();
            var pltDeviceOperations = Substitute.For <IDeviceOperations>();

            pltDeviceOperations.Get("1234").Returns(TestDataCreator.Device("1234", "1234", "12345", "123456", "1234567", 1));
            messagingOperations.Peek(1)
            .Returns(new OutgoingMessageToStoreWithState(new OutgoingMessageToStore(1, new byte[] { 48, 49, 50 }, 1, DateTime.UtcNow, "sender"), OutgoingState.Ok));

            var messagingService = new MessagingService(messagingOperations, pltDeviceOperations);

            var msg = messagingService.Peek("1234");

            Assert.IsNotNull(msg);
            Assert.AreEqual(OutgoingState.Ok, msg.State);
            Assert.AreEqual("1234", msg.Message.DeviceId);
            Assert.AreEqual("012", msg.Message.Payload);
            Assert.AreEqual("sender", msg.Message.SenderDeviceId);

            msg = messagingService.Peek("1234");

            Assert.IsNotNull(msg);
            Assert.AreEqual(OutgoingState.Ok, msg.State);
            Assert.AreEqual("1234", msg.Message.DeviceId);
            Assert.AreEqual("012", msg.Message.Payload);
            Assert.AreEqual("sender", msg.Message.SenderDeviceId);
        }
        public void ResolveIncomingNullAllTest()
        {
            var deviceOperations   = Substitute.For <IDeviceOperations>();
            var networkeOperations = Substitute.For <INetworkOperations>();
            var serviceOperations  = Substitute.For <IServiceOperations>();
            var companyOperations  = Substitute.For <ICompanyOperations>();
            var telemetryDataSinkMetadataRegistry = Substitute.For <ITelemetryDataSinkMetadataRegistry>();

            var deviceId = Identity.Next();

            var serviceId = Identity.Next();
            var networkId = Identity.Next();
            var companyId = Identity.Next();

            deviceOperations.Get(deviceId).Returns(TestDataCreator.Device(deviceId, null, networkId, serviceId, companyId, 0));
            serviceOperations.Get(serviceId)
            .Returns(TestDataCreator.Service(serviceId, null,
                                             companyId, new TelemetryDataSinkSettings {
                Incoming = null
            }));
            companyOperations.Get(companyId)
            .Returns(TestDataCreator.Company(companyId, new TelemetryDataSinkSettings {
                Incoming = null
            }));
            networkeOperations.Get(networkId)
            .Returns(TestDataCreator.Network(networkId, "key", null, serviceId, companyId, new TelemetryDataSinkSettings {
                Incoming = new List <TelemetryDataSinkParameters>()
            }));

            var telemetryDataSinkResolver = new TelemetryDataSinkResolver(deviceOperations, networkeOperations, serviceOperations, companyOperations,
                                                                          telemetryDataSinkMetadataRegistry, new DynamicConnectionStringResolver(null));

            Assert.AreEqual(0, telemetryDataSinkResolver.ResolveIncoming(deviceId).Count());
        }
Esempio n. 5
0
        public void GetTestResults_OutputWithSkippedTestAsLastTest_AllResultsAreFound()
        {
            var cases = new List <TestCase>
            {
                TestDataCreator.ToTestCase("Test.Succeed", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
                TestDataCreator.ToTestCase("Test.Skip", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
                TestDataCreator.ToTestCase("Test.Fail", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
            };

            var parser = new StreamingStandardOutputTestResultParser(cases, TestEnvironment.Logger, MockFrameworkReporter.Object);

            ConsoleOutputWithSkippedTestAsLastTest.ToList().ForEach(parser.ReportLine);
            parser.Flush();
            var results = parser.TestResults;

            results.Should().HaveCount(3);

            var result = results[0];

            result.TestCase.FullyQualifiedName.Should().Be("Test.Succeed");
            XmlTestResultParserTests.AssertTestResultIsPassed(result);

            result = results[1];
            result.TestCase.FullyQualifiedName.Should().Be("Test.Fail");
            XmlTestResultParserTests.AssertTestResultIsFailure(result);

            result = results[2];
            result.TestCase.FullyQualifiedName.Should().Be("Test.Skip");
            XmlTestResultParserTests.AssertTestResultIsSkipped(result);
        }
Esempio n. 6
0
        private void DoRunCancelingTests(bool killProcesses, int lower)
        {
            MockOptions.Setup(o => o.KillProcessesOnCancel).Returns(killProcesses);
            List <Model.TestCase> testCasesToRun = TestDataCreator.GetTestCases("Crashing.LongRunning", "LongRunningTests.Test2");

            testCasesToRun.Should().HaveCount(2);

            var stopwatch = new Stopwatch();
            var executor  = new TestExecutor(TestEnvironment.Logger, TestEnvironment.Options, MockDebuggerAttacher.Object);

            var canceller = new Thread(() =>
            {
                Thread.Sleep(WaitBeforeCancelInMs);
                executor.Cancel();
            });

            canceller.Start();

            stopwatch.Start();
            executor.RunTests(testCasesToRun.Select(tc => tc.ToVsTestCase()), MockRunContext.Object, MockFrameworkHandle.Object);
            stopwatch.Stop();

            canceller.Join();
            stopwatch.ElapsedMilliseconds.Should().BeInRange(lower, lower + OverheadInMs);
        }
Esempio n. 7
0
        public void TryLoginSameDeviceTwiceTest()
        {
            var connection          = Substitute.For <IPersistentConnection>();
            var connection2         = Substitute.For <IPersistentConnection>();
            var deviceAuthenticator = Substitute.For <IDeviceAuthenticator>();
            var deviceOperations    = Substitute.For <IDeviceOperations>();

            var connectionRegistry = new ConnectionRegistry(new PusherRegistry(new DateTimeProvider()), null);

            connection.ConnectionId.Returns(Guid.NewGuid());
            connection2.ConnectionId.Returns(Guid.NewGuid());

            deviceAuthenticator.Authenticate(null).ReturnsForAnyArgs(true);
            var deviceId = Identity.Next();

            deviceOperations.Get(null).ReturnsForAnyArgs(TestDataCreator.Device(deviceId, "1234", "2345", "3456", "4567", 1));

            connectionRegistry.RegisterInitiatedConnection(connection);
            connectionRegistry.RegisterInitiatedConnection(connection2);

            var commandExecutor = new CommandExecutor(null, connectionRegistry, null, deviceAuthenticator, deviceOperations, null, null);

            commandExecutor.Execute(connection, new LoginCommand(deviceId + " " + Identity.Next()));
            commandExecutor.Execute(connection2, new LoginCommand(deviceId + " " + Identity.Next()));

            connection.Received().Reply("login ack");
            connection2.Received().Reply("login badcommand");
            Assert.AreEqual(ConnectionState.LoggedIn, connection.ConnectionState);
            Assert.AreEqual(1, connection.NumericDeviceId);
        }
        public void GetCommandLines_HugeNumberOfSuitesToBeExecutedFully_WontBreakCommandLineCreation()
        {
            // we create 400 testsuites, with 380 of them holding 2 test-cases, 20 of them ("MyTestSuite..."[0-19]) holding three test-cases (named Test,Test2,Test3)
            var          range         = Enumerable.Range(0, 400);
            const string baseSuiteName = "MyTestSuiteWithSomeWhatLongNameIsStillHandledCorrectly";
            var          allTests      = range.Select(idx => baseSuiteName + idx + ".Test")
                                         .Concat(range.Select(idx => baseSuiteName + idx + ".Test2"))
                                         .Concat(range.Take(20).Select(idx => baseSuiteName + idx + ".Test3"))
                                         .ToList();

            // 305 of the 380 2-test-suites will be executed fully (i.e. all test-cases are executed), only one 3-test-suite is executed fully (which holds also the only Test3-case to be execute)
            var testsToExecute = allTests.Where((testcase, idx) => idx < 700 || (idx + 5) % 20 == 0).ToList();

            IEnumerable <Model.TestCase> testCases = TestDataCreator.CreateDummyTestCasesFull(testsToExecute.ToArray(), allTests.ToArray());

            List <CommandLineGenerator.Args> commands =
                new CommandLineGenerator(testCases, TestDataCreator.DummyExecutable.Length, "", "", TestEnvironment.Options).GetCommandLines().ToList();

            int longestSuiteName  = baseSuiteName.Length + 6; // 6 = 3 for suiteIndex + 3 for suite-filter-delimiter
            int minimumLineLength = CommandLineGenerator.MaxCommandLength - longestSuiteName;

            CommandLineGenerator.MaxCommandLength.Should().Be(8191, "if the maximum command line length changes, we may need to adapt the following expectations");
            commands.Should().HaveCount(4, "based on given test-cases and maximum command line length we expect 4 command-lines to be created");
            commands.First().CommandLine.Should().NotMatchRegex(baseSuiteName + @"(\d|1[^5])\.", "none fo the 3-test-suites (0-19) expect suite 15 must be part of a command line");
            commands.First().TestCases.Count(testCase => testCase.DisplayName.EndsWith("Test3")).Should().Be(1, "the single fully executed 3-test-suite has to be part of the first command line");
            commands.Skip(1).Select(cmd => cmd.TestCases.Count(testCase => testCase.DisplayName.EndsWith("Test3"))).Sum().Should().Be(0, "only a single Test3 must be executed on the first command line");
            commands.Take(3).Select(cmd => cmd.CommandLine.Length).Should().OnlyContain(length => length >= minimumLineLength, "all command lines expect the last need to have a minimum length, so no superfluous command-lines are executed");
            commands.Select(cmd => cmd.TestCases.Count).Sum().Should().Be(testsToExecute.Count(), "the number of test to be executed must be identical to those on the command lines");
        }
Esempio n. 9
0
        public void HeartbeatTest()
        {
            var connection          = Substitute.For <IPersistentConnection>();
            var deviceAuthenticator = Substitute.For <IDeviceAuthenticator>();
            var deviceOperations    = Substitute.For <IDeviceOperations>();

            var connectionRegistry = new ConnectionRegistry(new PusherRegistry(new DateTimeProvider()), null);

            connection.ConnectionId.Returns(Guid.NewGuid());
            deviceAuthenticator.Authenticate(null).ReturnsForAnyArgs(true);
            deviceOperations.Get(null).ReturnsForAnyArgs(TestDataCreator.Device("1234", "1234", "2345", "3456", "4567", 1));

            connectionRegistry.RegisterInitiatedConnection(connection);

            var commandExecutor = new CommandExecutor(null, connectionRegistry, null, deviceAuthenticator, deviceOperations, null, null);

            commandExecutor.Execute(connection, new LoginCommand(Identity.Next() + " " + Identity.Next()));

            commandExecutor.Execute(connection, new SubscribeCommand("receiveandforget"));

            commandExecutor.Execute(connection, new HeartbeatCommand());

            Assert.AreEqual(ConnectionState.LoggedIn | ConnectionState.Subscribed, connection.ConnectionState);
            connection.Received().Heartbeat();
        }
Esempio n. 10
0
        public void CommitNotLoggedInTest()
        {
            var connection            = Substitute.For <IPersistentConnection>();
            var deviceAuthenticator   = Substitute.For <IDeviceAuthenticator>();
            var deviceOperations      = Substitute.For <IDeviceOperations>();
            var dateTimeProvider      = Substitute.For <IDateTimeProvider>();
            var outgoingMessageReader = Substitute.For <IMessagingOperations>();

            dateTimeProvider.UtcNow.Returns(DateTime.UtcNow);
            var pusherRegistry     = new PusherRegistry(dateTimeProvider);
            var connectionRegistry = new ConnectionRegistry(pusherRegistry, null);

            var deviceId = Identity.Next();

            connection.ConnectionId.Returns(Guid.NewGuid());
            deviceAuthenticator.Authenticate(null).ReturnsForAnyArgs(true);
            deviceOperations.Get(null).ReturnsForAnyArgs(TestDataCreator.Device(deviceId, "1234", "2345", "3456", "4567", 1));

            connectionRegistry.RegisterInitiatedConnection(connection);

            var commandExecutor = new CommandExecutor(pusherRegistry, connectionRegistry, outgoingMessageReader, deviceAuthenticator, deviceOperations, null, null);

            dateTimeProvider.UtcNow.Returns(DateTime.UtcNow);
            pusherRegistry.SetAsCommitNeededConnections(new[] { connection });

            outgoingMessageReader.Commit((long)0).ReturnsForAnyArgs(OutgoingState.Ok);

            connection.ClearReceivedCalls();

            commandExecutor.Execute(connection, new CommitCommand());
            connection.DidNotReceive().Heartbeat();
        }
Esempio n. 11
0
        public void SettingOperationsTest()
        {
            var settingOperations = Substitute.For <IPersistedSettingOperations>();

            var cachingSettingOperations = new SettingOperations(settingOperations);

            cachingSettingOperations.Remove("cat.conf");

            var id = new SettingId("cat", "conf");

            settingOperations.Get(id).Returns(TestDataCreator.Setting(id, "2"));

            var setting = cachingSettingOperations.Get(id);

            Assert.AreEqual("2", setting.Value);

            settingOperations.Received().Get(id);

            settingOperations.ClearReceivedCalls();

            var setting2 = cachingSettingOperations.Get(id);

            Assert.AreEqual("2", setting2.Value);

            settingOperations.DidNotReceive().Get(id);
        }
        public void UpdateTestDurations_SameTestsInDifferentExecutables_DurationsAreWrittenAndReadCorrectly()
        {
            string tempFile  = Path.GetTempFileName();
            string tempFile2 = Path.GetTempFileName();
            List <Model.TestResult> testResults = new List <Model.TestResult>
            {
                TestDataCreator.ToTestResult("TestSuite1.Test1", Model.TestOutcome.Passed, 3, tempFile),
                TestDataCreator.ToTestResult("TestSuite1.Test1", Model.TestOutcome.Failed, 4, tempFile2)
            };

            var serializer = new TestDurationSerializer();

            serializer.UpdateTestDurations(testResults);

            string durationsFile1 = GetDurationsFile(serializer, tempFile);

            durationsFile1.AsFileInfo().Should().Exist();
            string durationsFile2 = GetDurationsFile(serializer, tempFile2);

            durationsFile2.AsFileInfo().Should().Exist();

            IDictionary <Model.TestCase, int> durations = serializer.ReadTestDurations(testResults.Select(tr => tr.TestCase));

            durations.Should().HaveCount(2);
            durations.Should().ContainKey(testResults[0].TestCase);
            durations[testResults[0].TestCase].Should().Be(3);
            durations.Should().ContainKey(testResults[1].TestCase);
            durations[testResults[1].TestCase].Should().Be(4);

            File.Delete(durationsFile1);
            File.Delete(durationsFile2);
        }
Esempio n. 13
0
        public void TelemetryDataLoginRequiredTest()
        {
            var connection                = Substitute.For <IPersistentConnection>();
            var deviceAuthenticator       = Substitute.For <IDeviceAuthenticator>();
            var deviceOperations          = Substitute.For <IDeviceOperations>();
            var dateTimeProvider          = Substitute.For <IDateTimeProvider>();
            var telemetryDataSinkResolver = Substitute.For <ITelemetryDataSinkResolver>();

            dateTimeProvider.UtcNow.Returns(DateTime.UtcNow);
            var pusherRegistry     = new PusherRegistry(dateTimeProvider);
            var connectionRegistry = new ConnectionRegistry(pusherRegistry, null);

            var deviceId = Identity.Next();

            connection.ConnectionId.Returns(Guid.NewGuid());
            deviceAuthenticator.Authenticate(null).ReturnsForAnyArgs(true);
            deviceOperations.Get(null).ReturnsForAnyArgs(TestDataCreator.Device(deviceId, "1234", "2345", "3456", "4567", 1));

            connectionRegistry.RegisterInitiatedConnection(connection);

            telemetryDataSinkResolver.ResolveIncoming(null).ReturnsForAnyArgs(new List <ITelemetryDataSink>());
            var telemetryDataService = new DirectTelemetryDataService(telemetryDataSinkResolver);

            var commandExecutor = new CommandExecutor(pusherRegistry, connectionRegistry, null, deviceAuthenticator, deviceOperations, null, telemetryDataService);

            dateTimeProvider.UtcNow.Returns(DateTime.UtcNow);

            commandExecutor.Execute(connection, new TelemetryDataCommand("{\"Temperature\": 24, \"Time\":" + DateTime.UtcNow.Ticks + "}"));
            connection.Received(1).Reply("telemetrydata unauthorized");
        }
Esempio n. 14
0
        public void SendToErrorTest()
        {
            var connection          = Substitute.For <IPersistentConnection>();
            var deviceAuthenticator = Substitute.For <IDeviceAuthenticator>();
            var deviceOperations    = Substitute.For <IDeviceOperations>();
            var dateTimeProvider    = Substitute.For <IDateTimeProvider>();

            dateTimeProvider.UtcNow.Returns(DateTime.UtcNow);
            var pusherRegistry     = new PusherRegistry(dateTimeProvider);
            var connectionRegistry = new ConnectionRegistry(pusherRegistry, null);

            var deviceId = Identity.Next();

            connection.ConnectionId.Returns(Guid.NewGuid());
            deviceAuthenticator.Authenticate(null).ReturnsForAnyArgs(true);
            deviceOperations.Get(null).ReturnsForAnyArgs(TestDataCreator.Device(deviceId, "1234", "2345", "3456", "4567", 1));

            connectionRegistry.RegisterInitiatedConnection(connection);

            var commandExecutor = new CommandExecutor(pusherRegistry, connectionRegistry, null, deviceAuthenticator, deviceOperations, null, null);

            commandExecutor.Execute(connection, new LoginCommand(deviceId + " " + Identity.Next()));

            dateTimeProvider.UtcNow.Returns(DateTime.UtcNow);

            commandExecutor.Execute(connection, new SendToCommand("{\"Temperature\": 24, \"Time\":" + DateTime.UtcNow.Ticks + "}"));
            connection.Received(1).Reply("sendto error");
        }
Esempio n. 15
0
        public void ParentNetworkAuthOkTest()
        {
            var deviceOperations  = Substitute.For <IDeviceOperations>();
            var networkOperations = Substitute.For <INetworkOperations>();
            var serviceOperations = Substitute.For <IServiceOperations>();

            var deviceId  = Identity.Next();
            var deviceKey = Crypto.GenerateSafeRandomToken();

            var networkId  = Identity.Next();
            var networkKey = Crypto.GenerateSafeRandomToken();

            var parentNetworkId  = Identity.Next();
            var parentNetworkKey = Crypto.GenerateSafeRandomToken();

            var serviceId = Identity.Next();
            var apiKey    = Crypto.GenerateSafeRandomToken();

            deviceOperations.Get(deviceId).Returns(TestDataCreator.Device(deviceId, deviceKey, networkId, serviceId, null, 0));
            networkOperations.Get(networkId).Returns(TestDataCreator.Network(networkId, networkKey, parentNetworkId, serviceId, null, null));
            networkOperations.Get(parentNetworkId).Returns(TestDataCreator.Network(parentNetworkId, parentNetworkKey, null, serviceId, null, null));
            serviceOperations.Get(serviceId).Returns(TestDataCreator.Service(serviceId, apiKey, null, null));

            var deviceAuthenticator = new DeviceAuthenticator(deviceOperations, networkOperations, serviceOperations);

            Assert.IsTrue(deviceAuthenticator.Authenticate(new AuthenticationParameters(deviceId, parentNetworkKey)));
        }
Esempio n. 16
0
        public void GetTestResults_OutputWithSkippedTestAsLastTest_AllResultsAreFound()
        {
            var cases = new List <TestCase>
            {
                TestDataCreator.ToTestCase("Test.Succeed", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
                TestDataCreator.ToTestCase("Test.Skip", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
                TestDataCreator.ToTestCase("Test.Fail", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
            };

            var results = new StandardOutputTestResultParser(cases, ConsoleOutputWithSkippedTestAsLastTest, TestEnvironment.Logger).GetTestResults();

            results.Should().HaveCount(3);

            var result = results[0];

            result.TestCase.FullyQualifiedName.Should().Be("Test.Succeed");
            XmlTestResultParserTests.AssertTestResultIsPassed(result);

            result = results[1];
            result.TestCase.FullyQualifiedName.Should().Be("Test.Fail");
            XmlTestResultParserTests.AssertTestResultIsFailure(result);

            result = results[2];
            result.TestCase.FullyQualifiedName.Should().Be("Test.Skip");
            XmlTestResultParserTests.AssertTestResultIsSkipped(result);
        }
Esempio n. 17
0
        public ActionResult <IEnumerable <string> > Get()
        {
            var testData = new TestDataCreator();

            testData.Fill();

            return(new string[] { "Great" });
        }
Esempio n. 18
0
        public void GetCommandLines_ShuffleTestsWithDefaultSeed_IsAppendedCorrectly()
        {
            MockOptions.Setup(o => o.ShuffleTests).Returns(true);

            IEnumerable <Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("Suite1.Test1", "Suite2.Test2");
            string commandLine = new CommandLineGenerator(testCases, TestDataCreator.DummyExecutable.Length, "", "", TestEnvironment.Options).GetCommandLines().First().CommandLine;

            commandLine.Should().Be($"--gtest_output=\"xml:\"{DefaultArgs}{GoogleTestConstants.ShuffleTestsOption}");
        }
        public void GetTestResults_Sample1_UnexpectedTestOutcome_LogsErrorAndThrows()
        {
            IEnumerable <Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("GoogleTestSuiteName1.TestMethod_007");

            var parser = new XmlTestResultParser(testCases, "someexecutable", TestResources.XmlFile1, TestEnvironment.Logger);

            parser.Invoking(p => p.GetTestResults()).Should().NotThrow <Exception>();
            MockLogger.Verify(l => l.LogError(It.Is <string>(s => s.Contains("Foo"))), Times.Exactly(1));
        }
        public void GetTestResults_OutputWithSkippedTestAsLastTest_AllResultsAreFound()
        {
            string[] consoleOutput = @"[==========] Running 3 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 3 tests from Test
[ RUN      ] Test.Succeed
[       OK ] Test.Succeed (0 ms)
[ RUN      ] Test.Fail
C:\...\test.cpp(14): error: Value of: false
  Actual: false
Expected: true
[  FAILED  ] Test.Fail (0 ms)
[ RUN      ] Test.Skip
[  SKIPPED ] Test.Skip (1 ms)
[----------] 3 tests from Test (3 ms total)

[----------] Global test environment tear-down
[==========] 3 tests from 1 test suite ran. (6 ms total)
[  PASSED  ] 1 test.
[  SKIPPED ] 1 test, listed below:
[  SKIPPED ] Test.Skip
[  FAILED  ] 1 test, listed below:
[  FAILED  ] Test.Fail

 1 FAILED TEST
".Split('\n');
            var      cases         = new List <TestCase>
            {
                TestDataCreator.ToTestCase("Test.Succeed", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
                TestDataCreator.ToTestCase("Test.Skip", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
                TestDataCreator.ToTestCase("Test.Fail", TestDataCreator.DummyExecutable, @"c:\somepath\source.cpp"),
            };

            var parser = new StreamingStandardOutputTestResultParser(cases, TestEnvironment.Logger, MockFrameworkReporter.Object);

            consoleOutput.ToList().ForEach(parser.ReportLine);
            parser.Flush();
            var results = parser.TestResults;

            results.Should().HaveCount(3);

            var result = results[0];

            result.TestCase.FullyQualifiedName.Should().Be("Test.Succeed");
            XmlTestResultParserTests.AssertTestResultIsPassed(result);

            result = results[1];
            result.TestCase.FullyQualifiedName.Should().Be("Test.Fail");
            XmlTestResultParserTests.AssertTestResultIsFailure(result);

            result = results[2];
            result.TestCase.FullyQualifiedName.Should().Be("Test.Skip");
            XmlTestResultParserTests.AssertTestResultIsSkipped(result);

            CheckStandardOutputResultParser(cases, consoleOutput, results, parser.CrashedTestCase);
        }
        public void ResolveIncomingCompanyTest()
        {
            var deviceOperations   = Substitute.For <IDeviceOperations>();
            var networkeOperations = Substitute.For <INetworkOperations>();
            var serviceOperations  = Substitute.For <IServiceOperations>();
            var companyOperations  = Substitute.For <ICompanyOperations>();
            var telemetryDataSinkMetadataRegistry = Substitute.For <ITelemetryDataSinkMetadataRegistry>();

            var deviceId = Identity.Next();

            var serviceId = Identity.Next();
            var networkId = Identity.Next();
            var companyId = Identity.Next();

            telemetryDataSinkMetadataRegistry.Incoming.Returns(new List <TelemetryDataSinkMetadata>
            {
                new TelemetryDataSinkMetadata("azureData", "data", typeof(IncomingStubs.CurrentDataStub),
                                              new[] { "ConnectionString", "Table" }, new Dictionary <string, string>())
            });

            deviceOperations.Get(deviceId).Returns(TestDataCreator.Device(deviceId, null, networkId, serviceId, companyId, 0));
            serviceOperations.Get(serviceId)
            .Returns(TestDataCreator.Service(serviceId, null,
                                             companyId, new TelemetryDataSinkSettings {
                Incoming = new List <TelemetryDataSinkParameters>()
            }));

            companyOperations.Get(companyId)
            .Returns(TestDataCreator.Company(companyId, new TelemetryDataSinkSettings
            {
                Incoming =
                    new List <TelemetryDataSinkParameters>
                {
                    new TelemetryDataSinkParameters()
                    {
                        SinkName   = "azureData",
                        Parameters =
                            new Dictionary <string, string>()
                        {
                            { "ConnectionString", "that" },
                            { "Table", "t" }
                        }
                    }
                }
            }));
            networkeOperations.Get(networkId)
            .Returns(TestDataCreator.Network(networkId, "key", null, serviceId, companyId, new TelemetryDataSinkSettings {
                Incoming = new List <TelemetryDataSinkParameters>()
            }));

            var telemetryDataSinkResolver = new TelemetryDataSinkResolver(deviceOperations, networkeOperations, serviceOperations, companyOperations,
                                                                          telemetryDataSinkMetadataRegistry, new DynamicConnectionStringResolver(null));

            Assert.AreEqual(1, telemetryDataSinkResolver.ResolveIncoming(deviceId).Count());
            Assert.IsInstanceOfType(telemetryDataSinkResolver.ResolveIncoming(deviceId).First(), typeof(IncomingStubs.CurrentDataStub));
        }
Esempio n. 22
0
        public void OneTimeSetUp()
        {
            _logger      = new Logger();
            _dataCreator = new TestDataCreator();
            var lockDb = new DistributedLockDb(_logger);
            var docDb  = new DocumentDb(_logger);

            lockDb.InitializeDatabase();
            docDb.InitializeDatabase();
        }
Esempio n. 23
0
        public void GetCommandLines_TestsWithCommonSuite_AreCombinedViaSuite()
        {
            IEnumerable <Model.TestCase> testCasesWithCommonSuite = TestDataCreator.CreateDummyTestCases("FooSuite.BarTest", "FooSuite.BazTest");
            IEnumerable <Model.TestCase> allTestCases             = testCasesWithCommonSuite.Union(TestDataCreator.CreateDummyTestCases("BarSuite.FooTest"));

            string commandLine = new CommandLineGenerator(allTestCases, testCasesWithCommonSuite, TestDataCreator.DummyExecutable.Length, "", "", TestEnvironment)
                                 .GetCommandLines().First().CommandLine;

            commandLine.Should().Be($"--gtest_output=\"xml:\"{DefaultArgs} --gtest_filter=FooSuite.*:");
        }
Esempio n. 24
0
        public void Filter_ExpressionAcceptsAnything_NoFiltering()
        {
            _mockFilterExpression.Setup(e => e.MatchTestCase(It.IsAny <TestCase>(), It.IsAny <Func <string, object> >())).Returns(true);
            IEnumerable <TestCase> testCases = TestDataCreator.CreateDummyTestCases("Foo.Bar", "Foo.Baz").Select(DataConversionExtensions.ToVsTestCase);

            TestCaseFilter         filter            = new TestCaseFilter(MockRunContext.Object, _traitNames, TestEnvironment.Logger);
            IEnumerable <TestCase> filteredTestCases = filter.Filter(testCases).ToList();

            AssertAreEqual(testCases, filteredTestCases);
        }
Esempio n. 25
0
        public void Filter_ExpressionMatchesNothing_EmptyResult()
        {
            _mockFilterExpression.Setup(e => e.MatchTestCase(It.IsAny <TestCase>(), It.IsAny <Func <string, object> >())).Returns(false);
            IEnumerable <TestCase> testCases = TestDataCreator.CreateDummyTestCases("Foo.Bar", "Foo.Baz").Select(tc => tc.ToVsTestCase());

            TestCaseFilter         filter            = new TestCaseFilter(MockRunContext.Object, _traitNames, TestEnvironment.Logger);
            IEnumerable <TestCase> filteredTestCases = filter.Filter(testCases).ToList();

            AssertAreEqual(new List <TestCase>(), filteredTestCases);
        }
        public void GetTestResults_Sample1_FindsPassedParameterizedResult()
        {
            IEnumerable <Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("ParameterizedTestsTest1/AllEnabledTest.TestInstance/7");

            var parser = new XmlTestResultParser(testCases, "someexecutable", TestResources.XmlFile1, TestEnvironment.Logger);
            List <Model.TestResult> results = parser.GetTestResults();

            results.Should().ContainSingle();
            AssertTestResultIsPassed(results[0]);
        }
        public void GetTestResults_Sample2_FindsPassedResult()
        {
            IEnumerable <Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("FooTest.DoesXyz");

            var parser = new XmlTestResultParser(testCases, "someexecutable", TestResources.XmlFile2, TestEnvironment.Logger);
            List <Model.TestResult> results = parser.GetTestResults();

            results.Should().ContainSingle();
            AssertTestResultIsPassed(results[0]);
        }
        public void GetTestResults_Sample1_FindsPassedParameterizedResult()
        {
            IEnumerable <Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("ParameterizedTestsTest1/AllEnabledTest.TestInstance/7  # GetParam() = (false, 200, 0)");

            var parser = new XmlTestResultParser(testCases, TestResources.XmlFile1, TestEnvironment, "");
            List <Model.TestResult> results = parser.GetTestResults();

            results.Count.Should().Be(1);
            AssertTestResultIsPassed(results[0]);
        }
Esempio n. 29
0
        public void GetCommandLines_RepetitionsOption_IsAppendedCorrectly()
        {
            MockOptions.Setup(o => o.NrOfTestRepetitions).Returns(4711);

            IEnumerable <Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("Suite1.Test1", "Suite2.Test2");
            string commandLine = new CommandLineGenerator(testCases, TestDataCreator.DummyExecutable.Length, "", "", TestEnvironment.Options).GetCommandLines().First().CommandLine;

            string repetitionsOption = GoogleTestConstants.NrOfRepetitionsOption + "=4711";

            commandLine.Should().Be($"--gtest_output=\"xml:\"{DefaultArgs}{repetitionsOption}");
        }
Esempio n. 30
0
        public void GetCommandLines_TestsWithCommonSuite_AreCombinedViaSuite()
        {
            string[] testCaseNamesWithCommonSuite = { "FooSuite.BarTest", "FooSuite.BazTest" };
            string[] allTestCaseNames             = testCaseNamesWithCommonSuite.Union("BarSuite.FooTest".Yield()).ToArray();
            IEnumerable <Model.TestCase> testCasesWithCommonSuite = TestDataCreator.CreateDummyTestCasesFull(testCaseNamesWithCommonSuite, allTestCaseNames);

            string commandLine = new CommandLineGenerator(testCasesWithCommonSuite, TestDataCreator.DummyExecutable.Length, "", "", TestEnvironment.Options)
                                 .GetCommandLines().First().CommandLine;

            commandLine.Should().Be($"--gtest_output=\"xml:\"{DefaultArgs} --gtest_filter=FooSuite.*:");
        }