Esempio n. 1
0
        public void RazorError_CanBeDeserialized()
        {
            // Arrange
            var error = new RazorError(
                message: "Testing",
                location: new SourceLocation("somepath", absoluteIndex: 1, lineIndex: 2, characterIndex: 3),
                length: 456);
            var serializedError = JsonConvert.SerializeObject(error);

            // Act
            var deserializedError = JsonConvert.DeserializeObject <RazorError>(serializedError);

            // Assert
            Assert.Equal("Testing", deserializedError.Message, StringComparer.Ordinal);
            Assert.Equal(1, deserializedError.Location.AbsoluteIndex);
            Assert.Equal(2, deserializedError.Location.LineIndex);
            Assert.Equal(3, deserializedError.Location.CharacterIndex);
            Assert.Equal(456, deserializedError.Length);
        }
Esempio n. 2
0
        public void RazorError_WithFilePath_CanBeSerialized()
        {
            // Arrange
            var error = new RazorError(
                message: "Testing",
                location: new SourceLocation("some-path", absoluteIndex: 1, lineIndex: 2, characterIndex: 56),
                length: 3);
            var expectedSerializedError =
                $"{{\"{nameof(RazorError.Message)}\":\"Testing\",\"{nameof(RazorError.Location)}\":{{\"" +
                $"{nameof(SourceLocation.FilePath)}\":\"some-path\",\"" +
                $"{nameof(SourceLocation.AbsoluteIndex)}\":1,\"{nameof(SourceLocation.LineIndex)}\":2,\"" +
                $"{nameof(SourceLocation.CharacterIndex)}\":56}},\"{nameof(RazorError.Length)}\":3}}";

            // Act
            var serializedError = JsonConvert.SerializeObject(error);

            // Assert
            Assert.Equal(expectedSerializedError, serializedError, StringComparer.Ordinal);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates and tracks a new <see cref="RazorError"/>.
        /// </summary>
        /// <param name="location"><see cref="SourceLocation"/> of the error.</param>
        /// <param name="message">A message describing the error.</param>
        /// <param name="length">The length of the error.</param>
        public void OnError(SourceLocation location, string message, int length)
        {
            var error = new RazorError(message, location, length);

            _errors.Add(error);
        }
Esempio n. 4
0
 /// <summary>
 /// Tracks the given <paramref name="error"/>.
 /// </summary>
 /// <param name="error">The <see cref="RazorError"/> to track.</param>
 public void OnError(RazorError error) => _errors.Add(error);