public void ShouldSaveProfileWithCorrectDisplayName() { var leaderDto = GroupLeaderMock(); const string fakeToken = "letmein"; const int fakeUserId = 98124; var fakePerson = PersonMock(leaderDto); _userRepo.Setup(m => m.GetUserIdByUsername(leaderDto.OldEmail)).Returns(fakeUserId); _userRepo.Setup(m => m.UpdateUser(It.IsAny <Dictionary <string, object> >())); _personService.Setup(m => m.GetLoggedInUserProfile(fakeToken)).Returns(fakePerson); _contactMock.Setup(m => m.UpdateContact(It.IsAny <int>(), It.IsAny <Dictionary <string, object> >())).Callback((int contactId, Dictionary <string, object> obj) => { Assert.AreEqual(obj["Display_Name"], $"{leaderDto.LastName}, {leaderDto.NickName}"); }); _contactMock.Setup(m => m.UpdateHousehold(It.IsAny <MpHousehold>())).Returns(Observable.Start(() => new MpHousehold())); _fixture.SaveProfile(fakeToken, leaderDto).Wait(); }
public async Task <IHttpActionResult> SaveProfile([FromBody] GroupLeaderProfileDTO profile) { if (ModelState.IsValid) { return(await Authorized(token => { try { _groupLeaderService.SaveReferences(profile).Zip <int, IList <Unit>, int>(_groupLeaderService.SaveProfile(token, profile), (int first, IList <Unit> second) => first).Wait(); return Ok(); } catch (Exception e) { var apiError = new ApiErrorDto("Saving Leader Profile failed:", e); throw new HttpResponseException(apiError.HttpResponseMessage); } })); } var errors = ModelState.Values.SelectMany(val => val.Errors).Aggregate("", (current, err) => current + err.ErrorMessage); var dataError = new ApiErrorDto("Registration Data Invalid", new InvalidOperationException("Invalid Registration Data" + errors)); throw new HttpResponseException(dataError.HttpResponseMessage); }