public void TestDeSerializerAgainstWrong()
 {
     new Action(() => CreateCheckRunSerializer.DeSerialize(Resources.CheckRunSampleWrong))
     .Should()
     .Throw <JsonSerializationException>()
     .WithMessage("Could not find member 'names' on object of type 'CreateCheckRun'. Path 'names', line 1, position 9.");
 }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public async Task <CheckRun> SubmitAsync([NotNull] string owner, [NotNull] string repository, [NotNull] string sha,
                                                 [NotNull] string resourcePath, int pullRequestNumber)
        {
            if (string.IsNullOrWhiteSpace(owner))
            {
                throw new ArgumentException("Owner is null", nameof(owner));
            }

            if (string.IsNullOrWhiteSpace(repository))
            {
                throw new ArgumentException("Repository is null", nameof(repository));
            }

            if (string.IsNullOrWhiteSpace(sha))
            {
                throw new ArgumentException("Sha is null", nameof(sha));
            }

            if (string.IsNullOrWhiteSpace(resourcePath))
            {
                throw new ArgumentException("ResourcePath is null", nameof(resourcePath));
            }

            _logger.LogInformation("SubmitAsync owner:{0} repository:{1} sha:{2} resourcePath:{3}",
                                   owner, repository, sha, resourcePath);

            var readAllText = _fileSystem.File.ReadAllText(resourcePath, Encoding.Unicode);

            var createCheckRun = CreateCheckRunSerializer.DeSerialize(readAllText);

            if (createCheckRun.Summary != null)
            {
                var byteCount = Encoding.Unicode.GetByteCount(createCheckRun.Summary) / 1024.0;
                if (byteCount > 128.0)
                {
                    throw new InvalidOperationException();
                }
            }

            var pullRequestFiles = await _gitHubAppModelService.GetPullRequestFiles(owner, repository, pullRequestNumber);

            var hashSet = new HashSet(pullRequestFiles);

            var annotations = createCheckRun
                              .Annotations.Where(annotation => hashSet.Contains(annotation.Filename))
                              .ToArray();

            return(await _gitHubAppModelService.SubmitCheckRunAsync(owner, repository, sha, createCheckRun, annotations));
        }
 public static string ToJson(this CreateCheckRun createCheckRun) => CreateCheckRunSerializer.Serialize(createCheckRun);
        public void TestDeSerializerAgainstOriginal()
        {
            var createCheckRun = CreateCheckRunSerializer.DeSerialize(Resources.CheckRunSampleOriginal);

            createCheckRun.Should().BeEquivalentTo(CreateCheckRun);
        }
        public void TestSerializer()
        {
            var serialize = CreateCheckRunSerializer.Serialize(CreateCheckRun);

            serialize.Should().Be(Resources.CheckRunSample);
        }