Chapter 2, Ticket Projection

Hello. I found the text of the task is some misleading. There is the sentence “Once the unit tests are passing, run the application.” Speaking about the test “TestUpdateUserPreferences”, it is not clear for me if I should implement the method UsersRepository.SetUserPreferencesAsync(…) in this ticket? I attach the code of the method. I suppose the test never passes. So, my question. Please, tell me, must I implement the method SetUserPreferencesAsync?

         public async Task<UserResponse> SetUserPreferencesAsync(string email,
        Dictionary<string, string> preferences, CancellationToken cancellationToken = default)
              Ticket: User Preferences
              Update the "preferences" field in the corresponding user's document to
              reflect the new information in preferences.

            UpdateResult updateResult = null;
            // TODO Ticket: User Preferences
            // Use the data in "preferences" to update the user's preferences.
            // updateResult = await _usersCollection.UpdateOneAsync(
            //    new BsonDocument(),
            //    Builders<User>.Update.Set("TODO", preferences),
            //    /* Be sure to pass a new UpdateOptions object here,
            //       setting IsUpsert to false! */
            //    new UpdateOptions(),
            //    cancellationToken);

            return updateResult.MatchedCount == 0
                ? new UserResponse(false, "No user found with that email")
                : new UserResponse(true, updateResult.IsAcknowledged.ToString());
        catch (Exception e)
            return new UserResponse(false, e.Message);

Hi @Maksim_Pashkov, no, you don’t need to make any changes to the SetUserPreferencesAsync method for now. I believe it was a typo, you can go ahead by running the following test as mentioned in the ticket:

dotnet test --filter “Name~TestGetMoviesByCountry”

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.