示例#1
0
        private async Task <List <TestRunStepItem> > GenerateInputFiles(TestReadModel test, TestRunReadModel testRun)
        {
            var result = new List <TestRunStepItem>();

            _processingRunData.AllItemsCount    = ProcessingRun.Type == RunType.Quick ? test.IoExamples.Count + 3 : test.IoExamples.Count + 100;
            _processingRunData.CurrentItemIndex = 0;

            foreach (var ioExample in test.IoExamples)
            {
                var started = DateTime.Now;

                var inputName = ioExample.Name.Replace(' ', '_');

                _processingRunData.CurrentItemName = inputName;
                SendRunData();

                var inputPath = _paths.RunsData[ProcessingRun.Id][testRun.Id].Inputs[inputName].Absolute;
                await File.WriteAllTextAsync(inputPath, ioExample.Input);

                var finished = DateTime.Now;

                var item = new TestRunStepItem
                {
                    Id   = Guid.NewGuid(),
                    Name = Path.GetFileNameWithoutExtension(inputPath),
                    ProcessedForMilliseconds = (int)(finished - started).TotalMilliseconds,
                    Outcome = RunOutcome.Ok
                };
                result.Add(item);

                _processingRunData.CurrentItemIndex++;
            }

            var randomInputsToGenerate = ProcessingRun.Type == RunType.Full ? 100 : 3;

            {
                var inputFactory = new InputFactory(test.Input);

                for (int i = 1; i <= randomInputsToGenerate; i++)
                {
                    var started = DateTime.Now;

                    var inputName = $"Random_{i.ToString("D3")}";

                    _processingRunData.CurrentItemName = inputName;
                    SendRunData();

                    var inputPath = _paths.RunsData[ProcessingRun.Id][testRun.Id].Inputs[inputName].Absolute;
                    var input     = inputFactory.GenerateRandomInput();

                    if (input != null)
                    {
                        await File.WriteAllTextAsync(inputPath, input);
                    }

                    var finished = DateTime.Now;

                    var item = new TestRunStepItem
                    {
                        Id   = Guid.NewGuid(),
                        Name = Path.GetFileNameWithoutExtension(inputPath),
                        ProcessedForMilliseconds = (int)(finished - started).TotalMilliseconds,
                        Outcome = input != null ? RunOutcome.Ok : RunOutcome.Wrong
                    };
                    result.Add(item);

                    _processingRunData.CurrentItemIndex++;
                }
            }

            return(result);
        }