Skip to content

Commit

Permalink
Merge pull request #8 from johnmwright/typeTests
Browse files Browse the repository at this point in the history
adding support for shims with void returns.  Adding unit tests for a …
  • Loading branch information
johnmwright authored Mar 19, 2018
2 parents e5495b5 + 6d3fa74 commit 9fdb127
Show file tree
Hide file tree
Showing 13 changed files with 1,349 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ UpgradeLog*.XML
# Visual Studio 2015 cache/options directory
.vs/
/Fakes.Contrib/Demo.Scenarios/FakesAssemblies
/Fakes.Contrib/Fakes.Contrib.Tests/FakesAssemblies
124 changes: 124 additions & 0 deletions Fakes.Contrib/Fakes.Contrib.Tests.Classes/ClassUnderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.IO;

namespace Fakes.Contrib.Tests.Classes
{

public class ClassUnderTest
{
public void TestMethod_ArrayOfLongs(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesArray(new long[] { long.MinValue, 0, 1, 2, 3, long.MaxValue });
}

public void TestMethod_LongParams(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesParams(long.MinValue, 1, 2, 3, long.MaxValue);
}


public void TestMethod_ArrayOfLongs(IMethodsThatTakeArrays dependancy, long[] inputs)
{
dependancy.MethodTakesArray(inputs);
}

public void TestMethod_ArrayOfInt(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesArray(new int[] { int.MinValue, 0, 1, 2, 3, int.MaxValue });
}

public void TestMethod_IntParams(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesParams(int.MinValue, 1, 2, 3, int.MaxValue);
}


public void TestMethod_ArrayOfInt(IMethodsThatTakeArrays dependancy, int[] inputs)
{
dependancy.MethodTakesArray(inputs);
}

public void TestMethod_ArrayOfString(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesArray(new string[] { "", "foo", "bar", "baz", "bin" });
}

public void TestMethod_StringParams(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesParams("", "foo", "bar", "baz", "bin");
}


public void TestMethod_ArrayOfString(IMethodsThatTakeArrays dependancy, string[] inputs)
{
dependancy.MethodTakesArray(inputs);
}

public void TestMethod_ArrayOfObject(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesArray<object>(new object[] { new object(), "bin", new ClassUnderTest() });
}

public void TestMethod_ObjectParams(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesParams<object>(new object(), "bin", new ClassUnderTest());
}


public void TestMethod_ArrayOfObject(IMethodsThatTakeArrays dependancy, object[] inputs)
{
dependancy.MethodTakesArray(inputs);
}

public void TestMethod_ArrayOfInterface(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesArray(new IDisposable[] { new StreamReader(Stream.Null), new MemoryStream() });
}

public void TestMethod_InterfaceParams(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesParams<IDisposable>(new StreamReader(Stream.Null), new MemoryStream());
}


public void TestMethod_ArrayOfInterface(IMethodsThatTakeArrays dependancy, IDisposable[] inputs)
{
dependancy.MethodTakesArray(inputs);
}

public void TestMethod_ArrayOfGeneric(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesArray(new List<int>[] { new List<int>() { 0, 1 }, new List<int>() { 3, 4 } });
}

public void TestMethod_GenericParams(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesParams(new List<int>() { 0, 1 }, new List<int>() { 3, 4 });
}


public void TestMethod_ArrayOfGeneric(IMethodsThatTakeArrays dependancy, List<int>[] inputs)
{
dependancy.MethodTakesArray(inputs);
}

public void TestMethod_ArrayOfDates(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesArray(new DateTime[] { DateTime.MinValue, DateTime.MaxValue, DateTime.Now });
}

public void TestMethod_DateParams(IMethodsThatTakeArrays dependancy)
{
dependancy.MethodTakesParams(DateTime.MinValue, DateTime.MaxValue, DateTime.Now);
}


public void TestMethod_ArrayOfDates(IMethodsThatTakeArrays dependancy, DateTime[] inputs)
{
dependancy.MethodTakesArray(inputs);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{4B6BC67E-4782-4838-BA96-C6F7E56C73ED}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Fakes.Contrib.Tests.Classes</RootNamespace>
<AssemblyName>Fakes.Contrib.Tests.Classes</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</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="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="ClassUnderTest.cs" />
<Compile Include="MethodsThatTakeArrays.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
34 changes: 34 additions & 0 deletions Fakes.Contrib/Fakes.Contrib.Tests.Classes/MethodsThatTakeArrays.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Fakes.Contrib.Tests.Classes
{
public interface IMethodsThatTakeArrays
{
void MethodTakesArray<T>(T[] inputs);
void MethodTakesParams<T>(params T[] inputs);
}

public class MethodsThatTakeArrays : IMethodsThatTakeArrays
{
public virtual void MethodTakesArray<T>(T[] inputs)
{
}

public virtual void MethodTakesParams<T>(params T[] inputs)
{
}

}

public class NonVirtualMethodsThatTakeArrays : IMethodsThatTakeArrays
{
public void MethodTakesArray<T>(T[] inputs)
{
}

public void MethodTakesParams<T>(params T[] inputs)
{
}

}


}
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("Fakes.Contrib.Tests.Classes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Fakes.Contrib.Tests.Classes")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[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("4b6bc67e-4782-4838-ba96-c6f7e56c73ed")]

// 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.*")]
[assembly: AssemblyFileVersion("1.0")]
11 changes: 11 additions & 0 deletions Fakes.Contrib/Fakes.Contrib.Tests/Fakes.Contrib.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Fakes.Contrib.Tests.Classes.Fakes">
<HintPath>FakesAssemblies\Fakes.Contrib.Tests.Classes.Fakes.dll</HintPath>
</Reference>
<Reference Include="Microsoft.QualityTools.Testing.Fakes, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
Expand All @@ -63,11 +66,19 @@
</Compile>
<Compile Include="StubBaseExtensionsTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TypeTestsForClassShims.cs" />
<Compile Include="TypeTestsForInterfaceStubs.cs" />
<Compile Include="TypeTestsForClassStubs.cs" />
</ItemGroup>
<ItemGroup>
<Fakes Include="Fakes\Fakes.Contrib.Tests.Classes.fakes" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fakes.Contrib.Tests.Classes\Fakes.Contrib.Tests.Classes.csproj">
<Project>{4b6bc67e-4782-4838-ba96-c6f7e56c73ed}</Project>
<Name>Fakes.Contrib.Tests.Classes</Name>
</ProjectReference>
<ProjectReference Include="..\Fakes.Contrib\Fakes.Contrib.csproj">
<Project>{56e2764a-8d9d-4648-bf89-e9516f4b038b}</Project>
<Name>Fakes.Contrib</Name>
Expand Down
Binary file not shown.
Loading

0 comments on commit 9fdb127

Please sign in to comment.