Skip to content

Commit

Permalink
.Net 3.5 Client Profile unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Fauchelle committed Mar 4, 2015
1 parent 8e4724e commit 1a0218a
Show file tree
Hide file tree
Showing 15 changed files with 1,106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.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>{30696896-9463-441E-9789-C79F6BF7B793}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mindscape.Raygun4Net.Tests</RootNamespace>
<AssemblyName>Mindscape.Raygun4Net.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile>Client</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="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Model\CyclicObject.cs" />
<Compile Include="Model\FakeException.cs" />
<Compile Include="Model\FakeRaygunClient.cs" />
<Compile Include="Model\WrapperException.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RaygunClientBaseTests.cs" />
<Compile Include="RaygunClientTests.cs" />
<Compile Include="RaygunErrorMessageExceptionTests.cs" />
<Compile Include="RaygunErrorMessageInnerExceptionTests.cs" />
<Compile Include="RaygunMessageBuilderTests.cs" />
<Compile Include="RaygunSettingsTests.cs" />
<Compile Include="SimpleJsonTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mindscape.Raygun4Net.ClientProfile\Mindscape.Raygun4Net.ClientProfile.csproj">
<Project>{495E53B3-F3AF-4C4F-BAAF-865EFAA2F4A9}</Project>
<Name>Mindscape.Raygun4Net.ClientProfile</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.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>
44 changes: 44 additions & 0 deletions Mindscape.Raygun4Net.ClientProfile.Tests/Model/CyclicObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mindscape.Raygun4Net.Tests.Model
{
public class CyclicObject
{
private CyclicObject _child;
private CyclicObject[] _array = new CyclicObject[1];
private readonly IDictionary _dictionary = new Dictionary<object, object>();
private readonly IDictionary<string, object> _genericDictionary = new Dictionary<string, object>();

public CyclicObject Child
{
get { return _child; }
set
{
_child = value;
}
}

public CyclicObject[] Array
{
get { return _array; }
set
{
_array = value;
}
}

public IDictionary Dictionary
{
get { return _dictionary; }
}

public IDictionary<string, object> GenericDictionary
{
get { return _genericDictionary; }
}
}
}
26 changes: 26 additions & 0 deletions Mindscape.Raygun4Net.ClientProfile.Tests/Model/FakeException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mindscape.Raygun4Net.Tests
{
public class FakeException : Exception
{
private IDictionary _data;

public FakeException(IDictionary data)
{
_data = data;
}

public override System.Collections.IDictionary Data
{
get
{
return _data;
}
}
}
}
51 changes: 51 additions & 0 deletions Mindscape.Raygun4Net.ClientProfile.Tests/Model/FakeRaygunClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using Mindscape.Raygun4Net.Messages;

namespace Mindscape.Raygun4Net.Tests
{
public class FakeRaygunClient : RaygunClient
{
public FakeRaygunClient() { }

public FakeRaygunClient(string apiKey)
: base(apiKey)
{
}

public RaygunMessage ExposeBuildMessage(Exception exception, [Optional] IList<string> tags, [Optional] IDictionary userCustomData, [Optional] RaygunIdentifierMessage userIdentifierMessage)
{
return BuildMessage(exception, tags, userCustomData, userIdentifierMessage);
}

public WebClient ExposeCreateWebClient()
{
return CreateWebClient();
}

public bool ExposeValidateApiKey()
{
return ValidateApiKey();
}

public bool ExposeOnSendingMessage(RaygunMessage raygunMessage)
{
return OnSendingMessage(raygunMessage);
}

public bool ExposeCanSend(Exception exception)
{
return CanSend(exception);
}

public void ExposeFlagAsSent(Exception exception)
{
FlagAsSent(exception);
}
}
}
15 changes: 15 additions & 0 deletions Mindscape.Raygun4Net.ClientProfile.Tests/Model/WrapperException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mindscape.Raygun4Net.Tests
{
public class WrapperException : Exception
{
public WrapperException(Exception innerException)
: base("Something went wrong", innerException)
{
}
}
}
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("Mindscape.Raygun4Net.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Mindscape")]
[assembly: AssemblyProduct("Mindscape.Raygun4Net.Tests")]
[assembly: AssemblyCopyright("Copyright © Mindscape 2012-2015")]
[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("fd1d565f-38ab-469a-b930-2b005b3d4b79")]

// 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")]
62 changes: 62 additions & 0 deletions Mindscape.Raygun4Net.ClientProfile.Tests/RaygunClientBaseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mindscape.Raygun4Net.Messages;
using NUnit.Framework;

namespace Mindscape.Raygun4Net.Tests
{
[TestFixture]
public class RaygunClientBaseTests
{
private FakeRaygunClient _client = new FakeRaygunClient();

[Test]
public void FlagAsSentDoesNotCrash_DataDoesNotSupportStringKeys()
{
Assert.That(() => _client.ExposeFlagAsSent(new FakeException(new Dictionary<int, object>())), Throws.Nothing);
}

[Test]
public void FlagAsSentDoesNotCrash_NullData()
{
Assert.That(() => _client.ExposeFlagAsSent(new FakeException(null)), Throws.Nothing);
}

[Test]
public void CanSendIfDataIsNull()
{
Assert.IsTrue(_client.ExposeCanSend(new FakeException(null)));
}

[Test]
public void CannotSendSentException_StringDictionary()
{
Exception exception = new FakeException(new Dictionary<string, object>());
_client.ExposeFlagAsSent(exception);
Assert.IsFalse(_client.ExposeCanSend(exception));
}

[Test]
public void CannotSendSentException_ObjectDictionary()
{
Exception exception = new FakeException(new Dictionary<object, object>());
_client.ExposeFlagAsSent(exception);
Assert.IsFalse(_client.ExposeCanSend(exception));
}

[Test]
public void ExceptionInsideSendingMessageHAndlerDoesNotCrash()
{
FakeRaygunClient client = new FakeRaygunClient();
client.SendingMessage += (sender, args) =>
{
throw new Exception("Oops...");
};

Assert.That(() => client.ExposeOnSendingMessage(new RaygunMessage()), Throws.Nothing);
Assert.IsTrue(client.ExposeOnSendingMessage(new RaygunMessage()));
}
}
}
Loading

0 comments on commit 1a0218a

Please sign in to comment.