PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/connectors/cs/src/unittests/core/util/FreeBusyUrlTest.cs

http://google-calendar-connectors.googlecode.com/
C# | 92 lines | 63 code | 15 blank | 14 comment | 0 complexity | b3dc4a508fb679aeb9cc758a3ef16c15 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /* Copyright (c) 2008 Google Inc. All Rights Reserved
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Diagnostics;
  18. using System.DirectoryServices;
  19. using System.IO;
  20. using System.Net;
  21. using System.Text;
  22. using System.Xml;
  23. using System.Xml.XPath;
  24. using System.Reflection;
  25. using NUnit.Framework;
  26. using Google.GCalExchangeSync.Library;
  27. namespace Google.GCalExchangeSync.Library.Util
  28. {
  29. [TestFixture]
  30. public class FreeBusyUrlTest
  31. {
  32. private static readonly string ExchangeServer = "http://example.org";
  33. private static readonly string Organization = "Dev Project 1 Organization/";
  34. private static readonly string OrgUnit = "Administrative Group";
  35. private static readonly string LegacyDN = "/o=Microsoft/ou=APPS-ABC/cn=FOLDER/cn=ASAMPLE";
  36. private static readonly string AdminGroup = "Group";
  37. private static readonly string FreeBusyTestUrl =
  38. "http://example.org/public/NON_IPM_SUBTREE/SCHEDULE%2B%20FREE%20BUSY/EX:Dev%20Project%201%20Organization_xF8FF_/USER-_xF8FF_cn=RECIPIENTS_xF8FF_cn=Administrative%20Group.EML";
  39. private static readonly string FreeBusyFromDNUrl =
  40. "http://example.org/public/NON_IPM_SUBTREE/SCHEDULE%2B%20FREE%20BUSY/EX:_xF8FF_o=Microsoft_xF8FF_ou=APPS-ABC/USER-_xF8FF_cn=FOLDER_xF8FF_cn=ASAMPLE.EML";
  41. private static readonly string AdminGroupUrl =
  42. "http://example.org/public/NON_IPM_SUBTREE/SCHEDULE%2B%20FREE%20BUSY/EX:Group/";
  43. private static readonly string SingleUserFreeBusyUrl =
  44. "http://example.org/public/?cmd=freebusy&start=2007-06-30T05:16:11Z&end=2007-06-30T08:16:11Z&interval=15&u=user1@example.org";
  45. private static readonly string MultiUserFreeBusyUrl =
  46. "http://example.org/public/?cmd=freebusy&start=2007-06-30T05:16:11Z&end=2007-06-30T08:16:11Z&interval=15&u=user1@example.org&u=user2@example.org";
  47. private static readonly string User1Email = "user1@example.org";
  48. private static readonly string User2Email = "user2@example.org";
  49. private static readonly DateTime start = DateUtil.ParseDateToUtc("2007-06-30T05:16:11.000Z");
  50. private static readonly DateTime end = DateUtil.ParseDateToUtc("2007-06-30T08:16:11.000Z");
  51. [SetUp]
  52. public void Init()
  53. {
  54. }
  55. private ExchangeUser createFauxUser(string name, string email)
  56. {
  57. ExchangeUser result = new ExchangeUser();
  58. result.Email = email;
  59. result.MailNickname = name;
  60. result.LegacyExchangeDN = "/o=Microsoft/ou=APPS-ABC/cn=RECIPIENTS/cn=ASAMPLE";
  61. return result;
  62. }
  63. [Test]
  64. public void FreeBusyUrls()
  65. {
  66. Assert.AreEqual(FreeBusyTestUrl, FreeBusyUrl.GenerateUrl(ExchangeServer, Organization, OrgUnit));
  67. Assert.AreEqual(FreeBusyFromDNUrl, FreeBusyUrl.GenerateUrlFromDN(ExchangeServer, LegacyDN));
  68. Assert.AreEqual(AdminGroupUrl, FreeBusyUrl.GenerateAdminGroupUrl(ExchangeServer, AdminGroup));
  69. ExchangeUserDict users = new ExchangeUserDict();
  70. users.Add(User1Email, createFauxUser("User1", User1Email));
  71. DateTimeRange range = new DateTimeRange(start, end);
  72. Assert.AreEqual(SingleUserFreeBusyUrl, FreeBusyUrl.GenerateFreeBusyLookupUrl(ExchangeServer, users, range, 15));
  73. users.Add(User2Email, createFauxUser("User2", User2Email));
  74. Assert.AreEqual(MultiUserFreeBusyUrl, FreeBusyUrl.GenerateFreeBusyLookupUrl(ExchangeServer, users, range, 15));
  75. }
  76. }
  77. }