Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
natX #1
Member since May 2014 · 2 posts
Group memberships: Members
Show profile · Link to this post
Subject: NUnit Test - socket exception
I'm trying to setup a simple Integration test to verify that we're receiving some expected messages. My code works fine from the UI but when I execute it from an NUnit test harness I get a SocketException "No connection could be made because the target machine actively refused it <ipaddress>:5222

  1. private XmppClient client;
  2.  
  3. [Test]
  4. public void when_()
  5. {
  6.     var are = new AutoResetEvent(false);
  7.  
  8.  
  9.     client = new XmppClient();
  10.     client.StartTls = false;
  11.     client.SetXmppDomain("dev1.internal.com");
  12.     client.SetResource("IMClient");
  13.  
  14.     client.OnLogin += (s, e) =>
  15.     {
  16.         are.Set();
  17.         Assert.Pass();
  18.     };
  19.  
  20.     client.OnError += (s, e) =>
  21.     {
  22.         are.Set();
  23.         Assert.Fail();
  24.     };
  25.  
  26.     client.SetUsername("username".EncryptSha1());
  27.     client.Password = "password";
  28.     client.Open();
  29.  
  30.     are.WaitOne(5000, false);
  31. }
This post was edited on 2014-05-13, 16:15 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
which NUnit GUI are you using?

I ran your test in the Resharper NUnit GUI without any problems.
One problem I see is the OnError event. This fires even after Assert.Pass() in the OnLogin event because you don't close the session properly. Which means it gets hard killed and causes and Xml Error which will also fire the OnError event. Maybe this is your problem.
To get rid of this eather close the session properly or unsubscribe to the OnError event when you get the OnLogin. Because your test is supposed to wait for the first of them you get.

Alex
Avatar
natX #3
Member since May 2014 · 2 posts
Group memberships: Members
Show profile · Link to this post
If you run it in the debugger can you get it to break on line 16?
Avatar
Alex #4
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
yes no problem here using the latest build.
The only change I made is adding a license key when the tests starts. And I changed the credentials to our live server.

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS