コード例 #1
0
        public async Task Test_AddConnectionIdAsync_RemoveConnectionIdAsync()
        {
            var userId       = Guid.NewGuid();
            var connectionId = Guid.NewGuid().ToString("N");

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

            actor.IsInUnitTest = true;

            await actor.AddConnectionIdAsync(connectionId);

            var connectionIds = await actorStateManager.GetStateAsync <List <string> >(TheActor.ConnectionIdListPropertyName);

            Assert.IsTrue(connectionIds.Count == 1);  //添加成功

            await actor.RemoveConnectionIdAsync(Guid.NewGuid().ToString("N"));

            connectionIds = await actorStateManager.GetStateAsync <List <string> >(TheActor.ConnectionIdListPropertyName);

            Assert.IsTrue(connectionIds.Count == 1); //没有被删除掉

            await actor.RemoveConnectionIdAsync(connectionId);

            connectionIds = await actorStateManager.GetStateAsync <List <string> >(TheActor.ConnectionIdListPropertyName);

            Assert.IsTrue(connectionIds == null || connectionIds.Count == 0); //删除掉
        }
コード例 #2
0
        public override string GetStepParameters()
        {
            var parameters = new List <string>();

            parameters.Add(GlobalId != null ? GlobalId.ToStepValue() : "$");
            parameters.Add(OwnerHistory != null ? OwnerHistory.ToStepValue() : "$");
            parameters.Add(Name != null ? Name.ToStepValue() : "$");
            parameters.Add(Description != null ? Description.ToStepValue() : "$");
            parameters.Add(ObjectType != null ? ObjectType.ToStepValue() : "$");
            parameters.Add(TheActor != null ? TheActor.ToStepValue() : "$");

            return(string.Join(", ", parameters.ToArray()));
        }
コード例 #3
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);
        }
コード例 #4
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);
        }