Bläddra i källkod

Bug in DocX.SaveAs(fileName) is fixed. (Before fix the size of the resulting file was =0).

master
Viktor Loktev 9 år sedan
förälder
incheckning
2d0c8a1c08
5 ändrade filer med 45 tillägg och 6 borttagningar
  1. 14
    2
      DocX/DocX.cs
  2. 5
    0
      Examples/packages.config
  3. 23
    1
      UnitTests/DocXUnitTests.cs
  4. 2
    2
      UnitTests/UnitTests.csproj
  5. 1
    1
      UnitTests/packages.config

+ 14
- 2
DocX/DocX.cs Visa fil

@@ -3700,8 +3700,20 @@ namespace Novacode
{
using (FileStream fs = new FileStream(filename, FileMode.Create))
{
CopyStream(memoryStream, fs);
}
// Original code
// fs.Write( memoryStream.ToArray(), 0, (int)memoryStream.Length );
// was replaced by save using small buffer
// CopyStream( memoryStream, fs);
// Corection is to make position equal to 0
if(memoryStream.CanSeek)
{
// Write to the beginning of the stream
memoryStream.Position = 0;
CopyStream(memoryStream, fs);
}
else
fs.Write(memoryStream.ToArray(), 0, (int)memoryStream.Length);
}
}
else
{

+ 5
- 0
Examples/packages.config Visa fil

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.6.0" targetFramework="net40" />
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net40" />
</packages>

+ 23
- 1
UnitTests/DocXUnitTests.cs Visa fil

@@ -76,7 +76,29 @@ namespace UnitTests
}
}
[Test]
[Test]
public void Test_DocX_SaveAs()
{
string temporaryFilePath = Path.Combine( _directoryDocuments, "temp.docx" );
// Load the document 'Paragraphs.docx'
using( DocX document = DocX.Load( Path.Combine( _directoryWithFiles, "Paragraphs.docx" ) ) )
{
document.InsertParagraph( "text" );
// Test the saving of the document.
document.SaveAs( temporaryFilePath );
// Check file size
FileInfo f = new FileInfo( temporaryFilePath );
Assert.IsTrue( f.Length == 9659 );
}
// Delete the tempory file.
File.Delete( temporaryFilePath );
}
[Test]
public void TableWithSpecifiedWidths()
{
using (var output = File.Open(Path.Combine(_directoryWithFiles, "TableSpecifiedWidths.docx"), FileMode.Create))

+ 2
- 2
UnitTests/UnitTests.csproj Visa fil

@@ -46,8 +46,8 @@
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\nunit.framework.2.63.0\lib\nunit.framework.dll</HintPath>
<Reference Include="nunit.framework, Version=3.6.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.6.0\lib\net40\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />

+ 1
- 1
UnitTests/packages.config Visa fil

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.4.1" targetFramework="net40" />
<package id="NUnit" version="3.6.0" targetFramework="net40" />
<package id="NUnit.Console" version="3.4.1" targetFramework="net40" />
<package id="NUnit.ConsoleRunner" version="3.4.1" targetFramework="net40" />
<package id="NUnit.Extension.NUnitProjectLoader" version="3.4.1" targetFramework="net40" />

Laddar…
Avbryt
Spara