public void UsersDoNotConnectWhenOtherUserDoesNotExist( [Frozen(Matching.ImplementedInterfaces)] FakeDB db, User user, int otherUserId, ConnectionsController sut) { db.Add(user); db.IsDirty = false; var actual = sut.Post(user.Id.ToString(), otherUserId.ToString()); var err = Assert.IsAssignableFrom <BadRequestObjectResult>(actual); Assert.Equal("Other user not found.", err.Value); Assert.False(db.IsDirty); }
public void UsersFailToConnectWhenOtherUserIdIsNoInt( [Frozen] Mock <IUserCache> cacheTD, [Frozen] Mock <IUserRepository> repoTD, User user, string otherUserId, ConnectionsController sut) { Assert.False(int.TryParse(otherUserId, out var _)); cacheTD.Setup(c => c.Find(user.Id.ToString())).Returns(user); cacheTD.Setup(c => c.Find(otherUserId)).Returns((User)null); var actual = sut.Post(user.Id.ToString(), otherUserId); Assert.IsAssignableFrom <BadRequestErrorMessageResult>(actual); repoTD.Verify(r => r.Update(It.IsAny <User>()), Times.Never()); }
public void UsersFailToConnectWhenUserIsInNeitherCacheNorRepo( [Frozen] Mock <IUserCache> cacheTD, [Frozen] Mock <IUserRepository> repoTD, int userId, User otherUser, ConnectionsController sut) { cacheTD.Setup(c => c.Find(userId.ToString())).Returns((User)null); cacheTD.Setup(c => c.Find(otherUser.Id.ToString())).Returns(otherUser); repoTD.Setup(r => r.ReadUser(userId)).Returns((User)null); repoTD.Setup(r => r.ReadUser(otherUser.Id)).Returns(otherUser); var actual = sut.Post(userId.ToString(), otherUser.Id.ToString()); Assert.IsAssignableFrom <BadRequestErrorMessageResult>(actual); repoTD.Verify(r => r.Update(It.IsAny <User>()), Times.Never()); }
public void UsersFailToConnectWhenOtherUserIdIsInvalid( [Frozen(Matching.ImplementedInterfaces)] FakeDB db, User user, string otherUserId, ConnectionsController sut) { Assert.False(int.TryParse(otherUserId, out _)); db.Add(user); db.IsDirty = false; var actual = sut.Post(user.Id.ToString(), otherUserId); var err = Assert.IsAssignableFrom <BadRequestObjectResult>(actual); Assert.Equal("Invalid ID for other user.", err.Value); Assert.False(db.IsDirty); }
public void UsersFailToConnectWhenUserIdIsInvalid( [Frozen(Matching.ImplementedInterfaces)] FakeDB db, string userId, User otherUser, ConnectionsController sut) { Assert.False(int.TryParse(userId, out _)); db.Add(otherUser); db.IsDirty = false; var actual = sut.Post(userId, otherUser.Id.ToString()); var err = Assert.IsAssignableFrom <BadRequestErrorMessageResult>(actual); Assert.Equal("Invalid user ID.", err.Message); Assert.False(db.IsDirty); }
public void UsersSuccessfullyConnect( [Frozen(Matching.ImplementedInterfaces)] FakeDB db, User user, User otherUser, ConnectionsController sut) { db.Add(user); db.Add(otherUser); db.IsDirty = false; var actual = sut.Post(user.Id.ToString(), otherUser.Id.ToString()); var ok = Assert.IsAssignableFrom <OkResult>(actual); Assert.Equal(otherUser, ok.Content); Assert.True(db.IsDirty); Assert.Contains(otherUser.Id, user.Connections); }
public void UsersSuccessfullyConnectWhenOtherUserIsInCache( [Frozen] Mock <IUserCache> cacheTD, [Frozen] Mock <IUserRepository> repoTD, User user, User otherUser, ConnectionsController sut) { cacheTD.Setup(c => c.Find(user.Id.ToString())).Returns((User)null); cacheTD.Setup(c => c.Find(otherUser.Id.ToString())).Returns(otherUser); repoTD.Setup(r => r.ReadUser(user.Id)).Returns(user); var actual = sut.Post(user.Id.ToString(), otherUser.Id.ToString()); var ok = Assert.IsAssignableFrom <OkNegotiatedContentResult <User> >( actual); Assert.Equal(otherUser, ok.Content); repoTD.Verify(r => r.Update(user)); Assert.Contains(otherUser.Id, user.Connections); }