Created
March 25, 2014 14:39
-
-
Save rarous/9763165 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Xml.Linq; | |
using NSubstitute; | |
using Xunit; | |
namespace MultiConnector.Connectors | |
{ | |
public class WebConnectorTests | |
{ | |
[Fact] | |
public void ShouldReturnTimeoutWhenRequestTimeout() | |
{ | |
var connector = new TimeoutConnector(); | |
Assert.IsType<Timeout>(connector.Process(null)); | |
} | |
[Fact] | |
public void ShouldReturnFaultWhenExceptionThrown() | |
{ | |
var connector = new FaultedConnector(); | |
Assert.IsType<Fault>(connector.Process(null)); | |
} | |
[Fact] | |
public void ShouldReturnResult() | |
{ | |
var downloader = Substitute.For<IContentDownloader>(); | |
var connector = new Connector { Downloader = downloader }; | |
Assert.IsType<Response>(connector.Process(null)); | |
} | |
public class Connector : WebConnectorBase<string> | |
{ | |
protected override IEnumerable<string> CreateRequestUris(XElement requestXml) | |
{ | |
return new string[0]; | |
} | |
protected override IEnumerable<string> Parse(string text) | |
{ | |
return new string[0]; | |
} | |
protected override XElement TransformResult(IEnumerable<string> items) | |
{ | |
return TestData.CreateTestXml(); | |
} | |
} | |
class TimeoutConnector : WebConnectorBase<string> | |
{ | |
protected override IEnumerable<string> CreateRequestUris(XElement requestXml) | |
{ | |
throw new TimeoutException(); | |
} | |
protected override IEnumerable<string> Parse(string text) | |
{ | |
throw new TimeoutException(); | |
} | |
protected override XElement TransformResult(IEnumerable<string> items) | |
{ | |
throw new TimeoutException(); | |
} | |
} | |
class FaultedConnector : WebConnectorBase<string> | |
{ | |
protected override IEnumerable<string> CreateRequestUris(XElement requestXml) | |
{ | |
throw new NotImplementedException(); | |
} | |
protected override IEnumerable<string> Parse(string text) | |
{ | |
throw new NotImplementedException(); | |
} | |
protected override XElement TransformResult(IEnumerable<string> items) | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment