public void TestAddPermissionThrowsExceptionIfApplicationNotFound()
{
try
{
#region Arrange
Controller.ControllerContext.HttpContext = new MockHttpContext(1, new[] { "" });
ControllerRecordFakes.FakeApplications(3, ApplicationRepository);
ControllerRecordFakes.FakeRoles(5, RoleRepository);
ControllerRecordFakes.FakeUsers(3, UserRepository);
ControllerRecordFakes.FakePermissions(1, PermissionRepository);
RoleService.Expect(a => a.GetVisibleByUser("Name4", "UserName")).Return(RoleRepository.Queryable).Repeat.Any();
UserService.Expect(a => a.CanUserManageGivenLogin("Name4", "UserName", "LoginId3")).Return(true).Repeat.Any();
PermissionRepository.Expect(a => a.EnsurePersistent(Arg<Permission>.Is.Anything)).Repeat.Any();
#endregion Arrange
#region Act
Controller.AddPermission("Name4", "LoginId3", 3);
#endregion Act
}
catch (Exception ex)
{
#region Assert
Assert.IsNotNull(ex);
Assert.AreEqual("Sequence contains no elements", ex.Message);
UserService.AssertWasCalled(a => a.CanUserManageGivenLogin("Name4", "UserName", "LoginId3"));
RoleService.AssertWasCalled(a => a.GetVisibleByUser("Name4", "UserName"));
PermissionRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg<Permission>.Is.Anything));
#endregion Assert
throw;
}
}