/tags/1.31/src/Tests/Platform/SiteMapApiTests.cs
C# | 144 lines | 103 code | 21 blank | 20 comment | 0 complexity | 494d4b5ef3ed3f171bb26511d72e7993 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1
- /****************************************************************************************************
- Copyright (C) 2010 RapidWebDev Organization (http://rapidwebdev.org)
- Author: Eunge, Legal Name: Jian Liu, Email: eunge.liu@RapidWebDev.org
-
- 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 2 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.Common.Data;
- using BaoJianSoft.Platform;
- using BaoJianSoft.Platform.Initialization;
- using BaoJianSoft.Platform.Linq;
- using BaoJianSoft.RapidWeb;
- using BaoJianSoft.RapidWeb.Controls;
- using BaoJianSoft.RapidWeb.DynamicPages;
- using NUnit.Framework;
- using Rhino.Mocks;
- using BaoJianSoft.Common.Globalization;
-
- namespace BaoJianSoft.Tests.Platform
- {
- [TestFixture]
- public class SiteMapApiTests
- {
- private MockRepository mockRepository;
- private static IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();
- private static IAuthenticationContext authenticationContext = SpringContext.Current.GetObject<IAuthenticationContext>();
- private static IPlatformConfiguration platformConfiguration = SpringContext.Current.GetObject<IPlatformConfiguration>();
-
- private List<Guid> createdRoleIds = new List<Guid>();
- private List<Guid> createdUserIds = new List<Guid>();
- private List<Guid> createdOrganizationTypeIds = new List<Guid>();
-
- [SetUp]
- public void StartUp()
- {
- this.mockRepository = new MockRepository();
- }
-
- [TearDown]
- public void TearDown()
- {
- this.mockRepository.VerifyAll();
-
- string sessionKey = "FindSiteMapConfig_" + authenticationContext.User.UserId.ToString("N");
- authenticationContext.Session[sessionKey] = null;
- }
-
- [Test, Description("Test cases that get site map for administrators.")]
- public void SiteMapForAdministrators()
- {
- string siteMapFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../TestData/siteMap.config");
- IRoleApi roleApi = this.mockRepository.StrictMock<IRoleApi>();
- Expect.Call(roleApi.IsUserInRole(Guid.Empty, Guid.Empty)).IgnoreArguments().Return(true);
- SiteMapApi siteMapApi = new SiteMapApi(authenticationContext, roleApi, organizationApi, null, platformConfiguration, siteMapFilePath);
-
- this.mockRepository.ReplayAll();
-
- IEnumerable<SiteMapItemConfig> siteMapItems = siteMapApi.FindSiteMapConfig(authenticationContext.User.UserId);
- Assert.AreEqual(2, siteMapItems.Count());
-
- SiteMapItemConfig accountSiteMapItem = siteMapItems.First();
- string accountText = GlobalizationKit.ReplaceGlobalizationVariables("$Resources.SiteMap.Account, BaoJianSoft.Web$");
- Assert.AreEqual(accountText, accountSiteMapItem.Text);
- }
-
- [Test, Description("Test cases that get site map for non-administrators users having all permissions.")]
- public void SiteMapForNonAdministratorsWithAllPermissions()
- {
- string siteMapFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../TestData/siteMap.config");
- IRoleApi roleApi = this.mockRepository.StrictMock<IRoleApi>();
- Expect.Call(roleApi.IsUserInRole(Guid.Empty, Guid.Empty)).IgnoreArguments().Return(false);
-
- IPermissionApi permissionApi = this.mockRepository.StrictMock<IPermissionApi>();
-
- // there are 12 sitemap elements which have the attribute "Value".
- Expect.Call(permissionApi.HasPermission(Guid.Empty, null))
- .IgnoreArguments()
- .Return(true)
- .Repeat.Times(12);
-
- SiteMapApi siteMapApi = new SiteMapApi(authenticationContext, roleApi, organizationApi, permissionApi, platformConfiguration, siteMapFilePath);
- this.mockRepository.ReplayAll();
-
- IEnumerable<SiteMapItemConfig> siteMapItems = siteMapApi.FindSiteMapConfig(authenticationContext.User.UserId);
- Assert.AreEqual(2, siteMapItems.Count());
- }
-
- [Test, Description("Test cases that get site map for non-administrators users having partial permissions.")]
- public void SiteMapForNonAdministratorsWithPartialPermissions()
- {
- string siteMapFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../TestData/siteMap.config");
- IRoleApi roleApi = this.mockRepository.StrictMock<IRoleApi>();
- Expect.Call(roleApi.IsUserInRole(Guid.Empty, Guid.Empty)).IgnoreArguments().Return(false);
-
- IPermissionApi permissionApi = this.mockRepository.StrictMock<IPermissionApi>();
-
- Guid userId = authenticationContext.User.UserId;
- // there are 4 sitemap elements which have the attribute "Value" equals to "EveryOne".
- Expect.Call(permissionApi.HasPermission(userId, "EveryOne"))
- .Return(true)
- .Repeat.Times(4);
-
- // there are 8 sitemap elements which have the attribute "Value" not equals to "EveryOne".
- Expect.Call(permissionApi.HasPermission(userId, "OrganizationTypeManagement")).Return(false);
- Expect.Call(permissionApi.HasPermission(userId, "IncManagement")).Return(false);
- Expect.Call(permissionApi.HasPermission(userId, "CustomerManagement")).Return(false);
- Expect.Call(permissionApi.HasPermission(userId, "Inc.RoleManagement")).Return(false);
- Expect.Call(permissionApi.HasPermission(userId, "Customer.RoleManagement")).Return(false);
- Expect.Call(permissionApi.HasPermission(userId, "Inc.UserManagement")).Return(false);
- Expect.Call(permissionApi.HasPermission(userId, "Customer.UserManagement")).Return(false);
- Expect.Call(permissionApi.HasPermission(userId, "AreaManagement")).Return(false);
-
- SiteMapApi siteMapApi = new SiteMapApi(authenticationContext, roleApi, organizationApi, permissionApi, platformConfiguration, siteMapFilePath);
- this.mockRepository.ReplayAll();
-
- IEnumerable<SiteMapItemConfig> siteMapItems = siteMapApi.FindSiteMapConfig(userId);
- Assert.AreEqual(1, siteMapItems.Count());
- }
- }
- }