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

/tags/1.31/src/Tests/Mailing/MessageServiceTestBase.cs

#
C# | 131 lines | 75 code | 16 blank | 40 comment | 5 complexity | a4d8a08e7b1c397bb11c16c3320ba494 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1
  1. /***************************************************************************
  2. Copyright (C) 2010 RapidWebDev Organization (Author: Eunge, Legal Name: Jian Liu, Email: eunge.liu@gmail.com)
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ***************************************************************************/
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Collections.ObjectModel;
  17. using System.Data.Linq;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Transactions;
  22. using System.Web.UI;
  23. using System.Web.UI.WebControls;
  24. using System.Xml;
  25. using System.Xml.Schema;
  26. using BaoJianSoft.Common;
  27. using BaoJianSoft.Mailing.DataModel;
  28. using BaoJianSoft.Mailing.Interfaces;
  29. using BaoJianSoft.Mailing.Objects;
  30. using BaoJianSoft.Platform;
  31. using BaoJianSoft.Platform.Linq;
  32. using BaoJianSoft.Web.Extensions;
  33. using BaoJianSoft.Web.Extensions.DynamicPages;
  34. using BaoJianSoft.Web.Extensions.Controls;
  35. using NUnit.Framework;
  36. namespace BaoJianSoft.Tests.Mailing
  37. {
  38. public class MessageServiceTestBase
  39. {
  40. /// <summary>
  41. /// Gets AuthenticationContext instance
  42. /// </summary>
  43. protected IAuthenticationContext AuthenticationContext { get { return SpringContext.Current.GetObject<IAuthenticationContext>(); } }
  44. /// <summary>
  45. /// Gets MessageOutService instance.
  46. /// </summary>
  47. protected IMessageWriterService MessageWriterService { get { return SpringContext.Current.GetObject<IMessageWriterService>(); } }
  48. /// <summary>
  49. /// Gets MessageInService instance.
  50. /// </summary>
  51. protected IMessageReaderService MessageReaderService { get { return SpringContext.Current.GetObject<IMessageReaderService>(); } }
  52. /// <summary>
  53. /// Gets MessageTagService instance.
  54. /// </summary>
  55. protected IMessageTagService MessageTagService { get { return SpringContext.Current.GetObject<IMessageTagService>(); } }
  56. /// <summary>
  57. /// Gets "System Notice" as global tag.
  58. /// </summary>
  59. protected MessageTagElement MessageTag_SystemNotice { get; private set; }
  60. /// <summary>
  61. /// Gets "My Friends" as private tag of Admin
  62. /// </summary>
  63. protected MessageTagElement MessageTag_MyFriends { get; private set; }
  64. /// <summary>
  65. /// Gets generated message id collection which includes the messages have to be removed when tests tear down.
  66. /// </summary>
  67. protected List<Guid> GeneratedMessageIds { get; private set; }
  68. /// <summary>
  69. /// Constructor
  70. /// </summary>
  71. public MessageServiceTestBase()
  72. {
  73. this.GeneratedMessageIds = new List<Guid>();
  74. }
  75. [SetUp]
  76. public void LocalSetup()
  77. {
  78. AuthenticationContext.Login(SetupFixture.User_Admin.UserName, "password1");
  79. MessageTag_SystemNotice = new MessageTagElement()
  80. {
  81. IsGlobal = true,
  82. Name = "系统公告"
  83. };
  84. MessageTag_MyFriends = new MessageTagElement()
  85. {
  86. UserId = AuthenticationContext.User.UserId,
  87. Name = "朋友"
  88. };
  89. MessageTagService.Create(MessageTag_SystemNotice);
  90. MessageTagService.Create(MessageTag_MyFriends);
  91. }
  92. [TearDown]
  93. public void LocalUninstall()
  94. {
  95. MessageTagService.Delete(MessageTag_SystemNotice.MessageTagId.Value);
  96. MessageTagService.Delete(MessageTag_MyFriends.MessageTagId.Value);
  97. using (MessagingDataContext ctx = DataContextFactory.Create<MessagingDataContext>())
  98. {
  99. foreach (Guid messageId in GeneratedMessageIds)
  100. {
  101. ctx.MessageReceiptUsers.Delete(x => x.MessageId == messageId);
  102. ctx.MessageReceiptObjects.Delete(x => x.MessageId == messageId);
  103. ctx.MessageInTags.Delete(x => x.MessageId == messageId);
  104. ctx.MessageStatus.Delete(x => x.MessageId == messageId);
  105. ctx.Messages.Delete(x => x.MessageId == messageId);
  106. }
  107. ctx.SubmitChanges();
  108. GeneratedMessageIds.Clear();
  109. }
  110. }
  111. }
  112. }