Пример #1
0
        public void SingleAsync_Last_Unordered_Empty_Test()
        {
            var parmsList = new List <SDataParameters>();
            var client    = CreateClientAsync(parmsList, CreateCollection <object>(null, 0));
            var executor  = new SDataQueryExecutor(client);
            var builder   = CreateQueryBuilder <Contact>(true);

            builder.AddResultOperator(new LastAsyncResultOperator(true, CancellationToken.None));
            var result = executor.ExecuteSingleAsync <Contact>(builder.Build(), CancellationToken.None).Result;

            Assert.That(parmsList[0].Count, Is.EqualTo(0));
            Assert.That(result, Is.Null);
        }
Пример #2
0
        public void SingleAsync_Single_Test()
        {
            var parmsList = new List <SDataParameters>();
            var expected  = new Contact();
            var client    = CreateClientAsync(parmsList, CreateCollection(new[] { expected }, 1));
            var executor  = new SDataQueryExecutor(client);
            var builder   = CreateQueryBuilder <Contact>(true);

            builder.AddResultOperator(new SingleAsyncResultOperator(false, CancellationToken.None));
            var result = executor.ExecuteSingleAsync <Contact>(builder.Build(), CancellationToken.None).Result;

            Assert.That(parmsList[0].Count, Is.EqualTo(1));
            Assert.That(result, Is.EqualTo(expected));
        }
Пример #3
0
        public void SingleAsync_First_Take_Zero_Test()
        {
            var parmsList = new List <SDataParameters>();
            var client    = CreateClientAsync <Contact>(parmsList);
            var executor  = new SDataQueryExecutor(client);
            var builder   = CreateQueryBuilder <Contact>(true);

            builder.AddResultOperator(new TakeResultOperator(Expression.Constant(0)));
            builder.AddResultOperator(new FirstAsyncResultOperator(true, CancellationToken.None));
            var result = executor.ExecuteSingleAsync <Contact>(builder.Build(), CancellationToken.None).Result;

            Assert.That(parmsList, Is.Empty);
            Assert.That(result, Is.Null);
        }
Пример #4
0
        public void SingleAsync_Last_Unordered_Test()
        {
            var parmsList   = new List <SDataParameters>();
            var expected    = new Contact();
            var clientMock  = new Mock <ISDataClient>();
            var requestMock = new Mock <SDataParameters>();

            requestMock.SetupAllProperties();
            var responseMock1 = new Mock <ISDataResults <SDataCollection <object> > >();

            responseMock1.Setup(x => x.Content).Returns(CreateCollection <object>(null, 10));
            clientMock.Setup(x => x.ExecuteAsync <SDataCollection <object> >(It.IsAny <SDataParameters>(), CancellationToken.None))
            .Returns(() =>
            {
                var taskSource = new TaskCompletionSource <ISDataResults <SDataCollection <object> > >();
                taskSource.SetResult(responseMock1.Object);
                return(taskSource.Task);
            })
            .Callback((SDataParameters parms, CancellationToken cancel) => parmsList.Add(parms));
            var responseMock2 = new Mock <ISDataResults <SDataCollection <Contact> > >();

            responseMock2.Setup(x => x.Content).Returns(CreateCollection(new[] { expected }, 10));
            clientMock.Setup(x => x.ExecuteAsync <SDataCollection <Contact> >(It.IsAny <SDataParameters>(), CancellationToken.None))
            .Returns(() =>
            {
                var taskSource = new TaskCompletionSource <ISDataResults <SDataCollection <Contact> > >();
                taskSource.SetResult(responseMock2.Object);
                return(taskSource.Task);
            })
            .Callback((SDataParameters parms, CancellationToken cancel) => parmsList.Add(parms));
            var executor = new SDataQueryExecutor(clientMock.Object);
            var builder  = CreateQueryBuilder <Contact>(true);

            builder.AddResultOperator(new LastAsyncResultOperator(false, CancellationToken.None));
            var result = executor.ExecuteSingleAsync <Contact>(builder.Build(), CancellationToken.None).Result;

            Assert.That(parmsList[0].Count, Is.EqualTo(0));
            Assert.That(parmsList[1].Count, Is.EqualTo(1));
            Assert.That(parmsList[1].StartIndex, Is.EqualTo(10));
            Assert.That(result, Is.EqualTo(expected));
        }
Пример #5
0
        public void SingleAsync_Last_Ordered_Test()
        {
            var parmsList = new List <SDataParameters>();
            var expected  = new Contact();
            var client    = CreateClientAsync(parmsList, CreateCollection(new[] { expected }, 10));
            var executor  = new SDataQueryExecutor(client);
            var builder   = CreateQueryBuilder <Contact>(true);

            builder.AddClause(new OrderByClause
            {
                Orderings =
                {
                    new Ordering(((Expression <Func <Contact, string> >)(c => c.FirstName)).Body, OrderingDirection.Asc)
                }
            });
            builder.AddResultOperator(new LastAsyncResultOperator(false, CancellationToken.None));
            var result = executor.ExecuteSingleAsync <Contact>(builder.Build(), CancellationToken.None).Result;

            Assert.That(parmsList[0].Count, Is.EqualTo(1));
            Assert.That(parmsList[0].OrderBy, Is.EqualTo("FirstName desc"));
            Assert.That(result, Is.EqualTo(expected));
        }