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

Commit

Permalink
Removed all rest sharp references
Browse files Browse the repository at this point in the history
  • Loading branch information
Workshop2 committed Feb 7, 2017
1 parent 7a8065f commit 3e162df
Show file tree
Hide file tree
Showing 21 changed files with 19 additions and 1,203 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,285 +1,35 @@
using System.Net;
using NUnit.Framework;
using RestSharp;
using NUnit.Framework;
using Should;
using SlackConnector.Connections.Clients;
using SlackConnector.Connections.Models;
using SlackConnector.Connections.Responses;
using SlackConnector.Exceptions;
using SpecsFor;
using SpecsFor.ShouldExtensions;

namespace SlackConnector.Tests.Unit.Connections.Clients
{
public static class ResponseVerifierTests
[TestFixture]
public class ResponseVerifierTests
{
internal class given_valid_response_then_should_return_expected_object : SpecsFor<ResponseVerifier>
[Test]
public void should_throw_exception_with_given_error_message_when_request_failed()
{
private IRestResponse restResponse;
private ExampleModel Result { get; set; }
// given
var response = new StandardResponse { Ok = false, Error = "I AM A ERROR-message" };
var verifier = new ResponseVerifier();

protected override void Given()
{
restResponse = new RestResponse
{
StatusCode = HttpStatusCode.OK,
Content = @"{'ok': true, 'value': 'test'}"
};
}

protected override void When()
{
Result = SUT.VerifyResponse<ExampleModel>(restResponse);
}

[Test]
public void then_should_return_expected_model()
{
var expected = new ExampleModel
{
Ok = true,
Value = "test"
};
Result.ShouldLookLike(expected);
}
}

internal class given_invalid_http_response_then_should_throw_exception : SpecsFor<ResponseVerifier>
{
private IRestResponse restResponse;

protected override void Given()
{
restResponse = new RestResponse
{
StatusCode = HttpStatusCode.BadRequest
};
}


[Test]
public void then_should_throw_expected_exception()
{
CommunicationException exception = null;

try
{
SUT.VerifyResponse<ExampleModel>(restResponse);
}
catch (CommunicationException ex)
{
exception = ex;
}

string expectedMessage = $"Error occured while sending message '{restResponse.StatusCode}'";
exception.ShouldNotBeNull();
exception.Message.ShouldEqual(expectedMessage);
}
// when && then
var exception = Assert.Throws<CommunicationException>(() => verifier.VerifyResponse(response));
exception.Message.ShouldEqual($"Error occured while posting message '{response.Error}'");
}

internal class given_error_in_response_json_then_should_throw_exception : SpecsFor<ResponseVerifier>
[Test]
public void should_not_throw_exception()
{
private IRestResponse restResponse;

protected override void Given()
{
restResponse = new RestResponse
{
StatusCode = HttpStatusCode.OK,
Content = @"{'ok': false, 'error': 'test error'}"
};
}


[Test]
public void then_should_throw_expected_exception()
{
CommunicationException exception = null;

try
{
SUT.VerifyResponse<ExampleModel>(restResponse);
}
catch (CommunicationException ex)
{
exception = ex;
}

exception.ShouldNotBeNull();
exception.Message.ShouldEqual("Error occured while posting message 'test error'");
}
}

internal class given_join_channel_response : SpecsFor<ResponseVerifier>
{
private IRestResponse _restResponse;
private JoinChannelResponse Result { get; set; }

protected override void Given()
{
_restResponse = new RestResponse
{
StatusCode = HttpStatusCode.OK,
Content = @"{
'ok':true,
'channel': {
'id': 'my-id',
'name': 'my-name',
}
}"
};
}

protected override void When()
{
Result = SUT.VerifyResponse<JoinChannelResponse>(_restResponse);
}

[Test]
public void should_return_expected_channel_response()
{
var expected = new JoinChannelResponse
{
Ok = true,
Error = null,
Channel = new Channel
{
Id = "my-id",
Name = "my-name"
}
};

Result.ShouldLookLike(expected);
}
}

internal class given_handshake_response : SpecsFor<ResponseVerifier>
{
private IRestResponse _restResponse;
private HandshakeResponse Result { get; set; }

protected override void Given()
{
_restResponse = new RestResponse
{
StatusCode = HttpStatusCode.OK,
Content = Resources.ResourceManager.GetHandShakeResponseJson()
};
}

protected override void When()
{
Result = SUT.VerifyResponse<HandshakeResponse>(_restResponse);
}

[Test]
public void should_return_expected_channel_response()
{
var expected = new HandshakeResponse
{
Ok = true,
Self = new Detail
{
Id = "self-id",
Name = "self-name"
},
Team = new Detail
{
Id = "team-id",
Name = "team-name"
},
Channels = new[]
{
new Channel
{
Id = "channel-id",
Name = "channel-name",
IsChannel = true,
IsArchived = true,
IsMember = true
}
},
Groups = new[]
{
new Group
{
Id = "group-id",
Name = "group-name",
IsGroup = true,
IsArchived = true,
IsOpen = true,
Members = new []
{
"member1"
}
}
},
Ims = new[]
{
new Im
{
Id = "im-id",
User = "im-user",
IsIm = true,
IsOpen = true
}
},
Users = new[]
{
new User
{
Id = "user-id",
Name = "user-name",
Deleted = true,
Profile = new Profile
{
FirstName = "first-name",
LastName = "last-name",
RealName = "real-name",
RealNameNormalised = "real-name-normalized",
Email = "email"
},
IsAdmin = true,
IsBot = true
}
},
WebSocketUrl = @"wss://ms331.slack-msgs.com/websocket/999"
};

Result.ShouldLookLike(expected);
}
}

private class ExampleModel : StandardResponse
{
public string Value { get; set; }
}

[TestFixture]
public class ResponseVerifierTests2
{
[Test]
public void should_throw_exception_with_given_error_message_when_request_failed()
{
// given
var response = new StandardResponse { Ok = false, Error = "I AM A ERROR-message" };
var verifier = new ResponseVerifier();

// when && then
var exception = Assert.Throws<CommunicationException>(() => verifier.VerifyResponse(response));
exception.Message.ShouldEqual($"Error occured while posting message '{response.Error}'");
}

[Test]
public void should_not_throw_exception()
{
// given
var response = new StandardResponse { Ok = true };
var verifier = new ResponseVerifier();
// given
var response = new StandardResponse { Ok = true };
var verifier = new ResponseVerifier();

// when && then
Assert.DoesNotThrow(() => verifier.VerifyResponse(response));
}
// when && then
Assert.DoesNotThrow(() => verifier.VerifyResponse(response));
}
}
}
Loading

0 comments on commit 3e162df

Please sign in to comment.