public async Task GetMessagesAsync_Test()
        {
            //Arrage:
            await InitDictDataAsync();

            var service = new ConversationMsgAppService(statefulServiceContext, stateManager);
            var msg     = DefaultConversationMsg.DeepCopy();

            //Act:
            var gettedMessages = await service.GetMessagesAsync(new List <MessageNotifyDto>()
            {
                new MessageNotifyDto()
                {
                    LatestMsgId    = Guid.Empty,
                    Target         = NotifyTargetType.Conversation,
                    TargetId       = msg.ConversationId.ToString(),
                    TargetCategory = (int)ConversationType.P2P,
                }
            });

            //Assert:
            //PS:P2PMessageIndexDictName 类型错误
            Assert.AreEqual(2, gettedMessages.Count);
            var targetMsg = gettedMessages.Find(o => o.Id == msg.Id);

            Assert.IsNotNull(targetMsg);
            Assert.AreEqual(msg.Content, targetMsg.Content);
            Assert.AreEqual(msg.SenderId, targetMsg.SenderId);
            Assert.AreEqual(msg.Type, targetMsg.Type);
        }
Beispiel #2
0
        protected async Task InitQueueDataAsync()
        {
            await InitDictAsync();

            var message1 = DefaultConversationMsg.DeepCopy();

            using (var tx = stateManager.CreateTransaction())
            {
                await MessageProccessQueue.EnqueueAsync(tx, message1);

                await tx.CommitAsync();
            }
        }
Beispiel #3
0
        public async Task ProcessQueueAsync_Test()
        {
            //Arrage:
            await InitQueueDataAsync();

            var conversation = DefaultConversation.DeepCopy();
            var mock_conversationCtrlAppService = new Mock <IConversationCtrlAppService>();
            var mock_notifySessionActor         = new Mock <INotifySessionActor>();

            mock_conversationCtrlAppService.Setup(u => u.DeleteAsync(It.IsAny <Guid>())).Returns(Task.CompletedTask);
            mock_conversationCtrlAppService.Setup(u => u.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(conversation);
            mock_notifySessionActor.Setup(u => u.PushMsgNotifyAsync(It.IsAny <MessageNotifyDto>())).Returns(Task.CompletedTask);
            Func <Guid, INotifySessionActor> notifySessionActorFactory = (id) => mock_notifySessionActor.Object;

            //Act:
            CancellationTokenSource source = new CancellationTokenSource();

            ThreadPool.QueueUserWorkItem(u =>
            {
                Thread.Sleep(200);
                source.Cancel();
            });

            ConversationMsgQueueProcessor.IsInUnitTest = true;
            await ConversationMsgQueueProcessor.ProcessQueueAsync(stateManager,
                                                                  mock_conversationCtrlAppService.Object, notifySessionActorFactory, source.Token);

            //Assert:
            var msg1 = DefaultConversationMsg.DeepCopy();

            using (var tx = stateManager.CreateTransaction())
            {
                Assert.AreEqual(0, MessageProccessQueue.Count);
                var msgIndex = await MessageIndexDict.TryGetValueAsync(tx, msg1.ConversationId);

                var msgIds = msgIndex.Value;
                var msg    = await MessageListDict.TryGetValueAsync(tx, msgIds[0]);

                Assert.IsTrue(msgIndex.HasValue);
                Assert.AreEqual(1, msgIds.Count);
                Assert.AreEqual(msg1, msg.Value);
                mock_conversationCtrlAppService.Verify(u => u.GetByIdAsync(It.IsAny <Guid>()), Times.Once);
                mock_notifySessionActor.Verify(u => u.PushMsgNotifyAsync(It.IsAny <MessageNotifyDto>()), Times.AtLeast(2));
            }
        }
        public async Task GetOldMessagesAsync_Test()
        {
            //Arrage:
            await InitDictDataAsync();

            var service = new ConversationMsgAppService(statefulServiceContext, stateManager);
            var msg2    = DefaultConversationMsg2.DeepCopy();
            var msg1    = DefaultConversationMsg.DeepCopy();

            //Act:
            var oldMeesage = await service.GetOldMessagesAsync(new GetOldMessagesInput()
            {
                Id          = msg2.ConversationId,
                OldestMsgId = msg2.Id,
            });

            //Assert:
            Assert.AreEqual(1, oldMeesage.Count);
        }
        public async Task SendMessageAsync_Test()
        {
            //Arrage:
            await InitDictDataAsync();

            //Act:
            var service = new ConversationMsgAppService(statefulServiceContext, stateManager);
            var msg     = DefaultConversationMsg.DeepCopy();
            await service.SendMessageAsync(msg);

            //Assert:
            using (var tx = stateManager.CreateTransaction())
            {
                var msgValue = await MessageProccessQueue.TryDequeueAsync(tx);

                var msg2 = msgValue.Value;
                Assert.IsTrue(msgValue.HasValue);
                Assert.IsTrue(msg2.Content == msg.Content);
            }
        }
Beispiel #6
0
        protected async Task InitDictDataAsync()
        {
            await InitDictAsync();

            var conversation = DefaultConversation.DeepCopy(); //need deep copy
            var message1     = DefaultConversationMsg.DeepCopy();
            var message2     = DefaultConversationMsg2.DeepCopy();

            using (var tx = stateManager.CreateTransaction())
            {
                await dictKeyToId.AddOrUpdateAsync(tx, conversation.Key, conversation.Id, (k, v) => conversation.Id);

                await dictIdToEntity.AddOrUpdateAsync(tx, conversation.Id, conversation, (k, v) => conversation);

                await MessageIndexDict.SetAsync(tx, message1.ConversationId, new List <Guid>() { message1.Id, message2.Id });

                await MessageListDict.SetAsync(tx, message1.Id, message1);

                await MessageListDict.SetAsync(tx, message2.Id, message2);

                await tx.CommitAsync();
            }
        }