示例#1
0
        public static string GetTestJsonData(BDTestRunDescriptor bdTestRunDescriptor)
        {
            var scenarios = BDTestUtil.GetScenarios();

            var testTimer = GetTestTimer(scenarios);

            var dataToOutput = new BDTestOutputModel
            {
                Id          = BDTestUtil.GetCurrentReportId,
                Environment = bdTestRunDescriptor?.Environment ?? BDTestSettings.Environment,
                Tag         = bdTestRunDescriptor?.Tag ?? BDTestSettings.Tag,
                BranchName  = bdTestRunDescriptor?.BranchName ?? BDTestSettings.BranchName,
                MachineName = Environment.MachineName,
                Scenarios   = scenarios,
                TestTimer   = testTimer,
                NotRun      = BDTestUtil.GetNotRunScenarios(),
                Version     = BDTestVersionHelper.CurrentVersion
            };

            var settings = new JsonSerializerSettings
            {
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            };

            return(JsonConvert.SerializeObject(dataToOutput, Formatting.Indented, settings));
        }
示例#2
0
 public IEnumerable <CustomLinkData> GetCustomLinks(BDTestOutputModel currentTestReport)
 {
     return(new List <CustomLinkData>
     {
         new CustomLinkData("Google", new Uri("https://www.google.com"))
     });
 }
示例#3
0
 private static void AddCustomProperties(BDTestOutputModel dataOutputModel)
 {
     foreach (var customProperty in BDTestSettings.CustomProperties)
     {
         dataOutputModel.CustomProperties.Add(customProperty.Key, customProperty.Value);
     }
 }
