Exemple #1
0
        public void Single_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.Execute <SDataCollection <object> >(It.IsAny <SDataParameters>()))
            .Returns(responseMock1.Object)
            .Callback((SDataParameters parms) => parmsList.Add(parms));
            var responseMock2 = new Mock <ISDataResults <SDataCollection <Contact> > >();

            responseMock2.Setup(x => x.Content).Returns(CreateCollection(new[] { expected }, 10));
            clientMock.Setup(x => x.Execute <SDataCollection <Contact> >(It.IsAny <SDataParameters>()))
            .Returns(responseMock2.Object)
            .Callback((SDataParameters parms) => parmsList.Add(parms));
            var executor = new SDataQueryExecutor(clientMock.Object);
            var builder  = CreateQueryBuilder <Contact>(true);

            builder.AddResultOperator(new LastResultOperator(false));
            var result = executor.ExecuteSingle <Contact>(builder.Build(), false);

            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));
        }
Exemple #2
0
        public void Single_Single_MultipleResults_Test()
        {
            var parmsList = new List <SDataParameters>();
            var expected  = new Contact();
            var client    = CreateClient(parmsList, CreateCollection(new[] { expected }, 2));
            var executor  = new SDataQueryExecutor(client);
            var builder   = CreateQueryBuilder <Contact>(true);

            builder.AddResultOperator(new SingleResultOperator(false));
            Assert.That(() => executor.ExecuteSingle <Contact>(builder.Build(), false), Throws.InstanceOf <SDataClientException>());
        }
Exemple #3
0
        public void Single_Last_Unordered_Empty_Test()
        {
            var parmsList = new List <SDataParameters>();
            var client    = CreateClient(parmsList, CreateCollection <object>(null, 0));
            var executor  = new SDataQueryExecutor(client);
            var builder   = CreateQueryBuilder <Contact>(true);

            builder.AddResultOperator(new LastResultOperator(true));
            var result = executor.ExecuteSingle <Contact>(builder.Build(), false);

            Assert.That(parmsList[0].Count, Is.EqualTo(0));
            Assert.That(result, Is.Null);
        }
Exemple #4
0
        public void Single_Single_Test()
        {
            var parmsList = new List <SDataParameters>();
            var expected  = new Contact();
            var client    = CreateClient(parmsList, CreateCollection(new[] { expected }, 1));
            var executor  = new SDataQueryExecutor(client);
            var builder   = CreateQueryBuilder <Contact>(true);

            builder.AddResultOperator(new SingleResultOperator(false));
            var result = executor.ExecuteSingle <Contact>(builder.Build(), false);

            Assert.That(parmsList[0].Count, Is.EqualTo(1));
            Assert.That(result, Is.EqualTo(expected));
        }
Exemple #5
0
        public void Single_First_Take_Zero_Test()
        {
            var parmsList = new List <SDataParameters>();
            var client    = CreateClient <Contact>(parmsList);
            var executor  = new SDataQueryExecutor(client);
            var builder   = CreateQueryBuilder <Contact>(true);

            builder.AddResultOperator(new TakeResultOperator(Expression.Constant(0)));
            builder.AddResultOperator(new FirstResultOperator(true));
            var result = executor.ExecuteSingle <Contact>(builder.Build(), false);

            Assert.That(parmsList, Is.Empty);
            Assert.That(result, Is.Null);
        }
Exemple #6
0
        public void Single_Last_Ordered_Test()
        {
            var parmsList = new List <SDataParameters>();
            var expected  = new Contact();
            var client    = CreateClient(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 LastResultOperator(false));
            var result = executor.ExecuteSingle <Contact>(builder.Build(), false);

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