List:Commits« Previous MessageNext Message »
From:rburnett Date:August 1 2007 4:18am
Subject:Connector/NET commit: r834 - branches/5.1/MySql.Web/Tests
View as plain text  
Added:
   branches/5.1/MySql.Web/Tests/RoleManagement.cs
Modified:
   branches/5.1/MySql.Web/Tests/App.config
   branches/5.1/MySql.Web/Tests/MySql.Web.Tests.csproj
Log:
Added some new unit tests for the web providers

Modified: branches/5.1/MySql.Web/Tests/App.config
===================================================================
--- branches/5.1/MySql.Web/Tests/App.config	2007-07-30 22:48:40 UTC (rev 833)
+++ branches/5.1/MySql.Web/Tests/App.config	2007-08-01 02:18:32 UTC (rev 834)
@@ -9,7 +9,7 @@
       <providers>
         <remove name="MySQLMembershipProvider"/>
         <add name="MySQLMembershipProvider" 
-             type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web,
Version=5.1.2.2, Culture=neutral, PublicKeyToken=c5687fc88969c44d" 
+             type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=5.1.3,
Culture=neutral, PublicKeyToken=c5687fc88969c44d" 
              connectionStringName="LocalMySqlServer" enablePasswordRetrieval="false" 
              enablePasswordReset="true" requiresQuestionAndAnswer="true" 
              applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" 

Modified: branches/5.1/MySql.Web/Tests/MySql.Web.Tests.csproj
===================================================================
--- branches/5.1/MySql.Web/Tests/MySql.Web.Tests.csproj	2007-07-30 22:48:40 UTC (rev 833)
+++ branches/5.1/MySql.Web/Tests/MySql.Web.Tests.csproj	2007-08-01 02:18:32 UTC (rev 834)
@@ -37,6 +37,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="BaseTest.cs" />
+    <Compile Include="RoleManagement.cs" />
     <Compile Include="SchemaTests.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="UserManagement.cs" />

Added: branches/5.1/MySql.Web/Tests/RoleManagement.cs
===================================================================
--- branches/5.1/MySql.Web/Tests/RoleManagement.cs	2007-07-30 22:48:40 UTC (rev 833)
+++ branches/5.1/MySql.Web/Tests/RoleManagement.cs	2007-08-01 02:18:32 UTC (rev 834)
@@ -0,0 +1,100 @@
+// Copyright (C) 2007 MySQL AB
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation
+//
+// There are special exceptions to the terms and conditions of the GPL 
+// as it is applied to this software. View the full text of the 
+// exception in file EXCEPTIONS in the directory of this software 
+// distribution.
+//
+// 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, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+
+//  This code was contributed by Sean Wright (srwright@stripped) on 2007-01-12
+//  The copyright was assigned and transferred under the terms of
+//  the MySQL Contributor License Agreement (CLA)
+
+using NUnit.Framework;
+using System.Web.Security;
+using System.Collections.Specialized;
+using System.Data;
+using System;
+using System.Configuration.Provider;
+
+namespace MySql.Web.Security.Tests
+{
+    [TestFixture]
+    public class RoleManagement : BaseTest
+    {
+        private MySQLMembershipProvider provider;
+        private MySQLRoleProvider roleProvider;
+
+        [SetUp]
+        public void SetUp()
+        {
+            execSQL("DROP TABLE IF EXISTS mysql_membership");
+            execSQL("DROP TABLE IF EXISTS mysql_roles");
+
+            provider = new MySQLMembershipProvider();
+            NameValueCollection config = new NameValueCollection();
+            config.Add("connectionStringName", "LocalMySqlServer");
+            config.Add("applicationName", "/");
+            provider.Initialize(null, config);
+        }
+
+        [Test]
+        public void CreateAndDeleteRoles()
+        {
+            roleProvider = new MySQLRoleProvider();
+            NameValueCollection config = new NameValueCollection();
+            config.Add("connectionStringName", "LocalMySqlServer");
+            config.Add("applicationName", "/");
+            roleProvider.Initialize(null, config);
+
+            // Add the role
+            roleProvider.CreateRole("Administrator");
+            string[] roles = roleProvider.GetAllRoles();
+            Assert.AreEqual(1, roles.Length);
+            Assert.AreEqual("Administrator", roles[0]);
+
+            // now delete the role
+            roleProvider.DeleteRole("Administrator", false);
+            roles = roleProvider.GetAllRoles();
+            Assert.AreEqual(0, roles.Length);
+        }
+
+        private void AddUser(string username, string password)
+        {
+            MembershipCreateStatus status;
+            provider.CreateUser(username, password, "foo@stripped", null,
+                null, true, null, out status);
+            if (status != MembershipCreateStatus.Success)
+                Assert.Fail("User creation failed");
+        }
+
+        [Test]
+        public void AddUserToRole()
+        {
+            roleProvider = new MySQLRoleProvider();
+            NameValueCollection config = new NameValueCollection();
+            config.Add("connectionStringName", "LocalMySqlServer");
+            config.Add("applicationName", "/");
+            roleProvider.Initialize(null, config);
+
+            AddUser("eve", "eve");
+            roleProvider.CreateRole("Administrator");
+            roleProvider.AddUsersToRoles(new string[] { "eve" },
+                new string[] { "Administrator" });
+            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
+            provider.DeleteUser("foo", false);
+        }
+    }
+}

Thread
Connector/NET commit: r834 - branches/5.1/MySql.Web/Testsrburnett1 Aug