Esempio n. 1
0
        public async Task Can_write_to_stream()
        {
            ////Arrange
            var service = new CitylineService(new[] { new SampleProvider() });
            var stream  = new MemoryStream();
            var cancellationTokenSource = new CancellationTokenSource();

            cancellationTokenSource.CancelAfter(1000);

            ////Act
            await service.WriteStream(stream, new CitylineRequest(), null, cancellationTokenSource.Token);

            ////Assert
            stream.Position = 0;
            string eventName;
            string eventData;
            string eventTicket;

            using (var reader = new StreamReader(stream)) {
                eventTicket = await reader.ReadLineAsync();

                eventName = await reader.ReadLineAsync();

                eventData = await reader.ReadLineAsync();
            }

            Assert.AreEqual("event: sample", eventName);
        }
Esempio n. 2
0
        public async Task StartStream(Cityline.CitylineRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var context = new Context {
                RequestUrl = new Uri(Request.GetEncodedUrl()), User = User
            };

            Response.Headers.Add("content-type", "text/event-stream");
            await _citylineService.WriteStream(Response.Body, request, context, cancellationToken);
        }