Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Finish test-refactoring
Browse files Browse the repository at this point in the history
* feature/test-refactoring:
  Wrap async in !net40 regions
  Adjusted namespace and removed the RavenClient prefix of the RavenClient test classes
  Moved RavenClient tests into a RavenClientTests folder
  Added CaptureException tests
  Tidied up async tests
  Added Capture tests
  Added CaptureAsync() tests
  Merge tags in Capture(SentryEvent)
  Fixed InvokesSendAndJsonPacketFactoryOnCreate async test
  Set LastPacket in async as well
  Add CaptureMessageAsync tests
  Rename RavenClientTests to RavenClientTester
  • Loading branch information
asbjornu committed Mar 17, 2016
2 parents 9db2734 + 1ccd9eb commit fba43d2
Show file tree
Hide file tree
Showing 9 changed files with 920 additions and 97 deletions.
5 changes: 3 additions & 2 deletions src/app/SharpRaven/RavenClient.Net45.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public partial class RavenClient
/// </returns>
public async Task<string> CaptureAsync(SentryEvent @event)
{
@event.Tags = MergeTags(@event.Tags);
var packet = this.jsonPacketFactory.Create(CurrentDsn.ProjectID, @event);
return await SendAsync(packet);
}
Expand Down Expand Up @@ -85,7 +86,7 @@ public async Task<string> CaptureExceptionAsync(Exception exception,
Message = message,
Level = level,
Extra = extra,
Tags = MergeTags(tags),
Tags = tags,
Fingerprint = fingerprint
};

Expand Down Expand Up @@ -115,7 +116,7 @@ public async Task<string> CaptureMessageAsync(SentryMessage message,
{
Level = level,
Extra = extra,
Tags = MergeTags(tags),
Tags = tags,
Fingerprint = fingerprint
};

Expand Down
148 changes: 148 additions & 0 deletions src/tests/SharpRaven.UnitTests/RavenClientTests/CaptureAsyncTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#region License

// Copyright (c) 2014 The Sentry Team and individual contributors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// 3. Neither the name of the Sentry nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#endregion

#if (!net40)

using System;
using System.Threading.Tasks;

using NUnit.Framework;

using SharpRaven.Data;

namespace SharpRaven.UnitTests.RavenClientTests
{
[TestFixture]
public class CaptureAsyncTests
{
#region SetUp/Teardown

[SetUp]
public void SetUp()
{
this.tester = new RavenClientTester();
}

#endregion

[Test]
public void ClientEnvironmentIsIgnored()
{
this.tester.ClientEnvironmentIsIgnored(client => client.CaptureAsync(new SentryEvent("Test")));
}


[Test]
public void ClientLoggerIsIgnored()
{
this.tester.ClientLoggerIsIgnored(async client => await client.CaptureAsync(new SentryEvent("Test")));
}


[Test]
public void ClientReleaseIsIgnored()
{
this.tester.ClientReleaseIsIgnored(async client => await client.CaptureAsync(new SentryEvent("Test")));
}


[Test]
public async Task InvokesSendAndJsonPacketFactoryOnCreate()
{
var project = Guid.NewGuid().ToString();
var client = this.tester.GetTestableRavenClient(project);
var result = await client.CaptureAsync(new SentryEvent("Test"));

Assert.That(result, Is.EqualTo(project));
}


[Test]
public void OnlyDefaultTags()
{
this.tester.OnlyDefaultTags(async client => await client.CaptureAsync(new SentryEvent("Test")));
}


[Test]
public void OnlyMessageTags()
{
this.tester.OnlyMessageTags(async (client, tags) => await client.CaptureAsync(new SentryEvent("Test")
{
Level = ErrorLevel.Info,
Tags = tags
}));
}


[Test]
public void ScrubberIsInvoked()
{
this.tester.ScrubberIsInvoked(async (client, message) => await client.CaptureAsync(new SentryEvent(message)));
}


[Test]
public void SendsEnvironment()
{
this.tester.SendsEnvironment(async client => await client.CaptureAsync(new SentryEvent("Test")));
}


[Test]
public void SendsLogger()
{
this.tester.SendsLogger(async client => await client.CaptureAsync(new SentryEvent("Test")));
}


[Test]
public void SendsRelease()
{
this.tester.SendsRelease(async client => await client.CaptureAsync(new SentryEvent("Test")));
}


[Test]
public void TagHandling()
{
this.tester.TagHandling(async (client, tags) => await client.CaptureAsync(new SentryEvent("Test")
{
Level = ErrorLevel.Info,
Tags = tags
}));
}


private RavenClientTester tester;
}
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#region License

// Copyright (c) 2014 The Sentry Team and individual contributors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// 3. Neither the name of the Sentry nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#endregion

#if (!net40)

using System;
using System.Threading.Tasks;

using NUnit.Framework;

using SharpRaven.Data;

namespace SharpRaven.UnitTests.RavenClientTests
{
[TestFixture]
public class CaptureExceptionAsyncTests
{
#region SetUp/Teardown

[SetUp]
public void SetUp()
{
this.tester = new RavenClientTester();
}

#endregion

[Test]
public void ClientEnvironmentIsIgnored()
{
this.tester.ClientEnvironmentIsIgnored(async client => await client.CaptureExceptionAsync(new Exception("Test")));
}


[Test]
public void ClientLoggerIsIgnored()
{
this.tester.ClientLoggerIsIgnored(async client => await client.CaptureExceptionAsync(new Exception("Test")));
}


[Test]
public void ClientReleaseIsIgnored()
{
this.tester.ClientReleaseIsIgnored(async client => await client.CaptureExceptionAsync(new Exception("Test")));
}


[Test]
public async Task InvokesSendAndJsonPacketFactoryOnCreate()
{
var project = Guid.NewGuid().ToString();
var client = this.tester.GetTestableRavenClient(project);
var result = await client.CaptureExceptionAsync(new Exception("Test"));

Assert.That(result, Is.EqualTo(project));
}


[Test]
public void OnlyDefaultTags()
{
this.tester.OnlyDefaultTags(async client => await client.CaptureExceptionAsync(new Exception("Test")));
}


[Test]
public void OnlyMessageTags()
{
this.tester.OnlyMessageTags(
async (client, tags) => await client.CaptureExceptionAsync(new Exception("Test"), level : ErrorLevel.Info, tags : tags));
}


[Test]
public void ScrubberIsInvoked()
{
this.tester.ScrubberIsInvoked(async (client, message) => await client.CaptureExceptionAsync(new Exception(message)));
}


[Test]
public void SendsEnvironment()
{
this.tester.SendsEnvironment(async client => await client.CaptureExceptionAsync(new Exception("Test")));
}


[Test]
public void SendsLogger()
{
this.tester.SendsLogger(async client => await client.CaptureExceptionAsync(new Exception("Test")));
}


[Test]
public void SendsRelease()
{
this.tester.SendsRelease(async client => await client.CaptureExceptionAsync(new Exception("Test")));
}


[Test]
public void TagHandling()
{
this.tester.TagHandling(
async (client, tags) => await client.CaptureExceptionAsync(new Exception("Test"), level : ErrorLevel.Info, tags : tags));
}


private RavenClientTester tester;
}
}

#endif
Loading

0 comments on commit fba43d2

Please sign in to comment.