Ejemplo n.º 1
0
    public void TestCollectionGetPage()
    {
      var getPageEntities = new List<GetPageEntity>();

      for( int i = 10; i < 30; i++ )
      {
        var entity = new GetPageEntity {Name = "name#" + i, Age = 20 + i};
        Backendless.Persistence.Save( entity );

        if( i > 19 && i < 30 )
          getPageEntities.Add( entity );

        Thread.Sleep( 1000 );
      }

      var dataQuery = new BackendlessDataQuery( new QueryOptions( 10, 0, "Age" ) );
      var collection = Backendless.Persistence.Of<GetPageEntity>().Find( dataQuery ).GetPage( 10, 10 );

      Assert.IsNotNull( collection, "Next page returned a null object" );
      Assert.IsNotNull( collection.GetCurrentPage(), "Next page contained a wrong data size" );
      Assert.AreEqual( getPageEntities.Count, collection.GetCurrentPage().Count, "Next page returned a wrong size" );

      foreach( GetPageEntity entity in getPageEntities )
        Assert.IsTrue( collection.GetCurrentPage().Contains( entity ), "Server result didn't contain expected entity" );
    }
Ejemplo n.º 2
0
        public BackendlessDataQuery Build()
        {
            BackendlessDataQuery dataQuery = pagedQueryBuilder.Build();

            dataQuery.QueryOptions = queryOptionsBuilder.Build();
            dataQuery.Properties   = properties;
            dataQuery.WhereClause  = whereClause;

            return(dataQuery);
        }
Ejemplo n.º 3
0
        internal BackendlessDataQuery Build()
        {
            ValidateOffset(offset);
            ValidatePageSize(pageSize);

            BackendlessDataQuery dataQuery = new BackendlessDataQuery();

            dataQuery.PageSize = pageSize;
            dataQuery.Offset   = offset;

            return(dataQuery);
        }
Ejemplo n.º 4
0
        public BackendlessDataQuery Build()
        {
            BackendlessDataQuery dataQuery = pagedQueryBuilder.Build();

            dataQuery.QueryOptions      = queryOptionsBuilder.Build();
            dataQuery.Properties        = properties;
            dataQuery.ExcludeProperties = excludeProperties;
            dataQuery.WhereClause       = whereClause;
            dataQuery.GroupBy           = groupBy;
            dataQuery.HavingClause      = havingClause;
            return(dataQuery);
        }
Ejemplo n.º 5
0
        public void TestCollectionGetPage()
        {
            RunAndAwait( () =>
            {
              var getPageEntities = new List<GetPageEntityAsync>();
              var latch = new CountdownEvent( 20 );
              for( int i = 10; i < 30; i++ )
              {
            var entity = new GetPageEntityAsync {Name = "name#" + i, Age = 20 + i};
            Backendless.Persistence.Save( entity,
                                          new AsyncCallback<GetPageEntityAsync>( response => latch.Signal(), fault =>
                                            {
                                              for( int j = 0; j < latch.CurrentCount; j++ )
                                                latch.Signal();
                                            } ) );

            if( i > 19 && i < 30 )
              getPageEntities.Add( entity );
              }
              latch.Wait();

              var dataQuery = new BackendlessDataQuery( new QueryOptions( 10, 0, "Age" ) );
              Backendless.Persistence.Of<GetPageEntityAsync>()
                     .Find( dataQuery,
                            new ResponseCallback<BackendlessCollection<GetPageEntityAsync>>( this )
                              {
                                ResponseHandler =
                                  response =>
                                  response.GetPage( 10, 10,
                                                    new ResponseCallback<BackendlessCollection<GetPageEntityAsync>>( this )
                                                      {
                                                        ResponseHandler = collection =>
                                                          {
                                                            Assert.IsNotNull( collection, "Next page returned a null object" );
                                                            Assert.IsNotNull( collection.GetCurrentPage(),
                                                                              "Next page contained a wrong data size" );
                                                            Assert.AreEqual( getPageEntities.Count,
                                                                             collection.GetCurrentPage().Count,
                                                                             "Next page returned a wrong size" );

                                                            foreach( GetPageEntityAsync entity in getPageEntities )
                                                              Assert.IsTrue(
                                                                collection.GetCurrentPage().Contains( entity ),
                                                                "Server result didn't contain expected entity" );

                                                            CountDown();
                                                          }
                                                      } )
                              } );
            } );
        }
