コード例 #1
0
        public async Task Tesh_PushMsgNotifyAsync_WhenNotHaveConnection()
        {
            var userId         = Guid.NewGuid();
            var conversationId = Guid.NewGuid();
            var msgId          = Guid.NewGuid();

            void configBus(IInMemoryReceiveEndpointConfigurator e)
            {
                e.Handler <SendMessageNotify>(context =>
                {
                    var notify = context.Message;

                    Assert.Fail();

                    return(Task.CompletedTask);
                });

                MapEndpointConverion(e);
            };

            var actor = new TheActor(CreateActorService(CreateBus(configBus)), new ActorId(userId));

            actor.IsInUnitTest = true;

            await actor.PushMsgNotifyAsync(new MessageNotifyDto
            {
                Target         = NotifyTargetType.Conversation,
                TargetId       = conversationId.ToString(),
                TargetCategory = 1,
                LatestMsgId    = msgId,
            });

            var listPushNotify = await actorStateManager.GetStateAsync <List <MessageNotifyDto> >(
                TheActor.MessageListPropertyName);

            Assert.IsTrue(listPushNotify.Count > 0);
            var dto = listPushNotify.Find(o => o.TargetId == conversationId.ToString());

            Assert.IsNotNull(dto);
            Assert.AreEqual(msgId, dto.LatestMsgId);
        }
コード例 #2
0
        public async Task Test_PushMsgNotifyAsync_WhenHaveConnection()
        {
            var userId         = Guid.NewGuid();
            var connectionId   = Guid.NewGuid().ToString("N");
            var conversationId = Guid.NewGuid();
            var msgId          = Guid.NewGuid();

            void configBus(IInMemoryReceiveEndpointConfigurator e)
            {
                e.Handler <SendMessageNotify>(context =>
                {
                    var notify = context.Message;

                    Assert.IsNotNull(notify);
                    Assert.AreEqual(1, notify.Notifies.Count);
                    Assert.AreEqual(conversationId.ToString(), notify.Notifies[0].TargetId);
                    Assert.AreEqual(msgId, notify.Notifies[0].LatestMsgId);
                    Assert.AreEqual(1, notify.Notifies[0].TargetCategory);

                    return(Task.CompletedTask);
                });

                MapEndpointConverion(e);
            };

            var actor = new TheActor(CreateActorService(CreateBus(configBus)), new ActorId(userId));

            actor.IsInUnitTest = true;

            await actor.AddConnectionIdAsync(connectionId);

            await actor.PushMsgNotifyAsync(new MessageNotifyDto
            {
                Target         = NotifyTargetType.Conversation,
                TargetId       = conversationId.ToString(),
                TargetCategory = 1,
                LatestMsgId    = msgId,
            });

            await Task.Delay(500);
        }