Esempio n. 1
0
    public User GetUserByEmail(DfpUser user, string email) {
      UserService userService = (UserService) user.GetService(DfpService.v201502.UserService);

      // Create a Statement to get all users sorted by name.
      Statement statement = new Statement();
      statement.query = string.Format("where email = '{0}' LIMIT 1", email);

      UserPage page = userService.getUsersByStatement(statement);

      if (page.results != null && page.results.Length > 0) {
        return page.results[0];
      } else {
        return null;
      }
    }
 private static bool StatementsAreEqual(Statement s1, Statement s2) {
   // Assumes both Statements are non-null and have non-null properties
   if (String.Compare(s1.query, s2.query, true) != 0) {
     return false;
   }
   if (s1.values.Length != s2.values.Length) {
     return false;
   }
   // Assumes Statement values are in the same order
   for (int i = 0; i < s1.values.Length; i++) {
     if (!StringValueMapEntriesAreEqual(s1.values[i], s2.values[i])) {
       return false;
     }
   }
   return true;
 }
Esempio n. 3
0
 public virtual UpdateResult performAdExclusionRuleAction(AdExclusionRuleAction adExclusionRuleAction, Statement filterStatement) {
   object[] results = this.Invoke("performAdExclusionRuleAction", new object[] { adExclusionRuleAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
    public void TestAllStatementBuilderPartialFunctions() {
      StatementBuilder statementBuilder = new StatementBuilder()
          .Select("Name, Id")
          .From("Geo_Target")
          .Where("Targetable = :targetable")
          .OrderBy("Id DESC")
          .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .Offset(0)
          .AddValue("targetable", true)
          .IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT)
          .RemoveLimitAndOffset();
      Assert.AreEqual(null, statementBuilder.GetOffset());

      Statement expectedStatement = new Statement();
      expectedStatement.query = "SELECT Name, Id FROM Geo_Target"
          + " WHERE Targetable = :targetable ORDER BY Id DESC";
      String_ValueMapEntry targetableEntry = new String_ValueMapEntry();
      targetableEntry.key = "targetable";
      BooleanValue targetableValue = new BooleanValue();
      targetableValue.value = true;
      targetableEntry.value = targetableValue;
      expectedStatement.values = new String_ValueMapEntry[] {targetableEntry};
      Assert.True(StatementsAreEqual(expectedStatement, statementBuilder.ToStatement()));
    }
    public void TestStatementBuilderBasicStatement() {
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("ID = 1");

      Statement expectedStatement = new Statement();
      expectedStatement.query = "WHERE ID = 1";
      expectedStatement.values = new String_ValueMapEntry[0];

      Assert.True(StatementsAreEqual(expectedStatement,
                                     statementBuilder.ToStatement()));
    }
    public void TestPerformLineItemCreativeAssociationAction() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE lineItemId = '{0}' LIMIT 1", lineItemId3);

      DeactivateLineItemCreativeAssociations action = new DeactivateLineItemCreativeAssociations();

      UpdateResult result = null;
      Assert.DoesNotThrow(delegate() {
        result = licaService.performLineItemCreativeAssociationAction(action, statement);
      });

      Assert.NotNull(result);
      Assert.AreEqual(result.numChanges, 1);
    }
    public void TestPerformAdUnitAction() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE id = '{0}' LIMIT 1", adUnit1.id);

      UpdateResult result = null;
      Assert.DoesNotThrow(delegate() {
        result = inventoryService.performAdUnitAction(new DeactivateAdUnits(), statement);
      });

      Assert.NotNull(result);
      Assert.AreEqual(result.numChanges, 1);
    }
    public void TestUpdateUsers() {
      Statement statement = new Statement();
      statement.query = String.Format("WHERE id = {0} LIMIT 1", salespersonId);
      User user = userService.getUsersByStatement(statement).results[0];
      user.preferredLocale = (user.preferredLocale == "fr_FR")? "en_US" : "fr_FR";

      User[] newUsers = null;

      Assert.DoesNotThrow(delegate() {
        newUsers = userService.updateUsers(new User[] {user});
      });

      Assert.NotNull(newUsers);
      Assert.AreEqual(newUsers.Length, 1);
      Assert.AreEqual(newUsers[0].id, user.id);
      Assert.AreEqual(newUsers[0].preferredLocale, user.preferredLocale);
    }
Esempio n. 9
0
 public virtual CreativeSetPage getCreativeSetsByStatement(Statement statement) {
   object[] results = this.Invoke("getCreativeSetsByStatement", new object[] { statement });
   return ((CreativeSetPage) (results[0]));
 }
