Skip to content

Commit

Permalink
Merge pull request #112 from MindscapeHQ/Refactoring
Browse files Browse the repository at this point in the history
Version 2.0.0
  • Loading branch information
QuantumNightmare committed Feb 3, 2014
2 parents 6c06191 + 2def040 commit 3b44a60
Show file tree
Hide file tree
Showing 86 changed files with 4,880 additions and 2,026 deletions.
4 changes: 2 additions & 2 deletions AssemblyVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
// 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.1.11.0")]
[assembly: AssemblyFileVersion("1.1.11.0")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
16 changes: 10 additions & 6 deletions Mindscape.Raygun4Net.Tests/Mindscape.Raygun4Net.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
<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.Core" />
Expand All @@ -44,21 +45,24 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Model\FakeRaygunClient.cs" />
<Compile Include="Model\WrapperException.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RaygunClientJsonTests.cs" />
<Compile Include="RaygunClientTests.cs" />
<Compile Include="RaygunErrorMessageExceptionTests.cs" />
<Compile Include="RaygunErrorMessageInnerExceptionTests.cs" />
<Compile Include="RaygunMessageBuilderTests.cs" />
<Compile Include="RaygunRequestMessageTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mindscape.Raygun4Net\Mindscape.Raygun4Net.csproj">
<Project>{495E53B3-F3AF-4C4F-BAAF-865EFAA2F4A9}</Project>
<Name>Mindscape.Raygun4Net</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.
Expand Down
30 changes: 30 additions & 0 deletions Mindscape.Raygun4Net.Tests/Model/FakeRaygunClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
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 CreateMessage(Exception exception, [Optional] IList<string> tags, [Optional] IDictionary userCustomData)
{
return BuildMessage(exception, tags, userCustomData);
}

public bool Validate()
{
return ValidateApiKey();
}
}
}
15 changes: 15 additions & 0 deletions Mindscape.Raygun4Net.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)
{
}
}
}
4 changes: 2 additions & 2 deletions Mindscape.Raygun4Net.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
[assembly: AssemblyTitle("Mindscape.Raygun4Net.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Mindscape")]
[assembly: AssemblyProduct("Mindscape.Raygun4Net.Tests")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyCopyright("Copyright © Mindscape 2012-2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
24 changes: 0 additions & 24 deletions Mindscape.Raygun4Net.Tests/RaygunClientJsonTests.cs

This file was deleted.

183 changes: 183 additions & 0 deletions Mindscape.Raygun4Net.Tests/RaygunClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using Mindscape.Raygun4Net.Messages;
using NUnit.Framework;

namespace Mindscape.Raygun4Net.Tests
{
[TestFixture]
public class RaygunClientTests
{
private FakeRaygunClient _client;
private Exception _exception = new NullReferenceException("The thing is null");

[SetUp]
public void SetUp()
{
_client = new FakeRaygunClient();
}

// User tests

[Test]
public void DefaultUser()
{
Assert.IsNull(_client.User);
}

[Test]
public void UserProperty()
{
_client.User = "Robbie Robot";
Assert.AreEqual("Robbie Robot", _client.User);
}

[Test]
public void MessageWithUser()
{
_client.User = "Robbie Robot";

RaygunMessage message = _client.CreateMessage(_exception);
Assert.AreEqual("Robbie Robot", message.Details.User.Identifier);
}

// Application version tests

[Test]
public void DefaultApplicationVersion()
{
Assert.IsNull(_client.ApplicationVersion);
}

[Test]
public void ApplicationVersionProperty()
{
_client.ApplicationVersion = "Custom Version";
Assert.AreEqual("Custom Version", _client.ApplicationVersion);
}

[Test]
public void SetCustomApplicationVersion()
{
_client.ApplicationVersion = "Custom Version";

RaygunMessage message = _client.CreateMessage(_exception);
Assert.AreEqual("Custom Version", message.Details.Version);
}

// Exception stripping tests

[Test]
public void StripTargetInvocationExceptionByDefault()
{
TargetInvocationException wrapper = new TargetInvocationException(_exception);

RaygunMessage message = _client.CreateMessage(wrapper);
Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
}

[Test]
public void StripHttpUnhandledExceptionByDefault()
{
HttpUnhandledException wrapper = new HttpUnhandledException("Something went wrong", _exception);

RaygunMessage message = _client.CreateMessage(wrapper);
Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
}

[Test]
public void StripSpecifiedWrapperException()
{
_client.AddWrapperExceptions(new Type[] { typeof(WrapperException) });

WrapperException wrapper = new WrapperException(_exception);

RaygunMessage message = _client.CreateMessage(wrapper);
Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
}

[Test]
public void DontStripIfNoInnerException()
{
HttpUnhandledException wrapper = new HttpUnhandledException();

RaygunMessage message = _client.CreateMessage(wrapper);
Assert.AreEqual("System.Web.HttpUnhandledException", message.Details.Error.ClassName);
Assert.IsNull(message.Details.Error.InnerError);
}

[Test]
public void StripMultipleWrapperExceptions()
{
HttpUnhandledException wrapper = new HttpUnhandledException("Something went wrong", _exception);
TargetInvocationException wrapper2 = new TargetInvocationException(wrapper);

RaygunMessage message = _client.CreateMessage(wrapper2);
Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
}

// Validation tests

[Test]
public void NoAPIKeyIsInvalid()
{
Assert.IsFalse(_client.Validate());
}

[Test]
public void APIKeyIsValid()
{
FakeRaygunClient client = new FakeRaygunClient("MY_API_KEY");
Assert.IsTrue(client.Validate());
}

// Tags and user custom data tests

[Test]
public void TagsAreNullByDefault()
{
RaygunMessage message = _client.CreateMessage(_exception);
Assert.IsNull(message.Details.Tags);
}

[Test]
public void Tags()
{
IList<string> tags = new List<string>();
tags.Add("Very Important");
tags.Add("WPF");

RaygunMessage message = _client.CreateMessage(_exception, tags);
Assert.IsNotNull(message.Details.Tags);
Assert.AreEqual(2, message.Details.Tags.Count);
Assert.Contains("Very Important", (ICollection)message.Details.Tags);
Assert.Contains("WPF", (ICollection)message.Details.Tags);
}

[Test]
public void UserCustomDataIsNullByDefault()
{
RaygunMessage message = _client.CreateMessage(_exception);
Assert.IsNull(message.Details.UserCustomData);
}

[Test]
public void UserCustomData()
{
IDictionary data = new Dictionary<string, string>();
data.Add("x", "42");
data.Add("obj", "NULL");

RaygunMessage message = _client.CreateMessage(_exception, null, data);
Assert.IsNotNull(message.Details.UserCustomData);
Assert.AreEqual(2, message.Details.UserCustomData.Count);
Assert.AreEqual("42", message.Details.UserCustomData["x"]);
Assert.AreEqual("NULL", message.Details.UserCustomData["obj"]);
}
}
}
Loading

0 comments on commit 3b44a60

Please sign in to comment.