Skip to content

Commit

Permalink
Using Microsoft.Fakes for DirectoryHelpers.CreateTempDirectory method…
Browse files Browse the repository at this point in the history
… testing.
  • Loading branch information
vladislav-karamfilov committed Oct 22, 2016
1 parent dba4dfa commit 0a81d10
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Collections.Generic;

namespace MoreDotNet.Tests.Extensions.Collections.EnumerableExtensions
namespace MoreDotNet.Tests.Extensions.Collections.EnumerableExtensions
{
using System;
using System.Collections.Generic;

using MoreDotNet.Extensions.Collections;

using Xunit;

public class ToStringTests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace MoreDotNet.Tests.Helpers.DirectoryHelpers
{
using System;
using System.IO;
using System.IO.Abstractions.TestingHelpers;
using System.IO.Fakes;

using Microsoft.QualityTools.Testing.Fakes;

using MoreDotNet.Helpers;

using Xunit;

public class CreateTempDirectoryTests : IDisposable
{
private readonly MockFileSystem fileSystem;
private readonly IDisposable shimsContext;

public CreateTempDirectoryTests()
{
this.fileSystem = new MockFileSystem();
this.shimsContext = ShimsContext.Create();
this.PrepareFileSystemShims();
}

[Fact]
public void CreateTempDirectory_ShouldCreateTempDirectory()
{
var path = DirectoryHelpers.CreateTempDirectory();
Assert.True(Directory.Exists(path));
}

public void Dispose()
{
this.shimsContext.Dispose();
}

private void PrepareFileSystemShims()
{
ShimDirectory.ExistsString = dirPath => this.fileSystem.Directory.Exists(dirPath);
ShimDirectory.CreateDirectoryString = dirPath =>
{
this.fileSystem.AddDirectory(dirPath);
return new DirectoryInfo(dirPath);
};
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace MoreDotNet.Tests.Helpers.DirectoryHelpers
{
using System.IO;

using MoreDotNet.Helpers;

using Xunit;

public class SafeDeleteDirectoryTests
Expand Down
21 changes: 20 additions & 1 deletion Source/MoreDotNet.Test/MoreDotNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,28 @@
<HintPath>..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.QualityTools.Testing.Fakes, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Moq, Version=4.5.23.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.5.23\lib\net45\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="mscorlib.Fakes">
<HintPath>..\MoreDotNet.Tests.Fakes\FakesAssemblies\mscorlib.Fakes.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Fakes">
<HintPath>..\MoreDotNet.Tests.Fakes\FakesAssemblies\System.Fakes.dll</HintPath>
</Reference>
<Reference Include="System.IO.Abstractions, Version=2.0.0.137, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Abstractions.2.0.0.137\lib\net40\System.IO.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.IO.Abstractions.TestingHelpers, Version=2.0.0.137, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Abstractions.TestingHelpers.2.0.0.137\lib\net40\System.IO.Abstractions.TestingHelpers.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
Expand Down Expand Up @@ -111,7 +126,7 @@
<Compile Include="Models\FakeSerializationClass.cs" />
<Compile Include="Extensions\Common\XmlExtensions\XmlExtensionsTests.cs" />
<Compile Include="Models\XmlSerializableModel.cs" />
<Compile Include="Helpers\DirectoryHelpers\DirectoryHelpersTests.cs" />
<Compile Include="Helpers\DirectoryHelpers\CreateTempDirectoryTests.cs" />
<Compile Include="Helpers\DirectoryHelpers\SafeDeleteDirectoryTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Wrappers\CharWrappersTests.cs" />
Expand All @@ -126,6 +141,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MoreDotNet.Tests.Fakes\MoreDotNet.Tests.Fakes.csproj">
<Project>{71270963-e392-45b4-847a-3a3c33d81de1}</Project>
<Name>MoreDotNet.Tests.Fakes</Name>
</ProjectReference>
<ProjectReference Include="..\MoreDotNet\MoreDotNet.csproj">
<Project>{35bb3946-1a1b-4426-93bd-62d3adc44abe}</Project>
<Name>MoreDotNet</Name>
Expand Down
2 changes: 2 additions & 0 deletions Source/MoreDotNet.Test/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<package id="Castle.Core" version="3.3.3" targetFramework="net452" />
<package id="Moq" version="4.5.23" targetFramework="net452" />
<package id="StyleCop.Analyzers" version="1.0.0" targetFramework="net452" developmentDependency="true" />
<package id="System.IO.Abstractions" version="2.0.0.137" targetFramework="net452" />
<package id="System.IO.Abstractions.TestingHelpers" version="2.0.0.137" targetFramework="net452" />
<package id="xunit" version="2.1.0" targetFramework="net452" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net452" />
<package id="xunit.assert" version="2.1.0" targetFramework="net452" />
Expand Down
Binary file added Source/MoreDotNet.Tests.Fakes/Fakes/System.fakes
Binary file not shown.
Binary file added Source/MoreDotNet.Tests.Fakes/Fakes/mscorlib.fakes
Binary file not shown.
72 changes: 72 additions & 0 deletions Source/MoreDotNet.Tests.Fakes/MoreDotNet.Tests.Fakes.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{71270963-E392-45B4-847A-3A3C33D81DE1}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MoreDotNet.Tests.Fakes</RootNamespace>
<AssemblyName>MoreDotNet.Tests.Fakes</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.QualityTools.Testing.Fakes, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Fakes Include="Fakes\System.fakes" />
</ItemGroup>
<ItemGroup>
<Fakes Include="Fakes\mscorlib.fakes" />
</ItemGroup>
<ItemGroup>
<Content Include="FakesAssemblies\mscorlib.4.0.0.0.Fakes.dll" />
<Content Include="FakesAssemblies\mscorlib.4.0.0.0.Fakes.xml" />
<Content Include="FakesAssemblies\System.4.0.0.0.Fakes.dll" />
<Content Include="FakesAssemblies\System.4.0.0.0.Fakes.xml" />
</ItemGroup>
<ItemGroup>
<None Include="FakesAssemblies\mscorlib.4.0.0.0.Fakes.fakesconfig" />
<None Include="FakesAssemblies\System.4.0.0.0.Fakes.fakesconfig" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
36 changes: 36 additions & 0 deletions Source/MoreDotNet.Tests.Fakes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MoreDotNet.Tests.Fakes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreDotNet.Tests.Fakes")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("71270963-e392-45b4-847a-3a3c33d81de1")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
6 changes: 6 additions & 0 deletions Source/MoreDotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreDotNet", "MoreDotNet\Mo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreDotNet.Tests", "MoreDotNet.Test\MoreDotNet.Tests.csproj", "{26E622DD-17FA-4B3A-A076-78DD5A2113D4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreDotNet.Tests.Fakes", "MoreDotNet.Tests.Fakes\MoreDotNet.Tests.Fakes.csproj", "{71270963-E392-45B4-847A-3A3C33D81DE1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{26E622DD-17FA-4B3A-A076-78DD5A2113D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26E622DD-17FA-4B3A-A076-78DD5A2113D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26E622DD-17FA-4B3A-A076-78DD5A2113D4}.Release|Any CPU.Build.0 = Release|Any CPU
{71270963-E392-45B4-847A-3A3C33D81DE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71270963-E392-45B4-847A-3A3C33D81DE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71270963-E392-45B4-847A-3A3C33D81DE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71270963-E392-45B4-847A-3A3C33D81DE1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 0a81d10

Please # to comment.