public void DirectMessageRequest_WhenSerializedAndDeserialized_ShouldBeEqual() { // Arrange Message message = new DirectMessageRequest("user", "lorem ipsum", true); // Act / Assert this.SerializeDeserializeAndCompare(message); }
public void ProcessingDirectMessageRequest_WhenPrivate_ShouldSendMessageToUser() { // Arrange var senderUser = new ChatUser("Sender"); var recipientUser = new ChatUser("RecipientUser"); var message = new DirectMessageRequest(recipientUser.Username, "Hello!", true); var users = new ChatUser[] { senderUser, recipientUser, new ChatUser("User01"), new ChatUser("User02"), new ChatUser("User03"), }; var userService = Substitute.For <IUserService>(); userService.GetConnectedUsers().Returns(users); userService.TryGetUserByName(Arg.Is(senderUser.Username), out Arg.Any <ChatUser>()) .Returns(args => { args[1] = senderUser; return(true); }); userService.TryGetUserByName(Arg.Is(recipientUser.Username), out Arg.Any <ChatUser>()) .Returns(args => { args[1] = recipientUser; return(true); }); var messageSenderService = Substitute.For <IMessageSenderService>(); var processor = new DirectMessageRequestProcessor(userService, messageSenderService); // Act processor.HandleMessage(senderUser.Username, message); // Assert messageSenderService.Received(1).SendMessageToUser(recipientUser.Username, Arg.Any <DirectMessageResponse>()); }