public async Task RequestContributor_SavesRequest() { var contributorRequestViewModel = new SurveyContributorRequestViewModel { SurveyId = 123, EmailAddress = "*****@*****.**" }; var apiResult = new Mock <ApiResult>(); var invitations = new List <ContributorRequest>(); _surveyService.Setup(c => c.AddContributorRequestAsync(It.IsAny <ContributorRequest>())) .ReturnsAsync(apiResult.Object) .Callback <ContributorRequest>(c => invitations.Add(c)); // RequestContributor looks for existing contributors var contributorsDto = new ContributorsDTO { Contributors = new List <UserDTO>(), Requests = new List <ContributorRequest>() }; var apiResult2 = new Mock <ApiResult <ContributorsDTO> >(); apiResult2.Setup(x => x.Succeeded).Returns(true); apiResult2.Setup(x => x.Item).Returns(contributorsDto); _surveyService.Setup(c => c.GetSurveyContributorsAsync(It.IsAny <int>())) .ReturnsAsync(apiResult2.Object); var result = await _target.RequestContributor(contributorRequestViewModel); Assert.Equal(123, invitations[0].SurveyId); Assert.Equal("*****@*****.**", invitations[0].EmailAddress); }
public async Task RequestContributor_SavesRequest() { var contributorRequestViewModel = new SurveyContributorRequestViewModel { SurveyId = 123, EmailAddress = "*****@*****.**" }; var apiResult = A.Fake <ApiResult>(); var invitations = new List <ContributorRequest>(); A.CallTo(() => _surveyService.AddContributorRequestAsync(A <ContributorRequest> .Ignored)).Invokes((ContributorRequest r) => invitations.Add(r)).Returns(apiResult); // RequestContributor looks for existing contributors var contributorsDto = new ContributorsDTO { Contributors = new List <UserDTO>(), Requests = new List <ContributorRequest>() }; var apiResult2 = A.Fake <ApiResult <ContributorsDTO> >(); A.CallTo(() => apiResult2.Succeeded).Returns(true); A.CallTo(() => apiResult2.Item).Returns(contributorsDto); A.CallTo(() => _surveyService.GetSurveyContributorsAsync(A <int> .Ignored)).Returns(Task.FromResult(apiResult2)); var result = await _target.RequestContributor(contributorRequestViewModel); Assert.Equal(123, invitations[0].SurveyId); Assert.Equal("*****@*****.**", invitations[0].EmailAddress); }
public async Task Contributors_ShowsContributorsForSurvey() { var contributors = new ContributorsDTO(); var apiResult = A.Fake <ApiResult <ContributorsDTO> >(); A.CallTo(() => apiResult.Item).Returns(contributors); A.CallTo(() => apiResult.Succeeded).Returns(true); A.CallTo(() => _surveyService.GetSurveyContributorsAsync(A <int> .Ignored)).Returns(apiResult); var result = await _target.Contributors(12345); var viewResult = Assert.IsType <ViewResult>(result); Assert.Equal(contributors, viewResult.ViewData.Model); }
public async Task Contributors_ShowsContributorsForSurvey() { var contributors = new ContributorsDTO(); var apiResult = new Mock <ApiResult <ContributorsDTO> >(); apiResult.SetupGet(s => s.Item).Returns(contributors); apiResult.SetupGet(s => s.Succeeded).Returns(true); _surveyService.Setup(s => s.GetSurveyContributorsAsync(It.IsAny <int>())) .ReturnsAsync(apiResult.Object); var result = await _target.Contributors(12345); var viewResult = Assert.IsType <ViewResult>(result); Assert.Equal(contributors, viewResult.ViewData.Model); }