Esempio n. 10
0
 public virtual UpdateResult performProposalLineItemAction(ProposalLineItemAction proposalLineItemAction, Statement filterStatement) {
   object[] results = this.Invoke("performProposalLineItemAction", new object[] { proposalLineItemAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
Esempio n. 11
0
 public virtual ProposalLineItemPage getProposalLineItemsByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getProposalLineItemsByStatement", new object[] { filterStatement });
   return ((ProposalLineItemPage) (results[0]));
 }
Esempio n. 12
0
 public virtual UpdateResult performLineItemCreativeAssociationAction(LineItemCreativeAssociationAction lineItemCreativeAssociationAction, Statement filterStatement) {
   object[] results = this.Invoke("performLineItemCreativeAssociationAction", new object[] { lineItemCreativeAssociationAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
Esempio n. 13
0
 public virtual LineItemCreativeAssociationPage getLineItemCreativeAssociationsByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getLineItemCreativeAssociationsByStatement", new object[] { filterStatement });
   return ((LineItemCreativeAssociationPage) (results[0]));
 }
Esempio n. 14
0
 public virtual UpdateResult performSharedAdUnitAction(SharedAdUnitAction sharedAdUnitAction, Statement filterStatement) {
   object[] results = this.Invoke("performSharedAdUnitAction", new object[] { sharedAdUnitAction, filterStatement });
   return ((UpdateResult) (results[0]));
 }
Esempio n. 15
0
 public virtual SharedAdUnitPage getSharedAdUnitsByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getSharedAdUnitsByStatement", new object[] { filterStatement });
   return ((SharedAdUnitPage) (results[0]));
 }
    public void TestGetUsersByStatement() {
      Statement statement = new Statement();
      statement.query = "ORDER BY name LIMIT 500";

      UserPage page = null;

      Assert.DoesNotThrow(delegate() {
        page = userService.getUsersByStatement(statement);
      });

      Assert.NotNull(page);
      Assert.NotNull(page.results);

      List<long> salesPersonIds = new List<long>();
      List<long> traffickerIds = new List<long>();

      foreach(User tempUser in page.results) {
        if (tempUser.roleName == "Salesperson") {
          salesPersonIds.Add(tempUser.id);
        } else if (tempUser.roleName == "Trafficker") {
          traffickerIds.Add(tempUser.id);
        }
      }
      Assert.Contains(salespersonId, salesPersonIds);
      Assert.Contains(traffickerId, traffickerIds);
    }
    public void TestPerformUserAction() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE id = {0}", salespersonId);

      DeactivateUsers action = new DeactivateUsers();

      UpdateResult result = null;

      Assert.DoesNotThrow(delegate() {
        result = userService.performUserAction(action, statement);
      });

      Assert.NotNull(result);
      Assert.AreEqual(result.numChanges, 1);

      // Activate the user again.

      Assert.DoesNotThrow(delegate() {
        result = userService.performUserAction(new ActivateUsers(), statement);
      });

      Assert.NotNull(result);
      Assert.AreEqual(result.numChanges, 1);
    }
 /// <summary>
 /// Gets the <see cref="Statement"/> representing the state of this
 /// statement builder.
 /// </summary>
 /// <returns>The statement.</returns>
 public Statement ToStatement() {
   Statement statement = new Statement();
   statement.query = BuildQuery();
   statement.values = valueEntries.ToArray();
   return statement;
 }
    public void TestGetAdUnitsByStatement() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE id = '{0}' LIMIT 1", adUnit1.id);

      AdUnitPage page = null;

      Assert.DoesNotThrow(delegate() {
        page = inventoryService.getAdUnitsByStatement(statement);
      });

      Assert.NotNull(page);
      Assert.NotNull(page.results);
      Assert.AreEqual(page.totalResultSetSize, 1);
      Assert.NotNull(page.results[0]);

      Assert.AreEqual(page.results[0].name, adUnit1.name);
      Assert.AreEqual(page.results[0].parentId, adUnit1.parentId);
      Assert.AreEqual(page.results[0].id, adUnit1.id);
      Assert.AreEqual(page.results[0].status, adUnit1.status);
      Assert.AreEqual(page.results[0].targetWindow, adUnit1.targetWindow);
    }
    public void TestGetCompaniesByStatement() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE id = {0} ORDER BY name LIMIT 1", testCompany1.id);
      CompanyPage page = null;

      Assert.DoesNotThrow(delegate() {
        page = companyService.getCompaniesByStatement(statement);
      });

      Assert.NotNull(page);
      Assert.NotNull(page.results);
      Assert.AreEqual(page.results.Length, 1);
      Assert.NotNull(page.results[0]);
      Assert.AreEqual(page.results[0].id, testCompany1.id);
      Assert.AreEqual(page.results[0].name, testCompany1.name);
    }
