PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/sipsorcery-core/Tests/SIPSorcery.AppServer.DialPlan.UnitTests/DialPlanSettingsUnitTest.cs

https://github.com/thecc4re/sipsorcery-mono
C# | 99 lines | 80 code | 19 blank | 0 comment | 1 complexity | cb599c7b97210383e96c79073fd4f1b4 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. using SIPSorcery.AppServer.DialPlan;
  7. using SIPSorcery.SIP.App.Entities;
  8. namespace SIPSorcery.AppServer.DialPlan.UnitTests
  9. {
  10. [TestClass]
  11. public class DialPlanSettingsUnitTest
  12. {
  13. public DialPlanSettingsUnitTest()
  14. { }
  15. private TestContext testContextInstance;
  16. public TestContext TestContext
  17. {
  18. get
  19. {
  20. return testContextInstance;
  21. }
  22. set
  23. {
  24. testContextInstance = value;
  25. }
  26. }
  27. [TestMethod]
  28. public void ExtractENUMServersTest()
  29. {
  30. SIPDialplanOption options = new SIPDialplanOption()
  31. {
  32. enumservers = "e164.org\r\n\r\ne164.info\r\n\r\ne164.arpa\r\n\r\ne164.televolution.net\r\n\r\nenum.org\r\n\r\n"
  33. };
  34. DialPlanSettings settings = new DialPlanSettings(null, null, null, options);
  35. List<string> enumServersList = settings.GetENUMServers();
  36. Assert.AreEqual(5, enumServersList.Count, "The number of ENUM servers extracted from the list was incorrect.");
  37. Assert.AreEqual("e164.org", enumServersList[0], "The ENUM server at index 0 was not extracted correctly.");
  38. Assert.AreEqual("enum.org", enumServersList[4], "The ENUM server at index 4 was not extracted correctly.");
  39. }
  40. [TestMethod]
  41. public void ExtractExcludedPrefixesTest()
  42. {
  43. SIPDialplanOption options = new SIPDialplanOption()
  44. {
  45. excludedprefixes = " 1 (900 | 809)\r\n\r\n 1 \\d\\d\\d 555 1212\r\n\r\n44 (9 | 55 | 70 | 84 | 87)"
  46. };
  47. DialPlanSettings settings = new DialPlanSettings(null, null, null, options);
  48. List<string> excludedPrefixesList = settings.GetExcludedPrefixes();
  49. Assert.AreEqual(3, excludedPrefixesList.Count, "The number of excluded prefixes extracted from the list was incorrect.");
  50. Assert.AreEqual(" 1 (900 | 809)", excludedPrefixesList[0], "The excluded prefixes at index 0 was not extracted correctly.");
  51. Assert.AreEqual(" 1 \\d\\d\\d 555 1212", excludedPrefixesList[1], "The excluded prefixes at index 1 was not extracted correctly.");
  52. Assert.AreEqual("44 (9 | 55 | 70 | 84 | 87)", excludedPrefixesList[2], "The excluded prefixes at index 2 was not extracted correctly.");
  53. }
  54. [TestMethod]
  55. public void ExtractTimezoneOffsetTest()
  56. {
  57. SIPDialplanOption options = new SIPDialplanOption()
  58. {
  59. timezone = "(UTC+10:00) Hobart"
  60. };
  61. DialPlanSettings settings = new DialPlanSettings(null, null, null, options);
  62. int timezoneOffset = settings.GetTimezoneOffset();
  63. Assert.IsTrue(timezoneOffset >= 600 && timezoneOffset <= 660, "The timezone offset extracted was incorrect.");
  64. }
  65. [TestMethod]
  66. public void ExtractAllowedCountriesTest()
  67. {
  68. SIPDialplanOption options = new SIPDialplanOption()
  69. {
  70. allowedcountrycodes = "1 33 36 37[0-2] 380 39 41 420 44 49 61 7 86 883 886 90 972 998"
  71. };
  72. DialPlanSettings settings = new DialPlanSettings(null, null, null, options);
  73. List<string> allowedCountriesList = settings.GetAllowedCountries();
  74. Assert.AreEqual(18, allowedCountriesList.Count, "The number of allowed countries extracted from the list was incorrect.");
  75. Assert.AreEqual("1", allowedCountriesList[0], "The allowed countries at index 0 was not extracted correctly.");
  76. Assert.AreEqual("37[0-2]", allowedCountriesList[3], "The allowed countries at index 3 was not extracted correctly.");
  77. Assert.AreEqual("998", allowedCountriesList[17], "The allowed countries at index `7 was not extracted correctly.");
  78. }
  79. }
  80. }