SignalingSettingsTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Linq;
  3. using NUnit.Framework;
  4. using Unity.RenderStreaming.Signaling;
  5. namespace Unity.RenderStreaming.RuntimeTest
  6. {
  7. class IceServerTest
  8. {
  9. [Test]
  10. public void Clone()
  11. {
  12. var iceServer = new IceServer(
  13. urls: new[]{"stun:stun.l.google.com:19302"},
  14. username:"username",
  15. credentialType:IceCredentialType.Password,
  16. credential:"password");
  17. var copied = iceServer.Clone();
  18. Assert.That(copied.urls, Is.EqualTo(iceServer.urls));
  19. Assert.That(copied.username, Is.EqualTo(iceServer.username));
  20. Assert.That(copied.credentialType, Is.EqualTo(iceServer.credentialType));
  21. Assert.That(copied.credential, Is.EqualTo(iceServer.credential));
  22. copied = iceServer.Clone(
  23. username: "username2",
  24. credential: "password2");
  25. Assert.That(copied.urls, Is.EqualTo(iceServer.urls));
  26. Assert.That(copied.username, Is.Not.EqualTo(iceServer.username));
  27. Assert.That(copied.credentialType, Is.EqualTo(iceServer.credentialType));
  28. Assert.That(copied.credential, Is.Not.EqualTo(iceServer.credential));
  29. }
  30. }
  31. class SignalingSettingsTest
  32. {
  33. [Test]
  34. public void WebSocketSignalingSettings()
  35. {
  36. var settings = new WebSocketSignalingSettings();
  37. Assert.That(settings.signalingClass, Is.EqualTo(typeof(WebSocketSignaling)));
  38. Assert.That(settings.url, Is.Not.Empty);
  39. Assert.That(settings.iceServers, Is.Not.Empty);
  40. Assert.That(() => new WebSocketSignalingSettings(url: null), Throws.Exception.TypeOf<ArgumentNullException>());
  41. var url = "ws://localhost";
  42. settings = new WebSocketSignalingSettings(url:url);
  43. Assert.That(settings.url, Is.EqualTo(url));
  44. Assert.That(settings.iceServers, Is.Empty);
  45. var iceUrl = "stun:stun.l.google.com:19302";
  46. var iceServers = new[] { new IceServer(urls: new[] { iceUrl }) };
  47. settings = new WebSocketSignalingSettings(url: url, iceServers:iceServers);
  48. Assert.That(settings.iceServers.Count, Is.EqualTo(1));
  49. Assert.That(settings.iceServers.ElementAt(0).username, Is.Null);
  50. Assert.That(settings.iceServers.ElementAt(0).credential, Is.Null);
  51. Assert.That(settings.iceServers.ElementAt(0).credentialType, Is.EqualTo(IceCredentialType.Password));
  52. Assert.That(settings.iceServers.ElementAt(0).urls.Count, Is.EqualTo(1));
  53. Assert.That(settings.iceServers.ElementAt(0).urls.ElementAt(0), Is.EqualTo(iceUrl));
  54. }
  55. [Test]
  56. public void HttpSignalingSettings()
  57. {
  58. var settings = new HttpSignalingSettings();
  59. Assert.That(settings.signalingClass, Is.EqualTo(typeof(HttpSignaling)));
  60. Assert.That(settings.url, Is.Not.Empty);
  61. Assert.That(settings.iceServers, Is.Not.Empty);
  62. Assert.That(() => new HttpSignalingSettings(url: null), Throws.Exception.TypeOf<ArgumentNullException>());
  63. var url = "http://localhost";
  64. settings = new HttpSignalingSettings(url: url);
  65. Assert.That(settings.url, Is.EqualTo(url));
  66. Assert.That(settings.iceServers, Is.Empty);
  67. }
  68. [Test]
  69. public void FurioosSignalingSettings()
  70. {
  71. var settings = new FurioosSignalingSettings();
  72. Assert.That(settings.signalingClass, Is.EqualTo(typeof(FurioosSignaling)));
  73. Assert.That(settings.url, Is.Not.Empty);
  74. Assert.That(settings.iceServers, Is.Not.Empty);
  75. Assert.That(() => new HttpSignalingSettings(url: null), Throws.Exception.TypeOf<ArgumentNullException>());
  76. var url = "http://localhost";
  77. settings = new FurioosSignalingSettings(url: url);
  78. Assert.That(settings.url, Is.EqualTo(url));
  79. Assert.That(settings.iceServers, Is.Empty);
  80. }
  81. }
  82. }