/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
- /***************************************************************************
- Copyright (C) 2010 RapidWebDev Organization (Author: Eunge, Legal Name: Jian Liu, Email: eunge.liu@gmail.com)
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- ***************************************************************************/
-
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Data.Linq;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Transactions;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Xml;
- using System.Xml.Schema;
- using BaoJianSoft.Common;
- using BaoJianSoft.Mailing.DataModel;
- using BaoJianSoft.Mailing.Interfaces;
- using BaoJianSoft.Mailing.Objects;
- using BaoJianSoft.Platform;
- using BaoJianSoft.Platform.Linq;
- using BaoJianSoft.Web.Extensions;
- using BaoJianSoft.Web.Extensions.DynamicPages;
- using BaoJianSoft.Web.Extensions.Controls;
- using NUnit.Framework;
-
- namespace BaoJianSoft.Tests.Mailing
- {
- public class MessageServiceTestBase
- {
- /// <summary>
- /// Gets AuthenticationContext instance
- /// </summary>
- protected IAuthenticationContext AuthenticationContext { get { return SpringContext.Current.GetObject<IAuthenticationContext>(); } }
-
- /// <summary>
- /// Gets MessageOutService instance.
- /// </summary>
- protected IMessageWriterService MessageWriterService { get { return SpringContext.Current.GetObject<IMessageWriterService>(); } }
-
- /// <summary>
- /// Gets MessageInService instance.
- /// </summary>
- protected IMessageReaderService MessageReaderService { get { return SpringContext.Current.GetObject<IMessageReaderService>(); } }
-
- /// <summary>
- /// Gets MessageTagService instance.
- /// </summary>
- protected IMessageTagService MessageTagService { get { return SpringContext.Current.GetObject<IMessageTagService>(); } }
-
- /// <summary>
- /// Gets "System Notice" as global tag.
- /// </summary>
- protected MessageTagElement MessageTag_SystemNotice { get; private set; }
-
- /// <summary>
- /// Gets "My Friends" as private tag of Admin
- /// </summary>
- protected MessageTagElement MessageTag_MyFriends { get; private set; }
-
- /// <summary>
- /// Gets generated message id collection which includes the messages have to be removed when tests tear down.
- /// </summary>
- protected List<Guid> GeneratedMessageIds { get; private set; }
-
- /// <summary>
- /// Constructor
- /// </summary>
- public MessageServiceTestBase()
- {
- this.GeneratedMessageIds = new List<Guid>();
- }
-
- [SetUp]
- public void LocalSetup()
- {
- AuthenticationContext.Login(SetupFixture.User_Admin.UserName, "password1");
-
- MessageTag_SystemNotice = new MessageTagElement()
- {
- IsGlobal = true,
- Name = "系统公告"
- };
-
- MessageTag_MyFriends = new MessageTagElement()
- {
- UserId = AuthenticationContext.User.UserId,
- Name = "朋友"
- };
-
- MessageTagService.Create(MessageTag_SystemNotice);
- MessageTagService.Create(MessageTag_MyFriends);
- }
-
- [TearDown]
- public void LocalUninstall()
- {
- MessageTagService.Delete(MessageTag_SystemNotice.MessageTagId.Value);
- MessageTagService.Delete(MessageTag_MyFriends.MessageTagId.Value);
-
- using (MessagingDataContext ctx = DataContextFactory.Create<MessagingDataContext>())
- {
- foreach (Guid messageId in GeneratedMessageIds)
- {
- ctx.MessageReceiptUsers.Delete(x => x.MessageId == messageId);
- ctx.MessageReceiptObjects.Delete(x => x.MessageId == messageId);
- ctx.MessageInTags.Delete(x => x.MessageId == messageId);
- ctx.MessageStatus.Delete(x => x.MessageId == messageId);
- ctx.Messages.Delete(x => x.MessageId == messageId);
- }
-
- ctx.SubmitChanges();
- GeneratedMessageIds.Clear();
- }
- }
- }
- }