public void ShouldSaveReferenceData() { var fakeDto = GroupLeaderMock(); const int groupLeaderFormConfig = 23; const int groupLeaderReference = 56; const int groupLeaderReferenceName = 57; const int groupLeaderHuddle = 92; const int groupLeaderStudent = 126; _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderFormId")).Returns(groupLeaderFormConfig); _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderReferenceFieldId")).Returns(groupLeaderReference); _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderReferenceNameFieldId")).Returns(groupLeaderReferenceName); _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderHuddleFieldId")).Returns(groupLeaderHuddle); _configWrapper.Setup(m => m.GetConfigIntValue("GroupLeaderStudentFieldId")).Returns(groupLeaderStudent); _formService.Setup(m => m.SubmitFormResponse(It.IsAny <MpFormResponse>())).Returns((MpFormResponse form) => { Assert.AreEqual(groupLeaderFormConfig, form.FormId); return(1); }); var responseId = _fixture.SaveReferences(fakeDto).Wait(); Assert.AreEqual(responseId, 1); }
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); }