public void GivenValidConnectionDetails_WhenCreateConnectionCalled_ReturnCorrectCombinedProfileViewModel() { // Arrange var fakeConnection = A.Fake <Connection>(); fakeConnection.UserId = 5; fakeConnection.OtherUserId = 10; var fakeCombinedUserDetails = A.Fake <CombinedUserProfilesViewModel>(); fakeCombinedUserDetails.Connection = fakeConnection; fakeCombinedUserDetails.MyUserDetails = _mockUserData.FakeUser1; A.CallTo(() => _fakeProfileService.AddConnection(fakeConnection)).Returns(true); // Act var result = _profilesController.CreateConnectionBetweenUsers(fakeCombinedUserDetails) as RedirectToRouteResult; // Assert Assert.IsNotNull(result); var values = result.RouteValues.Values; var userDetails = values.First(); Assert.AreSame(userDetails, fakeCombinedUserDetails.MyUserDetails); Assert.IsTrue(values.Contains(CombinedUserProfilesViewModel.Success)); Assert.IsTrue(values.Contains(controllerName)); Assert.IsTrue(values.Contains(actionCalledOtherUsersProfile)); A.CallTo(() => _fakeProfileService.AddConnection(fakeConnection)).MustHaveHappened(Repeated.Exactly.Once); }
public void GivenValidConnectionDetails_WhenAddConnectionCalled_ReturnTrue() { // Arrange var fakeConnection = A.Fake <Connection>(); fakeConnection.UserId = 5; fakeConnection.OtherUserId = 10; A.CallTo(() => _fakeConnectionRepository.Create(fakeConnection)).Returns(true); A.CallTo(() => _fakeConnectionRepository.Create(fakeConnection)).Returns(true); var result = _profileService.AddConnection(fakeConnection); Assert.That(result, Is.Not.Null); Assert.That(result, Is.InstanceOf <bool>()); Assert.That(result, Is.EqualTo(true)); A.CallTo(() => _fakeConnectionRepository.Create(fakeConnection)).MustHaveHappened(Repeated.Exactly.Twice); }
public ActionResult CreateConnectionBetweenUsers(CombinedUserProfilesViewModel bothUserProfileDetails) { bool isConnectionCreated = _profileService.AddConnection(bothUserProfileDetails.Connection); bothUserProfileDetails.UsersAreConnected = isConnectionCreated; bothUserProfileDetails.ConnectionWasCreated = (isConnectionCreated) ? CombinedUserProfilesViewModel.Success : CombinedUserProfilesViewModel.Failed; return(RedirectToAction("OtherUsersProfile", "Profiles", bothUserProfileDetails)); }