Ejemplo n.º 6
0
        public BackendlessDataQuery Build()
        {
            if (string.IsNullOrEmpty(relationName))
            {
                throw new System.Exception("Unable to build a query for LoadRelations. Relation name is not set");
            }

            BackendlessDataQuery dataQuery    = pagedQueryBuilder.Build();
            QueryOptions         queryOptions = new QueryOptions();

            queryOptions.Related   = new List <String>(new[] { relationName });
            dataQuery.QueryOptions = queryOptions;
            return(dataQuery);
        }
Ejemplo n.º 7
0
    public void TestFindWithWhereEntities()
    {
      var entities = new List<FindWithWhereEntity>();

      for( int i = 0; i < 10; i++ )
      {
        var findWithWhereEntity = new FindWithWhereEntity();
        findWithWhereEntity.Name = "bot_#" + i;
        findWithWhereEntity.Age = 20 + i;

        Backendless.Persistence.Save( findWithWhereEntity );

        if( i < 5 )
          entities.Add( findWithWhereEntity );
      }

      BackendlessDataQuery dataQuery = new BackendlessDataQuery( "Age < 25" );
      BackendlessCollection<FindWithWhereEntity> backendlessCollection =
        Backendless.Persistence.Of<FindWithWhereEntity>().Find( dataQuery );

      AssertArgumentAndResultCollections( entities, backendlessCollection );
    }
Ejemplo n.º 8
0
        public void TestFindWithNullPropertiesQuery()
        {
            var findWithPropertiesEntity = new FindWithPropertiesEntity {Name = "bot_#foobar", Age = 20};
              Backendless.Persistence.Save( findWithPropertiesEntity );

              List<String> properties = null;
              var dataQuery = new BackendlessDataQuery( properties );

              BackendlessCollection<FindWithPropertiesEntity> backendlessCollection =
            Backendless.Persistence.Of<FindWithPropertiesEntity>().Find( dataQuery );

              Assert.IsTrue( backendlessCollection.TotalObjects > 0, "Server found wrong number of objects" );
              Assert.IsTrue( backendlessCollection.GetCurrentPage().Count > 0, "Server returned wrong number of objects" );

              foreach( FindWithPropertiesEntity entity in backendlessCollection.GetCurrentPage() )
              {
            Assert.IsTrue( entity.Age > 0, "Server result contained wrong age field value" );
            Assert.IsNotNull( entity.Name, "Server result contained non null field" );
            Assert.IsNotNull( entity.ObjectId, "Server result contained non null field" );
            Assert.IsNotNull( entity.Created, "Server result contained non null field" );
              }
        }
Ejemplo n.º 9
0
        public void TestFindWithMissingProperties()
        {
            var findWithPropertiesEntity = new FindWithPropertiesEntity {Name = "bot_#foobar", Age = 20};
              Backendless.Persistence.Save( findWithPropertiesEntity );

              var properties = new List<string> {"foobar"};
              var dataQuery = new BackendlessDataQuery( properties );

              try
              {
            Backendless.Persistence.Of<FindWithPropertiesEntity>().Find( dataQuery );
            Assert.Fail( "Server didn't throw an exception" );
              }
              catch( System.Exception e )
              {
            CheckErrorCode( 1006, e );
              }
        }
Ejemplo n.º 10
0
        public void TestFindWithWhereEntities()
        {
            RunAndAwait( () =>
            {
              var entities = new List<FindWithWhereEntityAsync>();
              var latch = new CountdownEvent( 10 );

              for( int i = 0; i < 10; i++ )
              {
            var findWithWhereEntity = new FindWithWhereEntityAsync();
            findWithWhereEntity.Name = "bot_#" + i;
            findWithWhereEntity.Age = 20 + i;

            Backendless.Persistence.Save( findWithWhereEntity, new AsyncCallback<FindWithWhereEntityAsync>( response => latch.Signal(), fault =>
                {
                  for( int j = 0; j < latch.CurrentCount; j++ )
                    latch.Signal();

                  FailCountDownWith( fault );
                } ) );

            if (i < 5)
              entities.Add(findWithWhereEntity);
              }
              latch.Wait();

              BackendlessDataQuery dataQuery = new BackendlessDataQuery( "Age < 25" );
              Backendless.Persistence.Of<FindWithWhereEntityAsync>()
                     .Find( dataQuery,
                            new ResponseCallback<BackendlessCollection<FindWithWhereEntityAsync>>( this )
                              {
                                ResponseHandler =
                                  backendlessCollection =>
                                  AssertArgumentAndResultCollections( entities, backendlessCollection )
                              } );
            } );
        }
