Example #1
0
        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);
        }
Example #2
0
        public void Should_Get_SetNicknameCommandHandler_When_Command_Is_SetNickname()
        {
            var command = new SetNicknameCommand();

            var handler = CommandHandlerFactory.GetHandler(command);

            Assert.IsAssignableFrom <SetNicknameCommandHandler>(handler);
        }
Example #3
0
        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);
        }
Example #4
0
        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));
        }