public async Task Should_Request_Nickname_When_Connect() { // arrage Guid expectedConnectionUid = Guid.NewGuid(); Client expectedClient = new Client() { ConnectionUid = expectedConnectionUid }; Client actualClient = null; SetNicknameCommand actualCommand = null; DomainEvents.OnCommand += (connectionUid, command) => { actualClient = connectionUid; actualCommand = command as SetNicknameCommand; return(Task.CompletedTask); }; ClientFactoryMock.Setup(mock => mock.Create(expectedConnectionUid)).Returns(expectedClient); // act await ChatFacade.ConnectAsync(expectedConnectionUid); // assert Assert.AreEqual(expectedConnectionUid, actualClient.ConnectionUid); Assert.IsNotNull(actualCommand); }
public void Should_Get_SetNicknameCommandHandler_When_Command_Is_SetNickname() { var command = new SetNicknameCommand(); var handler = CommandHandlerFactory.GetHandler(command); Assert.IsAssignableFrom <SetNicknameCommandHandler>(handler); }
public void Should_Convert_SetNicknameCommand_To_Text() { string expectedText = "Welcome to our chat! Please provide a nickname."; SetNicknameCommand messageCommand = new SetNicknameCommand(); string actualText = Mapper.ToString(messageCommand); Assert.AreEqual(expectedText, actualText); }
public void Should_UpdateNicknameAsync() { var connectionUid = Guid.NewGuid(); var nickname = "Will"; var command = new SetNicknameCommand() { ConnectionUid = connectionUid, Nickname = nickname }; SetNicknameCommandHandler.ProcessAsync(command); ChatServiceMock.Verify(mock => mock.UpdateNicknameAsync(connectionUid, nickname)); }