public SQLiteServerConnectionClientWorker(string connectionString, ConnectionsController controller, int commandTimeout) { if (null == controller) { throw new ArgumentNullException(nameof(controller)); } _controller = controller; _connectionString = connectionString; CommandTimeout = commandTimeout; }
public SQLiteServerDataReaderClientWorker(ConnectionsController controller, SQLiteServerCommandClientWorker parentCommand, int queryTimeouts) { if (null == controller) { throw new ArgumentNullException(nameof(controller), "The controller cannot be null."); } _controller = controller; _parentCommand = parentCommand; _queryTimeouts = queryTimeouts; }
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 GetConnectionsTest() { // Arrange ConnectionsController connectionsController = new ConnectionsController(unitOfFactory); // Act var result2 = connectionsController.GetConnection(1); var contentresult = result2.Result as OkNegotiatedContentResult <ConnectionDTO>; var result3 = connectionsController.GetConnection(-5); // Assert Assert.IsNotNull(contentresult.Content.Parts); Assert.IsNotNull(contentresult.Content.Train); Assert.AreEqual(1, contentresult.Content.Id); Assert.IsInstanceOfType(result3.Result, typeof(NotFoundResult)); }
public SQLiteServerConnectionServerWorker(string connectionString, ConnectionsController controller, int commandTimeout) { if (null == controller) { throw new ArgumentNullException(nameof(controller)); } CommandTimeout = commandTimeout; _controller = controller; _connection = new SQLiteConnection(connectionString); // we listen for messages right away // as we might not be the one who opens _controller.OnReceived += OnReceived; }
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 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); }
public void ShouldForwardLogicToConnectCommand() { //GIVEN var connectCommand = Substitute.For <IUserUseCase>(); var resultFromConnection = Any.Instance <IActionResult>(); var connectionInProgress = Substitute.For <IActionResultBasedConnectionInProgress>(); var useCaseFactory = Substitute.For <IUserUseCaseFactory>(); var connectionInProgressFactory = Substitute.For <IConnectionInProgressFactory>(); var user1Id = Any.String(); var user2Id = Any.String(); var connectionsController = new ConnectionsController( useCaseFactory, connectionInProgressFactory); connectionInProgressFactory.CreateConnectionInProgress().Returns(connectionInProgress); useCaseFactory.CreateConnectionUseCase(user1Id, user2Id, connectionInProgress).Returns(connectCommand); connectionInProgress.ToActionResult().Returns(resultFromConnection); //WHEN var actionResult = connectionsController.Connect(user1Id, user2Id); //THEN connectCommand.Received(1).Execute(); actionResult.Should().Be(resultFromConnection); }
public ConnectionsControllerTests() { _connectionServiceMock = new Mock <IConnectionService>(); _connectionsController = new ConnectionsController(_connectionServiceMock.Object); }