* origin/develop:
  Fix DateTime wrapper documentation Fixes #45
  Pass Encoding parameter to the ZipFile.Open method Fixes #47
  Added link to NuGet badge (#43)
  Fix disposable pattern to allow to protect behavior when inherited (#39)
This commit is contained in:
Jozef Izso 2018-02-23 21:00:54 +01:00
Родитель 0601a0fbb8 bf4f5e17b2
Коммит bcabcca93d
23 изменённых файлов: 197 добавлений и 23 удалений

Просмотреть файл

@ -1,6 +1,7 @@
# SystemWrapper
![NuGet version](https://img.shields.io/nuget/v/SystemWrapper.Interfaces.svg) ![branch: master](http://img.shields.io/badge/branch-master-blue.svg?style=flat) [![Build status: master](https://ci.appveyor.com/api/projects/status/1126fol0d56a8my8/branch/master?svg=true)](https://ci.appveyor.com/project/jozefizso/systemwrapper/branch/master) ° ![branch: master](http://img.shields.io/badge/branch-develop-blue.svg?style=flat) [![Build status: develop](https://ci.appveyor.com/api/projects/status/1126fol0d56a8my8/branch/develop?svg=true)](https://ci.appveyor.com/project/jozefizso/systemwrapper/branch/develop)
[![NuGet version](https://img.shields.io/nuget/v/SystemWrapper.Interfaces.svg)](https://www.nuget.org/packages/SystemWrapper.Wrappers/)
![branch: master](http://img.shields.io/badge/branch-master-blue.svg?style=flat) [![Build status: master](https://ci.appveyor.com/api/projects/status/1126fol0d56a8my8/branch/master?svg=true)](https://ci.appveyor.com/project/jozefizso/systemwrapper/branch/master) ° ![branch: master](http://img.shields.io/badge/branch-develop-blue.svg?style=flat) [![Build status: develop](https://ci.appveyor.com/api/projects/status/1126fol0d56a8my8/branch/develop?svg=true)](https://ci.appveyor.com/project/jozefizso/systemwrapper/branch/develop)
> **SystemWrapper** is .NET library for easier testing of system APIs.

Просмотреть файл

@ -6,7 +6,7 @@ namespace SystemInterface
using System.Diagnostics.CodeAnalysis;
/// <summary>
/// Wrapper for <see cref="System.Version"/> class.
/// Wrapper for <see cref="System.DateTime"/> class.
/// </summary>
public interface IDateTime
{

Просмотреть файл

@ -1,4 +1,5 @@
using System.IO;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
@ -135,14 +136,40 @@ namespace SystemWrapper.Tests.IO.Compression
}
[Test]
public void Open_WithEncoding_Creates_ZipArchiveWrap()
public void Open_WithUTF8Encoding_Creates_OpensZipWithCorrectEncoding()
{
var assembly = Assembly.GetAssembly(typeof(ZipFileWrapTests));
var testFilePath = assembly.CodeBase.Substring(8); //remove the "file://" from the front
testFilePath = Path.GetDirectoryName(testFilePath) + @"\TestData\Encoding_UTF8.zip";
var instance = new ZipFileWrap();
instance.CreateFromDirectory(ArchiveDirectory, ArchiveFileName);
using (var archive = instance.Open(ArchiveFileName, System.IO.Compression.ZipArchiveMode.Read, Encoding.UTF8))
using (var archive = instance.Open(testFilePath, System.IO.Compression.ZipArchiveMode.Read, Encoding.UTF8))
{
Assert.IsNotNull(archive);
Assert.IsInstanceOf<ZipArchiveWrap>(archive);
var entry = archive.Entries.First();
Assert.AreEqual("text-ľščťžýáíé.txt", entry.Name);
}
}
[Test]
public void Open_WithWindows1250Encoding_OpensZipWithCorrectEncoding()
{
var assembly = Assembly.GetAssembly(typeof(ZipFileWrapTests));
var testFilePath = assembly.CodeBase.Substring(8); //remove the "file://" from the front
testFilePath = Path.GetDirectoryName(testFilePath) + @"\TestData\Encoding_Windows1250.zip";
var instance = new ZipFileWrap();
var encodingWindows1250 = Encoding.GetEncoding(1250);
using (var archive = instance.Open(testFilePath, System.IO.Compression.ZipArchiveMode.Read, encodingWindows1250))
{
Assert.IsNotNull(archive);
Assert.IsInstanceOf<ZipArchiveWrap>(archive);
var entry = archive.Entries.First();
Assert.AreEqual("text-ľščťžýáíé.txt", entry.Name);
}
}
@ -158,4 +185,4 @@ namespace SystemWrapper.Tests.IO.Compression
}
}
}
}
}

Просмотреть файл

@ -118,6 +118,12 @@
<None Include="packages.config" />
<None Include="Settings.StyleCop" />
<None Include="SystemWrapper.snk" />
<Content Include="TestData\Encoding_UTF8.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\Encoding_Windows1250.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

Двоичные данные
SystemWrapper.Tests/TestData/Encoding_UTF8.zip Normal file

Двоичный файл не отображается.

Двоичные данные
SystemWrapper.Tests/TestData/Encoding_Windows1250.zip Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -168,6 +168,16 @@
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
this.directoryEntry.Dispose();
}
@ -184,4 +194,4 @@
#endregion
}
}
}

