public void TryUpdaterUser_With_Internal_User_Should_Update_User_From_Claims() { // arrange var mockUserDataAccess = new Mock <IUserDataAccess>(); mockUserDataAccess.Setup(m => m.GetUser(It.IsAny <string>())).Returns(new User()); var controllerHelperMock = new Mock <IControllerHelper>(); controllerHelperMock.Setup(m => m.IsInternalUser()).Returns(true); controllerHelperMock.Setup(m => m.GetFromClaim(It.IsAny <string>())).Returns("claimvalue"); var sut = new AuthControllerHelper(null, mockUserDataAccess.Object, controllerHelperMock.Object, null, null); // act sut.TryUpdateUser("1", new List <ClaimInfo>()); // assert controllerHelperMock.Verify(m => m.GetFromClaim(It.Is <string>(val => val == "/identity/claims/surname"))); controllerHelperMock.Verify(m => m.GetFromClaim(It.Is <string>(val => val == "/identity/claims/givenname"))); controllerHelperMock.Verify(m => m.GetFromClaim(It.Is <string>(val => val == "/identity/claims/emailaddress"))); mockUserDataAccess.Verify(m => m.UpdateUserOnLogin(It.Is <User>(u => u.EmailAddress == "claimvalue"), It.IsAny <string>(), It.IsAny <string>())); }
public void TryUpdaterUser_With_User_Should_Update_User_From_Db_If_Email_Changes() { // arrange var mockUserDataAccess = new Mock <IUserDataAccess>(); mockUserDataAccess.Setup(m => m.GetUser(It.IsAny <string>())).Returns(new User { FamilyName = "Meier", FirstName = "Bruno", EmailAddress = "*****@*****.**" }); var controllerHelperMock = new Mock <IControllerHelper>(); controllerHelperMock.Setup(m => m.IsInternalUser()).Returns(true); controllerHelperMock.Setup(m => m.GetFromClaim("/identity/claims/surname")).Returns("Meier"); controllerHelperMock.Setup(m => m.GetFromClaim("/identity/claims/givenname")).Returns("Bruno"); controllerHelperMock.Setup(m => m.GetFromClaim("/identity/claims/emailaddress")).Returns("*****@*****.**"); var sut = new AuthControllerHelper(null, mockUserDataAccess.Object, controllerHelperMock.Object, null, null); // act sut.TryUpdateUser("1", new List <ClaimInfo>()); // assert mockUserDataAccess.Verify(m => m.UpdateUserOnLogin(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>())); }
public void TryUpdaterUser_With_InExistent_User_Should_Return_False() { // arrange var mockUserDataAccess = Mock.Of <IUserDataAccess>(); var sut = new AuthControllerHelper(null, mockUserDataAccess, null, null, null); // act var result = sut.TryUpdateUser("1", null); // assert result.Should().BeFalse(); }
public void TryUpdaterUser_With_User_Without_ManagementRole_Should_Remove_StandardRole(string role) { // arrange var mockUserDataAccess = new Mock <IUserDataAccess>(); mockUserDataAccess.Setup(m => m.GetUser(It.IsAny <string>())).Returns(new User()); var controllerHelperMock = new Mock <IControllerHelper>(); controllerHelperMock.Setup(m => m.IsInternalUser()).Returns(true); controllerHelperMock.Setup(m => m.GetMgntRoleFromClaim()).Returns(role); controllerHelperMock.Setup(m => m.GetFromClaim(It.IsAny <string>())).Returns("claimvalue"); var applicationRoleUserDataAccessMock = new Mock <IApplicationRoleUserDataAccess>(); var sut = new AuthControllerHelper(applicationRoleUserDataAccessMock.Object, mockUserDataAccess.Object, controllerHelperMock.Object, null, null); // act sut.TryUpdateUser("1", new List <ClaimInfo>()); // assert applicationRoleUserDataAccessMock.Verify(m => m.RemoveRolesUser(It.IsAny <string>(), It.IsAny <string[]>())); }
public void TryUpdaterUser_With_Internal_User_Should_Set_Standard_Role_Only_For_Allowed_User() { // arrange var mockUserDataAccess = new Mock <IUserDataAccess>(); mockUserDataAccess.Setup(m => m.GetUser(It.IsAny <string>())).Returns(new User()); var controllerHelperMock = new Mock <IControllerHelper>(); controllerHelperMock.Setup(m => m.IsInternalUser()).Returns(true); controllerHelperMock.Setup(m => m.GetMgntRoleFromClaim()).Returns(AccessRoles.RoleMgntAllow); controllerHelperMock.Setup(m => m.GetFromClaim(It.IsAny <string>())).Returns("claimvalue"); var applicationRoleUserDataAccessMock = new Mock <IApplicationRoleUserDataAccess>(); var sut = new AuthControllerHelper(applicationRoleUserDataAccessMock.Object, mockUserDataAccess.Object, controllerHelperMock.Object, null, null); // act sut.TryUpdateUser("1", new List <ClaimInfo>()); // assert applicationRoleUserDataAccessMock.Verify(m => m.InsertRoleUser(It.Is <string>(val => val == "Standard"), It.IsAny <string>())); }