public void CreateTestRunWithFilename()
        {
            // Given
            TestApiClient apiClient   = new TestApiClient(_ => "{ \"id\": 1234 }");
            LoggerQueue   loggerQueue = new LoggerQueue(apiClient, "987", "foo", "bar")
            {
                Source = "Fizz.Buzz"
            };

            // When
            int id = loggerQueue.CreateTestRun(CancellationToken.None).Result;

            // Then
            id.ShouldBe(1234);
            apiClient.Messages.ShouldBe(new[]
            {
                new ClientMessage(
                    HttpMethod.Post,
                    null,
                    "5.0-preview.2",
                    $@"{{
                        ""name"": ""Fizz.Buzz (OS: {System.Runtime.InteropServices.RuntimeInformation.OSDescription}, Job: bar, Agent: foo)"",
                        ""build"": {{""id"":""987""}},
                        ""startedDate"": ""{loggerQueue.StartedDate.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ")}"",
                        ""isAutomated"": true
                    }}")
            });
        }
        public void GroupTestResults()
        {
            // Given
            TestApiClient apiClient   = new TestApiClient();
            LoggerQueue   loggerQueue = new LoggerQueue(apiClient, "987", "foo", "bar")
            {
                Source = "Fizz.Buzz"
            };

            ITestResult[] testResults = new[]
            {
                new TestTestResult
                {
                    FullyQualifiedName = "Fizz.Buzz.FooFixture.BarMethod"
                },
                new TestTestResult
                {
                    FullyQualifiedName = "Fizz.Buzz.FooFixture.BazMethod"
                },
                new TestTestResult
                {
                    FullyQualifiedName = "Fizz.Buzz.FutzFixture.BooMethod(\"x.y\")"
                },
                new TestTestResult
                {
                    FullyQualifiedName = "Fizz.Buzz.FutzFixture.NestedFixture.BlitzMethod"
                }
            };

            // When
            IEnumerable <IGrouping <string, ITestResult> > testResultsByParent = loggerQueue.GroupTestResultsByParent(testResults);

            // Then
            testResultsByParent.Select(x => x.Key).ShouldBe(
                new[]
            {
                "FooFixture",
                "FutzFixture",
                "FutzFixture.NestedFixture"
            },
                true);
        }
        public void CreateParents()
        {
            // Given
            TestApiClient apiClient = new TestApiClient(_ =>
                                                        @"{
                    ""count"": 2,
                    ""value"": [
                        {
                            ""id"": 100
                        },
                        {
                            ""id"": 101
                        }
                    ]
                }");
            LoggerQueue loggerQueue = new LoggerQueue(apiClient, "987", "foo", "bar")
            {
                Source          = "Fizz.Buzz",
                TestRunEndpoint = "/ep"
            };

            loggerQueue.Parents.Add("FitzFixture", new TestResultParent(123));
            ITestResult[] testResults = new[]
            {
                new TestTestResult
                {
                    FullyQualifiedName = "Fizz.Buzz.FooFixture.BarMethod"
                },
                new TestTestResult
                {
                    FullyQualifiedName = "Fizz.Buzz.FitzFixture.BazMethod"
                },
                new TestTestResult
                {
                    FullyQualifiedName = "Fizz.Buzz.FutzFixture.NestedFixture.BooMethod(\"x.y\")"
                }
            };
            IEnumerable <IGrouping <string, ITestResult> > testResultsByParent = loggerQueue.GroupTestResultsByParent(testResults);

            // When
            loggerQueue.CreateParents(testResultsByParent, CancellationToken.None).Wait();

            // Then
            apiClient.Messages.ShouldBe(new[]
            {
                new ClientMessage(
                    HttpMethod.Post,
                    "/ep",
                    "5.0-preview.5",
                    $@"[
                        {{
                            ""testCaseTitle"": ""FooFixture"",
                            ""automatedTestName"": ""FooFixture"",
                            ""resultGroupType"": ""generic"",
                            ""outcome"": ""Passed"",
                            ""state"": ""InProgress"",
                            ""startedDate"": ""{loggerQueue.Parents["FooFixture"].StartedDate.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ")}"",
                            ""automatedTestType"": ""UnitTest"",
                            ""automatedTestTypeId"": ""13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b"",
                            ""automatedTestStorage"": ""Fizz.Buzz""
                        }},
                        {{
                            ""testCaseTitle"": ""FutzFixture.NestedFixture"",
                            ""automatedTestName"": ""FutzFixture.NestedFixture"",
                            ""resultGroupType"": ""generic"",
                            ""outcome"": ""Passed"",
                            ""state"": ""InProgress"",
                            ""startedDate"": ""{loggerQueue.Parents["FutzFixture.NestedFixture"].StartedDate.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ")}"",
                            ""automatedTestType"": ""UnitTest"",
                            ""automatedTestTypeId"": ""13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b"",
                            ""automatedTestStorage"": ""Fizz.Buzz""
                        }}
                    ]")
            });
            loggerQueue.Parents.Keys.ShouldBe(new[] { "FitzFixture", "FooFixture", "FutzFixture.NestedFixture" }, true);
            loggerQueue.Parents.Values.Select(x => x.Id).ShouldBe(new[] { 123, 100, 101 }, true);
        }