public void IntegerGreaterOrEqualThanFilter()
 {
     IQbservable<StubMessage> qbservable = Observable.Range(18, 20).Select(i => new StubMessage { MessageId = i }).AsQbservable();
     UriQueryDeserializer uriQueryDeserializer = new UriQueryDeserializer();
     IQbservable<StubMessage> filteredQbservable = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc?$filter=MessageId ge 23"));
     Assert.AreEqual(23, filteredQbservable.ToEnumerable().First().MessageId);
 }
 public void IntegerDivisionEqualsFilter()
 {
     IQbservable<StubMessage> qbservable = Observable.Range(15, 3).Select(i => new StubMessage { MessageId = i }).AsQbservable();
     UriQueryDeserializer uriQueryDeserializer = new UriQueryDeserializer();
     IQbservable<StubMessage> filteredQbservable = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc?$filter=(MessageId div 2) eq 8"));
     Assert.AreEqual(16, filteredQbservable.ToEnumerable().First().MessageId);
 }
 public void EmptyFilterProducesUnfilteredObservable()
 {
     IQbservable<StubMessage> qbservable = Observable.Range(1, 10).Select(i => new StubMessage { MessageId = i }).AsQbservable();
     UriQueryDeserializer uriQueryDeserializer = new UriQueryDeserializer();
     IQbservable<StubMessage> filteredQbservable = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc"));
     Assert.AreEqual(1, filteredQbservable.ToEnumerable().First().MessageId);
 }
 public void CastFilter()
 {
     IQbservable<StubMessage> qbservable = Observable.Range(1, 3).Select(i => new StubMessage { MessageId = i, ComplexProperty = new StubMessage.ComplexType() { Foo = i.ToString(CultureInfo.InvariantCulture) } }).AsQbservable();
     UriQueryDeserializer uriQueryDeserializer = new UriQueryDeserializer();
     IQbservable<StubMessage> filteredQbservable = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc?$filter=MessageId gt cast(3,'Edm.Int32')"));
     Assert.AreEqual(2, filteredQbservable.ToEnumerable().First().MessageId);
 }
Beispiel #5
0
        public IObservable <TResult> GetEventStream <TSource, TResult>(EventQuery <TSource, TResult> query)
        {
            Uri = new QueryUriProvider().GetQueryUri(query);

            UriQueryDeserializer deserializer = new UriQueryDeserializer();


            return(deserializer.Deserialize(((IObservable <TSource>)Source).AsQbservable(), Uri) as IQbservable <TResult>);
        }
        public void IntegerLessThanFilter()
        {
            IQbservable <StubMessage> qbservable = new[] { 20, 19, 18, 17, 16 }.ToObservable().Select(i => new StubMessage {
                MessageId = i
            }).AsQbservable();
            UriQueryDeserializer      uriQueryDeserializer = new UriQueryDeserializer();
            IQbservable <StubMessage> filteredQbservable   = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc?$filter=MessageId lt 18"));

            Assert.AreEqual(17, filteredQbservable.ToEnumerable().First().MessageId);
        }
        public void IntegerGreaterOrEqualThanFilter()
        {
            IQbservable <StubMessage> qbservable = Observable.Range(18, 20).Select(i => new StubMessage {
                MessageId = i
            }).AsQbservable();
            UriQueryDeserializer      uriQueryDeserializer = new UriQueryDeserializer();
            IQbservable <StubMessage> filteredQbservable   = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc?$filter=MessageId ge 23"));

            Assert.AreEqual(23, filteredQbservable.ToEnumerable().First().MessageId);
        }
        public void EmptyFilterProducesUnfilteredObservable()
        {
            IQbservable <StubMessage> qbservable = Observable.Range(1, 10).Select(i => new StubMessage {
                MessageId = i
            }).AsQbservable();
            UriQueryDeserializer      uriQueryDeserializer = new UriQueryDeserializer();
            IQbservable <StubMessage> filteredQbservable   = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc"));

            Assert.AreEqual(1, filteredQbservable.ToEnumerable().First().MessageId);
        }
        public void SkipQueryParameterSkipsFirstNResultsReturned()
        {
            IQbservable <StubMessage> qbservable = Observable.Range(1, 15).Select(i => new StubMessage {
                MessageId = i
            }).AsQbservable();
            UriQueryDeserializer      uriQueryDeserializer = new UriQueryDeserializer();
            IQbservable <StubMessage> filteredQbservable   = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc?$skip=5"));

            Assert.AreEqual(6, filteredQbservable.ToEnumerable().First().MessageId);
        }
        public void IntegerDivisionEqualsFilter()
        {
            IQbservable <StubMessage> qbservable = Observable.Range(15, 3).Select(i => new StubMessage {
                MessageId = i
            }).AsQbservable();
            UriQueryDeserializer      uriQueryDeserializer = new UriQueryDeserializer();
            IQbservable <StubMessage> filteredQbservable   = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc?$filter=(MessageId div 2) eq 8"));

            Assert.AreEqual(16, filteredQbservable.ToEnumerable().First().MessageId);
        }
        public void CastFilter()
        {
            IQbservable <StubMessage> qbservable = Observable.Range(1, 3).Select(i => new StubMessage {
                MessageId = i, ComplexProperty = new StubMessage.ComplexType()
                {
                    Foo = i.ToString(CultureInfo.InvariantCulture)
                }
            }).AsQbservable();
            UriQueryDeserializer      uriQueryDeserializer = new UriQueryDeserializer();
            IQbservable <StubMessage> filteredQbservable   = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc?$filter=MessageId gt cast(3,'Edm.Int32')"));

            Assert.AreEqual(2, filteredQbservable.ToEnumerable().First().MessageId);
        }
