Ejemplo n.º 1
0
        public async Task SubscriptionHandlesShouldHaveIdentity()
        {
            var stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null);

            await Silo.CreateGrainAsync <Listener>(1);

            var handlers = await stream.GetAllSubscriptionHandles();

            handlers.Count.Should().Be(1);
            stream.Subscribed.Should().Be(1);


            foreach (var handle in handlers)
            {
                handle.ProviderName.Should().Be("Default");
                handle.HandleId.Should().NotBeEmpty();
                handle.StreamIdentity.Should().NotBeNull();
                handle.StreamIdentity.Namespace.Should().BeNull();
            }

            await handlers[0].UnsubscribeAsync();

            handlers.Count.Should().Be(1);
            stream.Subscribed.Should().Be(0);
        }
Ejemplo n.º 2
0
        public void GrainIsSubscribed()
        {
            var stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null);

            Silo.CreateGrain <Listener>(1);

            stream.Subscribed.Should().Be(1);
        }
Ejemplo n.º 3
0
        public async Task GrainIsSubscribed()
        {
            var stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null);

            await Silo.CreateGrainAsync <Listener>(1);

            stream.Subscribed.Should().Be(1);
        }
Ejemplo n.º 4
0
        public async Task GrainReceives()
        {
            var stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null);

            var grain = Silo.CreateGrain <Listener>(1);

            await stream.OnNextAsync(new ChatMessage("Ding"));

            (await grain.ReceivedCount()).Should().Be(1);
        }
Ejemplo n.º 5
0
        public void IncorrectProbeNamespace()
        {
            var chatty = Silo.CreateGrain <Chatty>(4);

            Silo.AddStreamProbe <ChatMessage>(Guid.Empty, "Wrong");

            const string msg = "Hello Chat";

            chatty.Invoking(p => p.SendChat(msg).Wait()).ShouldNotThrow();
        }
Ejemplo n.º 6
0
        public void IncorrectProbeId()
        {
            var chatty = Silo.CreateGrain <Chatty>(4);

            Silo.AddStreamProbe <ChatMessage>(Guid.NewGuid(), null);

            const string msg = "Hello Chat";

            chatty.Invoking(p => p.SendChat(msg).Wait()).ShouldNotThrow();
        }
Ejemplo n.º 7
0
        public async Task IncorrectProbeNamespace()
        {
            var chatty = await Silo.CreateGrainAsync <Chatty>(4);

            Silo.AddStreamProbe <ChatMessage>(Guid.Empty, "Wrong");

            const string msg = "Hello Chat";

            chatty.Invoking(p => p.SendChat(msg).Wait()).ShouldThrow <Exception>();
        }
Ejemplo n.º 8
0
        public async Task IncorrectProbeId()
        {
            var chatty = await Silo.CreateGrainAsync <Chatty>(4);

            Silo.AddStreamProbe <ChatMessage>(Guid.NewGuid(), null);

            const string msg = "Hello Chat";

            chatty.Invoking(p => p.SendChat(msg).Wait()).Should().Throw <Exception>();
        }
Ejemplo n.º 9
0
        public async Task IncorrectVerifyMessage()
        {
            var chatty = Silo.CreateGrain <Chatty>(4);

            var stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null);

            const string msg = "Hello Chat";

            await chatty.SendChat(msg);

            stream.Invoking(s => s.VerifySend(m => m.Msg == "This is not right")).ShouldThrow <Exception>();
        }
Ejemplo n.º 10
0
        public async Task GrainSentMessages()
        {
            var chatty = Silo.CreateGrain <Chatty>(4);

            var stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null);

            const string msg = "Hello Chat";

            await chatty.SendChat(msg);

            stream.Sends.Should().Be(1);
            stream.VerifySend(m => m.Msg == msg);
        }
Ejemplo n.º 11
0
        public async Task OnGameCreationWhenPlayerIIJoins_Should_StreamEvent()
        {
            var gameId = Guid.NewGuid();
            var sut    = BuildSut(gameId);
            var stream = Silo.AddStreamProbe <PlayerTookSeatII> (gameId, nameof(PlayerTookSeatII));

            var playerId   = Guid.NewGuid();
            var playerSeat = Silo.CreateGrain <SeatII> (id: gameId);
            await playerSeat.JoinGame(playerId);

            stream.Sends.Should().Be(1);
            stream.VerifySend(x => x.PlayerId == playerId);
        }
Ejemplo n.º 12
0
        public async Task GrainGetAllSubscriptionHandles()
        {
            var stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null);

            await Silo.CreateGrainAsync <Listener>(1);

            var handlers = await stream.GetAllSubscriptionHandles();

            handlers.Count.Should().Be(1);
            stream.Subscribed.Should().Be(1);

            await handlers[0].UnsubscribeAsync();

            handlers.Count.Should().Be(1);
            stream.Subscribed.Should().Be(0);
        }
Ejemplo n.º 13
0
        public async Task GrainSentBatchMessages()
        {
            var chatty = await Silo.CreateGrainAsync <Chatty>(4);

            var stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null);

            var msgs = new[] { "Hello Chat", "Goodbye Chat" };

            await chatty.SendChatBatch(msgs);

            stream.Sends.Should().Be((uint)msgs.Length);
            foreach (var msg in msgs)
            {
                stream.VerifySend(m => m.Msg == msg);
            }
        }
Ejemplo n.º 14
0
        public PersistantStreamNotWithinGrainStateTests()
        {
            _stateWithoutHandle = new PersistentListenerStateWithoutHandle();

            _persistentState = new Mock <IPersistentState <PersistentListenerStateWithoutHandle> >();
            _persistentState.SetupGet(o => o.State).Returns(_stateWithoutHandle);

            var mockMapper = new Mock <IAttributeToFactoryMapper <PersistentStateAttribute> >();

            mockMapper.Setup(o =>
                             o.GetFactory(It.IsAny <ParameterInfo>(), It.IsAny <PersistentStateAttribute>()))
            .Returns(context => _persistentState.Object);

            Silo.AddService(mockMapper.Object);

            _stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null, "Default");
        }
Ejemplo n.º 15
0
        public async Task GrainSentBatchMessagesHandlesException()
        {
            var chatty = await Silo.CreateGrainAsync <Chatty>(4);

            var stream       = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null);
            var mockObserver = new Mock <IAsyncObserver <ChatMessage> >();

            mockObserver.Setup(o => o.OnNextAsync(It.IsAny <ChatMessage>(), It.IsAny <StreamSequenceToken>()))
            .Throws <Exception>();

            await stream.SubscribeAsync(mockObserver.Object);

            var msgs = new[] { "Hello Chat", "Goodbye Chat" };

            await Assert.ThrowsAsync <AggregateException>(() => chatty.SendChatBatch(msgs));

            stream.Sends.Should().Be((uint)msgs.Length);
            foreach (var msg in msgs)
            {
                stream.VerifySend(m => m.Msg == msg);
            }
        }