Ejemplo n.º 1
0
		public void Correctly_assigns_current_user_to_role()
		{
			MockRepository mocks = new MockRepository();

			IPrincipal principal = mocks.CreateMock<IPrincipal>();
			IIdentity identity = mocks.CreateMock<IIdentity>();
			IWebContext context = mocks.CreateMock<IWebContext>();
			IPrincipalFactory principalFactory = mocks.CreateMock<IPrincipalFactory>();

			using (mocks.Record())
			{
				Expect.Call(context.GetUserIdentity()).Return(identity);
				Expect.Call(principalFactory.CreatePrincipal(identity, "Administrator", "Other Role")).Return(principal);
				context.SetUser(principal);
			}

			mocks.ReplayAll();

			using (mocks.Playback())
			{
				IRoleManager manager = new RoleManager(context, principalFactory);
				manager.AssignCurrentUserToRoles("Administrator", "Other Role");
			}

			mocks.VerifyAll();
		}
Ejemplo n.º 2
0
		public void Correctly_determines_if_user_is_not_in_role()
		{
			MockRepository mocks = new MockRepository();

			IPrincipal principal = mocks.CreateMock<IPrincipal>();
			IWebContext context = mocks.CreateMock<IWebContext>();

			using (mocks.Record())
			{
				Expect.Call(context.GetUserPrinciple()).Return(principal); ;
				Expect.Call(principal.IsInRole("Administrator")).Return(false);
			}

			mocks.ReplayAll();

			using (mocks.Playback())
			{
				IRoleManager manager = new RoleManager(context, null);
				Assert.That(manager.IsCurrentUserInRole("Administrator"), Is.False);
			}

			mocks.VerifyAll();
		}