Exemplo n.º 1
0
    public void CopyTo_PartialCopySourceOffset()
    {
        // Arrange
        var content         = "Hello, World!";
        var document        = new StringSourceDocument(content, Encoding.UTF8, RazorSourceDocumentProperties.Default);
        var expectedContent = "World";
        var charBuffer      = new char[expectedContent.Length];

        // Act
        document.CopyTo(7, charBuffer, 0, expectedContent.Length);

        // Assert
        var copiedContent = new string(charBuffer);

        Assert.Equal(expectedContent, copiedContent);
    }
        public void SourceTextSourceDocument_CopyTo_WorksAsExpected()
        {
            // Arrange
            var sourceDocumentProperties = RazorSourceDocumentProperties.Default;
            var stringSourceDocument     = new StringSourceDocument(SourceText.ToString(), Encoding.UTF8, sourceDocumentProperties);
            var stringDocumentBuffer     = new char[stringSourceDocument.Length];

            stringSourceDocument.CopyTo(0, stringDocumentBuffer, 0, stringDocumentBuffer.Length);
            var sourceTextSourceDocument = SourceText.GetRazorSourceDocument(sourceDocumentProperties.FilePath, sourceDocumentProperties.RelativePath);
            var sourceTextDocumentBuffer = new char[sourceTextSourceDocument.Length];

            // Act
            sourceTextSourceDocument.CopyTo(0, sourceTextDocumentBuffer, 0, sourceTextDocumentBuffer.Length);

            // Assert
            Assert.Equal(stringDocumentBuffer, sourceTextDocumentBuffer);
        }
Exemplo n.º 3
0
    public void CopyTo_CanCopyMultipleTimes()
    {
        // Arrange
        var content  = "Hi";
        var document = new StringSourceDocument(content, Encoding.UTF8, RazorSourceDocumentProperties.Default);

        // Act & Assert
        //
        // (we should be able to do this twice to prove that the underlying data isn't disposed)
        for (var i = 0; i < 2; i++)
        {
            var charBuffer = new char[2];
            document.CopyTo(0, charBuffer, 0, 2);
            var copiedContent = new string(charBuffer);
            Assert.Equal("Hi", copiedContent);
        }
    }