Beispiel #12
0
        /// <summary>
        /// Called when [connected async].
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="connectionId">The connection id.</param>
        /// <returns></returns>
        protected override Task OnConnected(IRequest request, string connectionId)
        {
            return(Task.Factory.StartNew(() => {
                logger.Log(Logger.LogLevel.Debug, "Request URI {0}", request.Url);
                IDisposable currentSubscription;
                if (subscriptions.ContainsKey(connectionId) && subscriptions.TryGetValue(connectionId, out currentSubscription))
                {
                    return;
                }
                if (request.Url == null)
                {
                    return;
                }
                string resourceName = queryDeserializer.GetResourceName(new Uri(request.Url.ToString().Replace("/connect", "")));

                PropertyInfo propertyInfo = typeof(T).GetProperty(resourceName);
                if (propertyInfo == null)
                {
                    throw new NotImplementedException("Need exception type");
                }

                Type messageType = propertyInfo.PropertyType.GetInterfaces().Concat(new[] { propertyInfo.PropertyType }).Where(
                    iface => iface.IsGenericType && iface.GetGenericTypeDefinition() == typeof(IQbservable <>)).Select(iface => iface.GetGenericArguments()[0]).FirstOrDefault();

                if (messageType == null)
                {
                    throw new NotImplementedException("Need exception type");
                }

                IQbservable qbservable = queryDeserializer.Deserialize(propertyInfo.GetValue(context, null) as IQbservable, messageType, request.Url);

                Func <IQbservable <int>, string, IDisposable> dummyCreateSubscription = CreateSubscription;

                IDisposable subscription = dummyCreateSubscription.Method.GetGenericMethodDefinition().MakeGenericMethod(new[] { messageType }).Invoke(
                    this, new object[] { qbservable, connectionId }) as IDisposable;

                subscriptions.AddOrUpdate(connectionId, subscription, (x, y) => subscription);

                logger.Log(Logger.LogLevel.Debug, string.Format("New client {0} connected to server. Total connected clients {1}", connectionId, subscriptions.Count));
            }));
        }
 public void IntegerLessOrEqualThanFilter()
 {
     IQbservable<StubMessage> qbservable = new[] { 20, 19, 18, 17, 16 }.ToObservable().Select(i => new StubMessage { MessageId = i }).AsQbservable();
     UriQueryDeserializer uriQueryDeserializer = new UriQueryDeserializer();
     IQbservable<StubMessage> filteredQbservable = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc?$filter=MessageId le 18"));
     Assert.AreEqual(18, filteredQbservable.ToEnumerable().First().MessageId);
 }
 public void TopQueryParameterLimitsResultsReturned()
 {
     IQbservable<StubMessage> qbservable = Observable.Range(1, 15).Select(i => new StubMessage { MessageId = i }).AsQbservable();
     UriQueryDeserializer uriQueryDeserializer = new UriQueryDeserializer();
     IQbservable<StubMessage> filteredQbservable = uriQueryDeserializer.Deserialize(qbservable, new Uri("http://foo.bar/qux.svc?$top=5"));
     Assert.AreEqual(5, filteredQbservable.ToEnumerable().Last().MessageId);
 }