コード例 #1
0
        public async Task Publish_diff_when_receiving_another_state_of_the_show()
        {
            var showId             = "3";
            var clientConnectionId = "signalR...";
            var topic = TopicBuilder.BuildTopicFor(showId);

            var fakeSignalR      = Substitute.For <IPublishMessages>();
            var publisherFactory = new PublisherFactory(fakeSignalR);
            IObserveReservedSeats clientProxy = new ClientProxy(showId, clientConnectionId, new List <string>(),
                                                                publisherFactory.GetPublisher());

            // Fake a new state of the show reception
            await clientProxy.Notify(new[] { "A1", "B7" });

            // Check that we published those new seats to the client
            var expectedPublication = new[] { "A1", "B7" };
            await fakeSignalR.Received().SendNewlyReservedSeatsAsync(topic, clientConnectionId,
                                                                     Arg.Is <string[]>(x => expectedPublication.SequenceEqual(x)));


            // Fake a new state of the show reception
            await clientProxy.Notify(new[] { "A1", "B2", "B7", "D99" });

            // Only the diff must be published then
            expectedPublication = new[] { "B2", "D99" };
            await fakeSignalR.Received().SendNewlyReservedSeatsAsync(topic, clientConnectionId,
                                                                     Arg.Is <string[]>(x => expectedPublication.SequenceEqual(x)));
        }
コード例 #2
0
        public async Task <ActionResult> SendNotification(string showId)
        {
            var topic = TopicBuilder.BuildTopicFor(showId);

            await _publisher.SendNewlyReservedSeatsToAllAsync(topic, new[] { "AZ", "ZZ" });

            //await _hubContext.Clients.All.SendAsync(topic, "Super message de ouf");

            return(Ok(""));
        }
コード例 #3
0
        private async Task PublishNewReservedSeats(IEnumerable <string> newlyAddedReservations)
        {
            var topic = TopicBuilder.BuildTopicFor(_showId);

            if (_messagePublisher == null)
            {
                // TEMP: should not happen at runtime!!!!
                _messagePublisher = _publishersFactory();
            }

            // Should we catch here?
            // var publisher = _publishersFactory(); // get a SignalR publisher
            await _messagePublisher.SendNewlyReservedSeatsAsync(topic, _clientConnectionId,
                                                                newlyAddedReservations.ToArray());
        }