Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testReadOnlyPutUserProfileFails()
        public virtual void testReadOnlyPutUserProfileFails()
        {
            User userUdpdate = MockProvider.createMockUser();

            when(identityServiceMock.ReadOnly).thenReturn(true);

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(UserProfileDto.fromUser(userUdpdate)).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(InvalidRequestException).Name)).body("message", equalTo("Identity service implementation is read-only.")).when().put(USER_PROFILE_URL);

            verify(identityServiceMock, never()).saveUser(userUdpdate);
        }
Exemplo n.º 2
0
        public virtual UserProfileDto getUserProfile(UriInfo context)
        {
            User dbUser = findUserObject();

            if (dbUser == null)
            {
                throw new InvalidRequestException(Status.NOT_FOUND, "User with id " + resourceId + " does not exist");
            }

            UserProfileDto user = UserProfileDto.fromUser(dbUser);

            return(user);
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPutProfileNonexistingFails()
        public virtual void testPutProfileNonexistingFails()
        {
            User userUpdate = MockProvider.createMockUserUpdate();

            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId("aNonExistingUser")).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(null);

            UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);

            given().pathParam("id", "aNonExistingUser").body(updateDto).contentType(ContentType.JSON).then().then().expect().statusCode(Status.NOT_FOUND.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(InvalidRequestException).Name)).body("message", equalTo("User with id aNonExistingUser does not exist")).when().put(USER_PROFILE_URL);

            // nothing was saved
            verify(identityServiceMock, never()).saveUser(any(typeof(User)));
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPutProfileThrowsAuthorizationException()
        public virtual void testPutProfileThrowsAuthorizationException()
        {
            User initialUser = MockProvider.createMockUser();
            User userUpdate  = MockProvider.createMockUserUpdate();

            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(initialUser);

            string message = "exception expected";

            doThrow(new AuthorizationException(message)).when(identityServiceMock).saveUser(any(typeof(User)));

            UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(updateDto).contentType(ContentType.JSON).then().statusCode(Status.FORBIDDEN.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(AuthorizationException).Name)).body("message", equalTo(message)).when().put(USER_PROFILE_URL);
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPutProfile()
        public virtual void testPutProfile()
        {
            User initialUser = MockProvider.createMockUser();
            User userUpdate  = MockProvider.createMockUserUpdate();

            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(initialUser);

            UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(updateDto).contentType(ContentType.JSON).then().statusCode(Status.NO_CONTENT.StatusCode).when().put(USER_PROFILE_URL);

            // password was updated
            verify(initialUser).Email     = updateDto.Email;
            verify(initialUser).FirstName = updateDto.FirstName;
            verify(initialUser).LastName  = updateDto.LastName;

            // and then saved
            verify(identityServiceMock).saveUser(initialUser);
        }