Skip to content

Commit

Permalink
Adding useful mocks. related #1
Browse files Browse the repository at this point in the history
  • Loading branch information
andreazevedo committed Aug 9, 2011
1 parent 985a669 commit 2cd1477
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/PetStore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{78965154-D
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PetStore.Core.Test", "Test\PetStore.Core.Test\PetStore.Core.Test.csproj", "{BF525221-D587-4727-A48D-9AFDADF2A3CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PetStore.TestBase", "Test\PetStore.TestBase\PetStore.TestBase.csproj", "{BE801B36-49C9-4770-952C-76259F81F5FF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,11 +29,16 @@ Global
{BF525221-D587-4727-A48D-9AFDADF2A3CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF525221-D587-4727-A48D-9AFDADF2A3CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF525221-D587-4727-A48D-9AFDADF2A3CB}.Release|Any CPU.Build.0 = Release|Any CPU
{BE801B36-49C9-4770-952C-76259F81F5FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE801B36-49C9-4770-952C-76259F81F5FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE801B36-49C9-4770-952C-76259F81F5FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE801B36-49C9-4770-952C-76259F81F5FF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BF525221-D587-4727-A48D-9AFDADF2A3CB} = {78965154-DBB2-4B27-AC6E-5B56E0C85A22}
{BE801B36-49C9-4770-952C-76259F81F5FF} = {78965154-DBB2-4B27-AC6E-5B56E0C85A22}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PetStore.Core.Infrastructure.Crypt;

namespace PetStore.TestBase.Mocks.Core.Infrastructure.Crypt
{
public class CryptographyMock : ICryptography
{
public string Encrypt(string value)
{
return value;
}

public string Decrypt(string encryptedValue)
{
return encryptedValue;
}

public string ComputeHash(string value)
{
return value;
}

public string ComputeHash(byte[] value)
{
return value.ToString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PetStore.Core.Infrastructure.Logging;

namespace PetStore.TestBase.Mocks.Core.Infrastructure.Logging
{
public class LoggerMock : ILogger
{
#region Static Properties

private static List<string> _messages;

public static List<string> Messages
{
get { return _messages ?? (_messages = new List<string>()); }
}

#endregion

#region Public Methods

public void Info(string message)
{
Messages.Add(message);
}

public void Warning(string message)
{
Messages.Add(message);
}

public void Error(string message)
{
Messages.Add(message);
}

public void Exception(Exception exception)
{
Messages.Add(exception.Message);
}

public void Exception(Exception exception, string message)
{
Messages.Add(message + " " + exception.Message);
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using PetStore.Core.Infrastructure.Mail;

namespace PetStore.TestBase.Mocks.Core.Infrastructure.Mail
{
public class EmailSenderMock : IEmailSender
{
#region Properties

public int SendEmailCallCount { get; private set; }

#endregion

public void SendEmail(MailMessage mailMessage)
{
SendEmailCallCount++;
}

public void SendEmail(string from, string recipients, string subject, string body)
{
SendEmailCallCount++;
}
}
}
62 changes: 62 additions & 0 deletions src/Test/PetStore.TestBase/PetStore.TestBase.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BE801B36-49C9-4770-952C-76259F81F5FF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PetStore.TestBase</RootNamespace>
<AssemblyName>PetStore.TestBase</AssemblyName>
<TargetFrameworkVersion>v4.0</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="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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Mocks\Core\Infrastructure\Crypt\CryptographyMock.cs" />
<Compile Include="Mocks\Core\Infrastructure\Logging\LoggerMock.cs" />
<Compile Include="Mocks\Core\Infrastructure\Mail\EmailSenderMock.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\PetStore.Core\PetStore.Core.csproj">
<Project>{FF79E5EE-F489-4239-B935-DA2C06848BFA}</Project>
<Name>PetStore.Core</Name>
</ProjectReference>
</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 src/Test/PetStore.TestBase/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("PetStore.TestBase")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("PetStore.TestBase")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[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("c96b1f82-85ef-4629-9561-cba7662c8e9d")]

// 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")]

0 comments on commit 2cd1477

Please sign in to comment.