Пример #1
0
        public static async Task <RelayDocument?> TryParseRelayDocumentAsync(
            IFile file,
            DocumentInfo documentInfo,
            IssueLogger logger,
            CancellationToken cancellationToken)
        {
            try
            {
                using var fs = await file.OpenAsync(cancellationToken).ConfigureAwait(false);

                using var sr = new StreamReader(fs);

                string sourceText = await sr.ReadToEndAsync().ConfigureAwait(false);

                return(RelayDocument.Parse(documentInfo, sourceText));
            }
            catch (Exception ex)
            {
                await logger.LogIssueAsync(
                    new Issue(
                        "PARSING_FAILED",
                        ex.Message,
                        file.Name,
                        new Location(0, 0, 1, 1),
                        IssueType.Error,
                        ResolutionType.CannotBeFixed),
                    cancellationToken)
                .ConfigureAwait(false);

                return(null);
            }
        }
Пример #2
0
 public void Parse_SourceText_Is_Empty()
 {
     Assert.Throws <ArgumentException>(
         () => RelayDocument.Parse(
             new DocumentInfo("abc", null, "sha1", HashFormat.Base64),
             string.Empty));
 }
Пример #3
0
        public void Parse_Valid_Document_With_Hash_Details()
        {
            // arrange
            string sourceText   = FileResource.Open("relay.json");
            var    documentInfo = new DocumentInfo("abc", null, "sha1", HashFormat.Base64);

            // act
            RelayDocument document = RelayDocument.Parse(documentInfo, sourceText);

            // assert
            document.MatchSnapshot();
        }
Пример #4
0
 public void Parse_DocumentInfo_Is_Null()
 {
     Assert.Throws <ArgumentNullException>(
         () => RelayDocument.Parse(null, "abc"));
 }