-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a check for a connection terminated by server (#21)
- Loading branch information
Showing
6 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.IO; | ||
using System.Xml; | ||
using SharpXMPP.XMPP; | ||
|
||
namespace SharpXMPP.NUnit.TestUtils | ||
{ | ||
public class MockedXmppTcpConnection : XmppTcpConnection | ||
{ | ||
public MockedXmppTcpConnection(Stream stream) : base("", new JID(), "") | ||
{ | ||
Reader = XmlReader.Create(stream); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.IO; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using SharpXMPP.Errors; | ||
using SharpXMPP.NUnit.TestUtils; | ||
|
||
namespace SharpXMPP.NUnit | ||
{ | ||
[TestFixture] | ||
public class XmppTcpConnectionTests | ||
{ | ||
private const string EmptyXmppStream = @"<?xml version='1.0'?> | ||
<stream:stream from='example.com' | ||
id='someid' | ||
xmlns='jabber:client' | ||
xmlns:stream='http://etherx.jabber.org/streams' | ||
version='1.0'> | ||
</stream:stream>"; | ||
|
||
[Test] | ||
public void ConnectionShouldStopAfterStreamClosed() | ||
{ | ||
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(EmptyXmppStream))) | ||
using (var connection = new MockedXmppTcpConnection(stream)) | ||
{ | ||
Assert.Throws<XmppConnectionTerminatedException>(() => connection.NextElement()); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace SharpXMPP.Errors | ||
{ | ||
public class XmppConnectionTerminatedException : Exception | ||
{ | ||
public override string Message => "XMPP connection was terminated by server"; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("SharpXMPP.NUnit")] |
This file contains 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
This file contains 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