public void FollowInvalidUserTest() { // act string input = "Charlie follows Alice"; _userManagerMock.Setup(x => x.GetUserByUsername("Charlie", true)).Returns(new User()); _userManagerMock.Setup(x => x.GetUserByUsername("Alice", true)).Throws(new NullReferenceException("Alice does not exists!")); var follow = new Follow(_userManagerMock.Object); // actual var actual = follow.Perform(input); // assert Assert.AreEqual(actual, "Alice does not exists!"); }
public void FollowMultipleNewUserTest() { // act string input = "Charlie follows Alice"; var parent = new User { Username = "******" }; var child = new User { Username = "******" }; _userManagerMock.Setup(x => x.GetUserByUsername(parent.Username, true)).Returns(parent); _userManagerMock.Setup(x => x.GetUserByUsername(child.Username, true)).Returns(child); _userManagerMock.Setup(x => x.CheckFollowerExists(parent, child)); _userManagerMock.Setup(x => x.FollowUser(parent, child)); var follow = new Follow(_userManagerMock.Object); // actual var actual = follow.Perform(input); // assert Assert.AreEqual(actual, string.Empty); _userManagerMock.Verify(x => x.FollowUser(parent, child), Times.Once); }
public void FollowAlreadyFollowedUserTest() { // act string input = "Charlie follows Alice"; var parent = new User { Username = "******" }; var child = new User { Username = "******" }; var children = new List<User> { child }; _userManagerMock.Setup(x => x.GetUserByUsername(parent.Username, true)).Returns(parent); _userManagerMock.Setup(x => x.GetUserByUsername(child.Username, true)).Returns(child); _userManagerMock.Setup(x => x.CheckFollowerExists(parent, child)).Throws(new Exception("Alice already followed!")); var follow = new Follow(_userManagerMock.Object); // actual var actual = follow.Perform(input); // assert Assert.AreEqual(actual, "Alice already followed!"); }