示例#4
0
        private void SetCounts(BDTestOutputModel bdTestOutputModel)
        {
            Counts.Total  = bdTestOutputModel.Scenarios.Count;
            Counts.NotRun = bdTestOutputModel.NotRun?.Count ?? 0;

            foreach (var scenario in bdTestOutputModel.Scenarios)
            {
                switch (scenario.Status)
                {
                case Status.Passed:
                    Counts.Passed++;
                    break;

                case Status.Failed:
                    Counts.Failed++;
                    break;

                case Status.Inconclusive:
                    Counts.Inconclusive++;
                    break;

                case Status.NotImplemented:
                    Counts.NotImplemented++;
                    break;

                case Status.Skipped:
                    Counts.Skipped++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
示例#5
0
        internal TestRunSummary(BDTestOutputModel bdTestOutputModel)
        {
            RecordId           = bdTestOutputModel.Id;
            StartedAtDateTime  = bdTestOutputModel.TestTimer.TestsStartedAt;
            FinishedAtDateTime = bdTestOutputModel.TestTimer.TestsFinishedAt;
            Status             = bdTestOutputModel.Scenarios.GetTotalStatus();
            Tag         = bdTestOutputModel.Tag;
            Environment = bdTestOutputModel.Environment;
            Version     = bdTestOutputModel.Version;
            MachineName = bdTestOutputModel.MachineName;
            BranchName  = bdTestOutputModel.BranchName;

            SetCounts(bdTestOutputModel);
        }
示例#6
0
 public static TestTimer GetTestTimer(IReadOnlyCollection <Scenario> scenarios,
                                      BDTestOutputModel totalReportData)
 {
     return(scenarios.Count switch
     {
         0 when totalReportData != null => new TestTimer
         {
             TestsStartedAt = totalReportData.TestTimer.TestsStartedAt,
             TestsFinishedAt = totalReportData.TestTimer.TestsFinishedAt
         },
         0 => new TestTimer(),
         _ => new TestTimer
         {
             TestsStartedAt = scenarios.GetStartDateTime(), TestsFinishedAt = scenarios.GetEndDateTime()
         }
     });
示例#7
0
        public OutputMetrics(BDTestOutputModel bdTestOutputModel)
        {
            if (bdTestOutputModel == null)
            {
                return;
            }

            foreach (var scenario in bdTestOutputModel.Scenarios)
            {
                switch (scenario.Status)
                {
                case Status.Failed:
                    AnyFailed = true;
                    AllPassed = false;
                    break;

                case Status.Inconclusive:
                    AnyInconclusive = true;
                    AllPassed       = false;
                    break;

                case Status.Skipped:
                    AnySkipped = true;
                    AllPassed  = false;
                    break;

                case Status.NotImplemented:
                    AnyNotImplemented = true;
                    AllPassed         = false;
                    break;

                case Status.Passed:
                    AnyPassed = true;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (scenario.Exception != null)
                {
                    AnyExceptions = true;
                }
            }

            AnyWarnings = bdTestOutputModel.NotRun.Any();
        }
示例#8
0
        public async Task <IActionResult> Index([FromBody] BDTestOutputModel bdTestOutputModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var id = bdTestOutputModel.Id ?? Guid.NewGuid().ToString("N");

            await _dataRepository.StoreData(bdTestOutputModel, id);

            if (_bdTestReportServerOptions.DataReceiver != null)
            {
                await _bdTestReportServerOptions.DataReceiver.OnReceiveTestDataAsync(bdTestOutputModel);
            }

            return(Ok(Url.ActionLink("Summary", "BDTest", new { id })));
        }
示例#9
0
 internal static TestRunSummary GetOverview(this BDTestOutputModel bdTestOutputModel)
 {
     return(new TestRunSummary(bdTestOutputModel));
 }
示例#10
0
        public static async Task <Uri> SendDataAndGetReportUriAsync(Uri serverAddress, BDTestRunDescriptor bdTestRunDescriptor,
                                                                    HttpClient httpClient)
        {
            var pingUri = new UriBuilder(serverAddress)
            {
                Path = "bdtest/ping"
            }.Uri;

            try
            {
                await httpClient.GetAsync(pingUri);
            }
            catch
            {
                // Result ignored - This is just to make sure the server is warmed up. If not, it'll warm it up!
            }

            var uploadUri = new UriBuilder(serverAddress)
            {
                Path = "bdtest/data"
            }.Uri;

            var scenarios = TestHolder.ScenariosByInternalId.Values.ToList();

            var dataOutputModel = new BDTestOutputModel
            {
                Id          = TestHolder.CurrentReportId,
                Environment = bdTestRunDescriptor?.Environment ?? BDTestSettings.Environment,
                Tag         = bdTestRunDescriptor?.Tag ?? BDTestSettings.Tag,
                BranchName  = bdTestRunDescriptor?.BranchName ?? BDTestSettings.BranchName,
                MachineName = Environment.MachineName,
                Scenarios   = scenarios,
                Version     = BDTestVersionHelper.CurrentVersion,
                NotRun      = TestHolder.NotRun.Values.ToList(),
                TestTimer   = BDTestUtil.GetTestTimer(scenarios)
            };

            AddCustomProperties(dataOutputModel);

            var stringContent = JsonConvert.SerializeObject(dataOutputModel);

            string responseContent;
            var    attempts = 0;

            while (true)
            {
                var stringHttpContent = new StringContent(stringContent, Encoding.UTF8, "application/json");

                try
                {
                    var httpRequestMessage = new HttpRequestMessage
                    {
                        RequestUri = uploadUri,
                        Method     = HttpMethod.Post,
                        Content    = stringHttpContent
                    };

                    var response = await httpClient.SendAsync(httpRequestMessage);

                    responseContent = await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync();

                    break;
                }
                catch (Exception)
                {
                    attempts++;
                    if (attempts == 3)
                    {
                        throw;
                    }
                }
            }

            return(new Uri(responseContent));
        }
示例#11
0
 public async Task StoreTestData(string id, BDTestOutputModel data)
 {
     await _testRecordContainer.CreateItemAsync(data, new PartitionKey(id));
 }
示例#12
0
 public Task StoreTestData(string id, BDTestOutputModel data)
 {
     return(_testDataContainer.GetBlockBlobClient(id).UploadAsync(data.AsStream()));
 }