Skip to content

Commit

Permalink
Tests: added for role provider
Browse files Browse the repository at this point in the history
  • Loading branch information
FoC- committed Jan 6, 2013
1 parent 94cd016 commit 46c9164
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 0 deletions.
5 changes: 5 additions & 0 deletions MongoMembership.Tests/MongoMembership.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\ProvidersStubs.cs" />
<Compile Include="Providers\MembershipProvider\When_CreateUser_is_caled_and_email_is_null.cs" />
<Compile Include="Providers\RoleProvider\When_AddUsersToRoles_is_called.cs" />
<Compile Include="Providers\RoleProvider\When_DeleteRole_is_called_and_role_exist.cs" />
<Compile Include="Providers\RoleProvider\When_DeleteRole_is_called_and_role_not_exist.cs" />
<Compile Include="Providers\RoleProvider\When_GetAllRoles_is_called_and_one_role_created.cs" />
<Compile Include="Providers\RoleProvider\When_GetAllRoles_is_called_and_roles__Admin__and__AdmiN__created.cs" />
<Compile Include="Providers\RoleProvider\When_GetUsersInRole_is_called_and_two_users_added_to_same_role.cs" />
<Compile Include="Providers\RoleProvider\When_CreateRole_is_called.cs" />
<Compile Include="Providers\RoleProvider\When_IsUserInRole_is_called_and_role_to_compare_different_cases.cs" />
Expand Down
8 changes: 8 additions & 0 deletions MongoMembership.Tests/Providers/ProvidersStubs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Web.Security;
using Machine.Specifications;
using MongoMembership.Providers;

namespace MongoMembership.Tests.Providers
Expand All @@ -14,5 +15,12 @@ protected static MongoRoleProvider CreateRoleProvider()
{
return (MongoRoleProvider)Roles.Provider;
}

protected static void AddUser(MongoMembershipProvider membershipProvider, string username)
{
MembershipCreateStatus status;
membershipProvider.CreateUser(username, "password123", username + "@em.ail", null, null, true, "Id-" + username, out status);
status.ShouldEqual(MembershipCreateStatus.Success);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Machine.Specifications;
using MongoMembership.Providers;

namespace MongoMembership.Tests.Providers.RoleProvider
{
[Subject(typeof(MongoRoleProvider))]
internal class When_AddUsersToRoles_is_called : ProvidersStubs
{
Establish conext = () =>
{
admin = "AdmiN";
guest = "GueSt";
banned = "bannned";
username1 = "username1";
username2 = "username2";
username3 = "username3";

MongoMembershipProvider membershipProvider = CreateMembershipProvider();

provider = CreateRoleProvider();
provider.CreateRole(admin);
provider.CreateRole(guest);
provider.CreateRole(banned);
AddUser(membershipProvider, username1);
AddUser(membershipProvider, username2);
AddUser(membershipProvider, username3);
};

Because of = () =>
{
provider.AddUsersToRoles(new[] { username1, username2 }, new[] { admin });
provider.AddUsersToRoles(new[] { username1, username2, username3 }, new[] { guest });
provider.AddUsersToRoles(new[] { username3 }, new[] { banned });
};

It should_return_true_for__username1__and__admin__role = () =>
provider.IsUserInRole(username1, admin).ShouldBeTrue();

It should_return_true_for__username1__and__guest__role = () =>
provider.IsUserInRole(username1, guest).ShouldBeTrue();

It should_return_false_for__username1__and__banned__role = () =>
provider.IsUserInRole(username1, banned).ShouldBeFalse();

It should_return_false_for__username3__and__admin__role = () =>
provider.IsUserInRole(username3, admin).ShouldBeFalse();

It should_return_true_for__username3__and__guest__role = () =>
provider.IsUserInRole(username3, guest).ShouldBeTrue();

It should_return_true_for__username3__and__banned__role = () =>
provider.IsUserInRole(username3, banned).ShouldBeTrue();

private static MongoRoleProvider provider;
private static string admin;
private static string guest;
private static string banned;
private static string username1;
private static string username2;
private static string username3;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Machine.Specifications;
using MongoMembership.Providers;

namespace MongoMembership.Tests.Providers.RoleProvider
{
[Subject(typeof(MongoRoleProvider))]
internal class When_DeleteRole_is_called_and_role_exist : ProvidersStubs
{
Establish conext = () =>
{
roleName = "AdmiN";
provider = CreateRoleProvider();
provider.CreateRole(roleName);
};

Because of = () =>
provider.DeleteRole(roleName, false);

It should_delete_role = () =>
provider.GetAllRoles().ShouldBeEmpty();

private static MongoRoleProvider provider;
private static string roleName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Machine.Specifications;
using MongoMembership.Providers;

namespace MongoMembership.Tests.Providers.RoleProvider
{
[Subject(typeof(MongoRoleProvider))]
internal class When_DeleteRole_is_called_and_role_not_exist : ProvidersStubs
{
Establish conext = () =>
{
provider = CreateRoleProvider();
};

Because of = () =>
exception = Catch.Exception(() => provider.DeleteRole("NotAdmiN", false));

It should_not_fail = () =>
exception.ShouldBeNull();

private static MongoRoleProvider provider;
private static Exception exception;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Machine.Specifications;
using MongoMembership.Providers;

namespace MongoMembership.Tests.Providers.RoleProvider
{
[Subject(typeof(MongoRoleProvider))]
internal class When_GetAllRoles_is_called_and_one_role_created : ProvidersStubs
{
Establish conext = () =>
{
roleName = "AdmiN";
provider = CreateRoleProvider();
provider.CreateRole(roleName);
};

Because of = () =>
result = provider.GetAllRoles();

It should_return_same_role = () =>
result.ShouldContainOnly(new[] { roleName });

private static MongoRoleProvider provider;
private static string roleName;
private static string[] result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Machine.Specifications;
using MongoMembership.Providers;

namespace MongoMembership.Tests.Providers.RoleProvider
{
[Subject(typeof(MongoRoleProvider))]
internal class When_GetAllRoles_is_called_and_roles__Admin__and__AdmiN__created : ProvidersStubs
{
Establish conext = () =>
{
provider = CreateRoleProvider();
AdmiN = "AdmiN";
provider.CreateRole(AdmiN);
provider.CreateRole("Admin");
};

Because of = () =>
result = provider.GetAllRoles();

It should_only__AdmiN__ = () =>
result.ShouldContainOnly(new[] { AdmiN });

private static MongoRoleProvider provider;
private static string AdmiN;
private static string[] result;
}
}

0 comments on commit 46c9164

Please sign in to comment.