コード例 #1
0
        public async Task ShouldNotifyChatMessageSent()
        {
            var dbContext  = InfrastructureFactory.GetInMemoryContext(nameof(ShouldNotifyChatMessageSent));
            var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext);
            await unitOfWork.AddAndSaveAsync(EntityFactory.GetUser("johndoe", "Pass@123"));

            await unitOfWork.AddAndSaveAsync(EntityFactory.GetChat("test", "johndoe"));

            var notifier = InfrastructureFactory.GetNotifierSubstitute();
            var handler  = new ChatMessageSentEventHandler(unitOfWork, InfrastructureFactory.GetMachineDateTime(), notifier);

            await handler.Handle(new ChatMessageSentEvent("Test Message", "johndoe", "test"), default);

            await notifier.Received(1).NotifyAsync("test", ChatConstants.MessageSentActionName, Arg.Any <ChatMessage>());
        }
コード例 #2
0
        public async Task ShouldSaveMessageSent()
        {
            var dbContext  = InfrastructureFactory.GetInMemoryContext(nameof(ShouldSaveMessageSent));
            var unitOfWork = InfrastructureFactory.GetEfUnitOfWork(dbContext);
            await unitOfWork.AddAndSaveAsync(EntityFactory.GetUser("johndoe", "Pass@123"));

            await unitOfWork.AddAndSaveAsync(EntityFactory.GetChat("test", "johndoe"));

            var handler = new ChatMessageSentEventHandler(unitOfWork, InfrastructureFactory.GetMachineDateTime(), InfrastructureFactory.GetNotifierSubstitute());

            await handler.Handle(new ChatMessageSentEvent("Test Message", "johndoe", "test"), default);

            var message = await unitOfWork.GetSingleAsync <ChatMessageEntity>(m => m.Stock == "test");

            Assert.AreEqual("johndoe", message.FromNickName);
            Assert.AreEqual("Test Message", message.Message);
        }