Ejemplo n.º 11
0
        public void TestFindWithNullPropertiesQuery()
        {
            RunAndAwait( () =>
            {
              var findWithPropertiesEntity = new FindWithPropertiesEntityAsync {Name = "bot_#foobar", Age = 20};
              Backendless.Persistence.Save( findWithPropertiesEntity,
                                        new ResponseCallback<FindWithPropertiesEntityAsync>( this )
                                          {
                                            ResponseHandler = response =>
                                              {
                                                List<String> properties = null;
                                                var dataQuery = new BackendlessDataQuery( properties );

                                                Backendless.Persistence.Of<FindWithPropertiesEntityAsync>()
                                                           .Find( dataQuery,
                                                                  new ResponseCallback
                                                                    <BackendlessCollection<FindWithPropertiesEntityAsync>>
                                                                    ( this )
                                                                    {
                                                                      ResponseHandler = backendlessCollection =>
                                                                        {
                                                                          Assert.IsTrue(
                                                                            backendlessCollection.TotalObjects > 0,
                                                                            "Server found wrong number of objects" );
                                                                          Assert.IsTrue(
                                                                            backendlessCollection.GetCurrentPage().Count > 0,
                                                                            "Server returned wrong number of objects" );

                                                                          foreach( FindWithPropertiesEntityAsync entity in
                                                                            backendlessCollection.GetCurrentPage() )
                                                                          {
                                                                            Assert.IsTrue( entity.Age > 0,
                                                                                           "Server result contained wrong age field value" );
                                                                            Assert.IsNotNull( entity.Name,
                                                                                              "Server result contained non null field" );
                                                                            Assert.IsNotNull( entity.ObjectId,
                                                                                              "Server result contained non null field" );
                                                                            Assert.IsNotNull( entity.Created,
                                                                                              "Server result contained non null field" );
                                                                          }

                                                                          CountDown();
                                                                        }
                                                                    } );
                                              }
                                          } );
            } );
        }
Ejemplo n.º 12
0
        public void TestFindWithMissingProperties()
        {
            RunAndAwait( () =>
            {
              var findWithPropertiesEntity = new FindWithPropertiesEntityAsync {Name = "bot_#foobar", Age = 20};
              Backendless.Persistence.Save( findWithPropertiesEntity,
                                        new ResponseCallback<FindWithPropertiesEntityAsync>( this )
                                          {
                                            ResponseHandler = response =>
                                              {
                                                var properties = new List<string> {"foobar"};
                                                var dataQuery = new BackendlessDataQuery( properties );

                                                Backendless.Persistence.Of<FindWithPropertiesEntityAsync>()
                                                           .Find( dataQuery,
                                                                  new AsyncCallback
                                                                    <BackendlessCollection<FindWithPropertiesEntityAsync>>
                                                                    ( collection =>
                                                                      Assert.Fail( "Server didn't throw an exception" ),
                                                                      fault => CheckErrorCode( 1006, fault ) ) );
                                              }
                                          } );
            } );
        }
 public TaskModel GetObjectFromTable(string query)
 {
     BackendlessDataQuery dataQuery = new BackendlessDataQuery(query) { QueryOptions = new QueryOptions() };
     return Backendless.Data.Find<TaskModel>(dataQuery).Data[0];
 }
 public int GetNumberOfObjectsFromTable(string query)
 {
     BackendlessDataQuery dataQuery = new BackendlessDataQuery(query) { QueryOptions = new QueryOptions() };
     return Backendless.Data.Of<TaskModel>().Find(dataQuery).TotalObjects;
 }
 public List<TaskModel> GetListOfObjectsFromTable(string query)
 {
     BackendlessDataQuery dataQuery = new BackendlessDataQuery(query) { QueryOptions = new QueryOptions() };
     return Backendless.Persistence.Of<TaskModel>().Find(dataQuery).Data;
 }
 public IEnumerable<Users> GetListOfAllUsers()
 {
     BackendlessDataQuery dataQuery = new BackendlessDataQuery("name LIKE '%'") { QueryOptions = new QueryOptions() };
     return Backendless.Persistence.Of<Users>().Find(dataQuery).Data;
 }