Просмотреть файл

@ -1,5 +1,6 @@
namespace SystemWrapper.ActiveDirectory
{
using System;
using System.Collections.Specialized;
using System.DirectoryServices;
@ -129,6 +130,16 @@
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
this.directorySearcher.Dispose();
}
@ -162,4 +173,4 @@
#endregion
}
}
}

Просмотреть файл

@ -1,5 +1,6 @@
namespace SystemWrapper.ActiveDirectory
{
using System;
using System.DirectoryServices.AccountManagement;
using SystemWrapper.ActiveDirectory.Contracts;
@ -51,10 +52,20 @@ namespace SystemWrapper.ActiveDirectory
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
this.principalContext.Dispose();
}
#endregion
}
}
}

Просмотреть файл

@ -147,6 +147,16 @@ namespace SystemWrapper.ActiveDirectory
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
this.searchResultCollection.Dispose();
}
@ -191,4 +201,4 @@ namespace SystemWrapper.ActiveDirectory
#endregion
}
}
}

Просмотреть файл

@ -6,7 +6,7 @@ using SystemInterface;
namespace SystemWrapper
{
/// <summary>
/// Wrapper for <see cref="System.Version"/> class.
/// Wrapper for <see cref="System.DateTime"/> class.
/// </summary>
[Serializable]
public class DateTimeWrap : IDateTime
@ -795,4 +795,4 @@ namespace SystemWrapper
return returnValue;
}
}
}
}

Просмотреть файл

@ -1,3 +1,4 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
@ -258,6 +259,16 @@ namespace SystemWrapper.IO
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
BinaryReaderInstance.Close();
}

Просмотреть файл

@ -247,6 +247,16 @@ namespace SystemWrapper.IO
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
BinaryWriterInstance.Close();
}

Просмотреть файл

@ -1,4 +1,5 @@
using System.IO.Compression;
using System;
using System.IO.Compression;
using SystemInterface.IO;
using SystemInterface.IO.Compression;
@ -75,6 +76,16 @@ namespace SystemWrapper.IO.Compression
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
DeflateStreamInstance.Dispose();
}

Просмотреть файл

@ -47,6 +47,16 @@ namespace SystemWrapper.IO.Compression
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
Instance.Dispose();
}

Просмотреть файл

@ -1,4 +1,4 @@
using System.IO.Compression;
using System.IO.Compression;
using System.Text;
using SystemInterface.IO.Compression;
@ -38,7 +38,7 @@ namespace SystemWrapper.IO.Compression
public IZipArchive Open(string archiveFileName, System.IO.Compression.ZipArchiveMode mode, Encoding entryNameEncoding)
{
return new ZipArchiveWrap(ZipFile.Open(archiveFileName, mode));
return new ZipArchiveWrap(ZipFile.Open(archiveFileName, mode, entryNameEncoding));
}
public IZipArchive OpenRead(string archiveFileName)

Просмотреть файл

@ -568,6 +568,16 @@ namespace SystemWrapper.IO
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
FileStreamInstance.Dispose();
}

Просмотреть файл

@ -406,6 +406,16 @@ namespace SystemWrapper.IO
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
MemoryStreamInstance.Dispose();
}

Просмотреть файл

@ -376,6 +376,16 @@ namespace SystemWrapper.IO
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
StreamReaderInstance.Dispose();
}

Просмотреть файл

@ -212,6 +212,16 @@
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
this.StreamInstance.Dispose();
}

Просмотреть файл

@ -1,3 +1,4 @@
using System;
using System.Security.AccessControl;
using Microsoft.Win32;
using SystemInterface.Microsoft.Win32;
@ -19,6 +20,16 @@ namespace SystemWrapper.Microsoft.Win32
/// Implementation of the Dispose.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
RegistryKeyInstance.Dispose();
}

Просмотреть файл

@ -2,8 +2,6 @@
{
using System;
using System.ServiceModel;
using SystemInterface.Attributes;
using SystemInterface.ServiceModel;
/// <summary>
@ -69,6 +67,7 @@
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(true);
}
#endregion

Просмотреть файл

@ -258,11 +258,17 @@ namespace SystemWrapper.Xml
/// <exception cref="T:System.InvalidOperationException">An <see cref="T:System.Xml.XmlWriter"/> method was called before a previous asynchronous operation finished. In this case, <see cref="T:System.InvalidOperationException"/> is thrown with the message “An asynchronous operation is already in progress.”</exception>
public void Dispose()
{
var disposable = this.instance as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">Indicates whether or not unmanaged resources should be disposed.</param>
protected virtual void Dispose(bool disposing)
{
this.instance.Dispose();
}
/// <summary>