Esempio n. 21
0
    public AdUnit FindRootAdUnit(DfpUser user) {
      // Get InventoryService.
      InventoryService inventoryService =
          (InventoryService)user.GetService(DfpService.v201502.InventoryService);

      // Create a Statement to only select the root ad unit.
      Statement statement = new Statement();
      statement.query = "WHERE parentId IS NULL LIMIT 500";

      // Get ad units by Statement.
      AdUnitPage page = inventoryService.getAdUnitsByStatement(statement);
      return page.results[0];
    }
    public void TestGetLineItemsByStatement() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE id = '{0}' LIMIT 1", lineItem1.id);

      LineItemPage page = null;

      Assert.DoesNotThrow(delegate() {
        page = lineItemService.getLineItemsByStatement(statement);
      });

      Assert.NotNull(page);
      Assert.AreEqual(page.totalResultSetSize, 1);
      Assert.NotNull(page.results);
      Assert.AreEqual(page.results[0].id, lineItem1.id);
      Assert.AreEqual(page.results[0].name, lineItem1.name);
      Assert.AreEqual(page.results[0].orderId, lineItem1.orderId);
    }
    public void TestGetLineItemCreativeAssociationsByStatement() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE lineItemId = '{0}' LIMIT 500", lineItemId3);

      LineItemCreativeAssociationPage page = null;
      Assert.DoesNotThrow(delegate() {
        page = licaService.getLineItemCreativeAssociationsByStatement(statement);
      });
      Assert.NotNull(page);
      Assert.NotNull(page.results);
      Assert.AreEqual(page.totalResultSetSize, 1);

      Assert.NotNull(page.results[0]);
      Assert.AreEqual(page.results[0].creativeId, lica1.creativeId);
      Assert.AreEqual(page.results[0].lineItemId, lica1.lineItemId);
    }
    public void TestPerformLineItemAction() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE orderId = '{0}' and status = '{1}'",
          orderId, ComputedStatus.INACTIVE);

      ActivateLineItems action = new ActivateLineItems();
      UpdateResult result = null;

      Assert.DoesNotThrow(delegate() {
        result = lineItemService.performLineItemAction(action, statement);
      });

      Assert.NotNull(result);
    }
    public void TestStatementBuilderBlankStatement() {
      StatementBuilder statementBuilder = new StatementBuilder();

      Statement expectedStatement = new Statement();
      expectedStatement.query = "";
      expectedStatement.values = new String_ValueMapEntry[0];

      Assert.True(StatementsAreEqual(expectedStatement,
                                     statementBuilder.ToStatement()));
    }
    public void TestGetPlacementsByStatement() {
      // Create a Statement to only select active placements.
      Statement statement = new Statement();
      statement.query = string.Format("WHERE id = '{0}'", placement.id);

      PlacementPage page = null;

      Assert.DoesNotThrow(delegate() {
        page = placementService.getPlacementsByStatement(statement);
      });

      Assert.NotNull(page);
      Assert.NotNull(page.results);
      Assert.AreEqual(page.results.Length, 1);

      Assert.AreEqual(page.results[0].id, placement.id);
      Assert.AreEqual(page.results[0].name, placement.name);
      Assert.AreEqual(page.results[0].description, placement.description);
      Assert.Contains(adUnit1.id, page.results[0].targetedAdUnitIds);
      Assert.Contains(adUnit2.id, page.results[0].targetedAdUnitIds);
    }
    public void TestStatementBuilderIncludesKeywordPrefix() {
      StatementBuilder statementBuilder = new StatementBuilder()
          .Where("WHEREWITHALL = 1");

      Statement expectedStatement = new Statement();
      expectedStatement.query = "WHERE WHEREWITHALL = 1";
      expectedStatement.values = new String_ValueMapEntry[0];

      Assert.True(StatementsAreEqual(expectedStatement,
        statementBuilder.ToStatement()));
    }
    public void TestPerformPlacementAction() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE status = '{0}'", InventoryStatus.ACTIVE);

      DeactivatePlacements action = new DeactivatePlacements();

      UpdateResult result = null;

      Assert.DoesNotThrow(delegate() {
        result = placementService.performPlacementAction(action, statement);
      });

      Assert.NotNull(result);
      Assert.GreaterOrEqual(result.numChanges, 0);
    }
    public void TestGetCreativesByStatement() {
      Statement statement = new Statement();
      statement.query = string.Format("WHERE id = '{0}' LIMIT 500", creative1.id);

      CreativePage page = null;

      Assert.DoesNotThrow(delegate() {
        page = creativeService.getCreativesByStatement(statement);
      });
      Assert.NotNull(page);
      Assert.NotNull(page.results);
      Assert.AreEqual(page.totalResultSetSize, 1);
      Assert.NotNull(page.results[0]);
      Assert.AreEqual(page.results[0].id, creative1.id);
      Assert.AreEqual(page.results[0].GetType(), creative1.GetType());
      Assert.AreEqual(page.results[0].name, creative1.name);
      Assert.AreEqual(page.results[0].advertiserId, creative1.advertiserId);
      Assert.AreEqual(page.results[0].previewUrl, creative1.previewUrl);
      Assert.AreEqual(page.results[0].size.height, creative1.size.height);
      Assert.AreEqual(page.results[0].size.width, creative1.size.width);
    }
Esempio n. 30
0
 public virtual AdExclusionRulePage getAdExclusionRulesByStatement(Statement filterStatement) {
   object[] results = this.Invoke("getAdExclusionRulesByStatement", new object[] { filterStatement });
   return ((AdExclusionRulePage) (results[0]));
 }