Ejemplo n.º 1
0
 public void CommandServiceSmokeTest()
 {
     WCFHelper.Using <WCFServiceProxy <ICommandService> >(new WCFServiceProxy <ICommandService>("CommandService"), client =>
     {
         client.Service.SendCommands(new List <HostingCommand>());
     });
 }
Ejemplo n.º 2
0
        public IEnumerable <ProxySync.PreCommitResponse> TestPreCommitVersionCompare_FacebookUser(long differentBetweenHostingVersionAndLocalVersion, out ProxySync.ObjectState facebookUserObjectState)
        {
            facebookUserObjectState                  = NextObjectState();
            facebookUserObjectState.HostingId        = -1;
            facebookUserObjectState.ObjectDetailType = (int)SEMObjectDetailType.FacebookUser;
            facebookUserObjectState.IsVersionCompare = true;
            facebookUserObjectState.EngineType       = (int)SearchEngineType.Facebook;
            facebookUserObjectState.LocalId          = SyncDataServiceHelper.GenerateLocalId(facebookUserObjectState);

            TblFacebookUser facebookUserEntity = NextFacebookUserEntity();

            facebookUserEntity.Id = facebookUserObjectState.ObjectId;

            facebookUserEntity.Version = facebookUserObjectState.LocalVersion + differentBetweenHostingVersionAndLocalVersion;

            RegisterCreatedFacebookUserEntityForCleanup(facebookUserEntity);
            InsertFacebookUserIntoDB(facebookUserEntity);

            ProxySync.PreCommitResponse[] responses = null;
            ProxySync.ObjectState         facebookUserObejctStateForLambdaExpression = facebookUserObjectState;
            WCFHelper.Using <SyncDataServiceClient>(new SyncDataServiceClient(), client =>
            {
                responses = client.PreCommit(new ProxySync.ObjectState[] { facebookUserObejctStateForLambdaExpression });
            });
            return(responses);
        }
Ejemplo n.º 3
0
 public void GoogleServiceSmokeTest()
 {
     WCFHelper.Using <WCFServiceProxy <IGoogleService> >(new WCFServiceProxy <IGoogleService>("GoogleService"), client =>
     {
         client.Service.GetParent(0, AdSage.Concert.Hosting.Common.SEMObjectDetailType.Unknown, false);
     });
 }
Ejemplo n.º 4
0
 public void QueryEventServiceSmokeTest()
 {
     WCFHelper.Using <WCFServiceProxy <IQueryEventService> >(new WCFServiceProxy <IQueryEventService>("QueryEventService"), client =>
     {
         client.Service.GetAllCommandInfoList();
     });
 }
Ejemplo n.º 5
0
        public void TestUpdateOneObjectStateWithClientVersionGreatThanServerVersion_FacebookCampaign()
        {
            //Initialize by precommit
            ProxySync.ObjectState       facebookCampaignObjectState;
            ProxySync.PreCommitResponse precommitResponse = SyncDataServiceHelper.DoPreCommitInitialize_FacebookCampaign(out facebookCampaignObjectState);
            Assert.IsNotNull(precommitResponse, "The PreCommitResponse object should be NOT NULL!!");

            //Insert Facebook Account entity
            TblFacebookAccount facebookAccountEntity = SyncDataServiceHelper.NextFacebookAccountEntity();

            facebookAccountEntity.Id = facebookCampaignObjectState.ParentId;
            SyncDataServiceHelper.RegisterCreatedFacebookAccountEntityForCleanup(facebookAccountEntity);
            SyncDataServiceHelper.InsertFacebookAccountIntoDB(facebookAccountEntity);

            TblFacebookCampaign facebookCampaignEntity;

            SyncDataServiceHelper.DoesExistFacebookCampaignEntityInDB(facebookCampaignObjectState.ObjectId, out facebookCampaignEntity);

            var inputDictionary = new Dictionary <long, ProxySync.ObjectState[]>();

            facebookCampaignObjectState.LocalVersion++;
            inputDictionary.Add(facebookCampaignEntity.LocalParentId, new ProxySync.ObjectState[] { facebookCampaignObjectState });

            ProxyDTO.SEMBaseDTO[] response = null;
            WCFHelper.Using <SyncDataServiceClient>(new SyncDataServiceClient(), client =>
            {
                response = client.Update(inputDictionary);
            });
            Assert.AreEqual(1, response.Length, "The length of response should be 1!!");
            Assert.AreEqual(facebookCampaignObjectState.LocalVersion - 1, response[0].Version, "The response version should be equal to localversion-1!!");
        }
Ejemplo n.º 6
0
 public void RuleManagementSmokeTest()
 {
     WCFHelper.Using <RuleManagementServiceClient>(new RuleManagementServiceClient(), client =>
     {
         client.GetRuleSets(0);
     });
 }
Ejemplo n.º 7
0
 public void TrackingServiceSmokeTest()
 {
     WCFHelper.Using <WCFServiceProxy <ITrackingService> >(new WCFServiceProxy <ITrackingService>("TrackingService"), client =>
     {
         try
         {
             client.Service.GetConversionsByAdvertiser(null);
         }
         catch (Exception ex)
         {
             Assert.AreEqual("Value cannot be null.\r\nParameter name: source\r\n", ex.Message);
             return;
         }
         Assert.Fail("Should throw an exception says 'Value cannot be null.\r\nParameter name: source\r\n'");
     });
 }
Ejemplo n.º 8
0
 public void FacebookServiceSmokeTest()
 {
     WCFHelper.Using <WCFServiceProxy <IFacebookService> >(new WCFServiceProxy <IFacebookService>("FacebookService"), client =>
     {
         try
         {
             client.Service.GetUserById(0);
         }
         catch (Exception ex)
         {
             Assert.AreEqual("Value cannot be null.\r\nParameter name: source", ex.Message);
             return;
         }
         Assert.Fail("Should throw an exception says 'Value cannot be null.\r\nParameter name: source'");
     });
 }
Ejemplo n.º 9
0
 public void AdvertiserServiceSmokeTest()
 {
     WCFHelper.Using <WCFServiceProxy <IAdvertiserService> >(new WCFServiceProxy <IAdvertiserService>("AdvertiserService"), client =>
     {
         try
         {
             client.Service.GetAccountsAndUserById(null);
         }
         catch (Exception ex)
         {
             Assert.AreEqual("Value cannot be null.\r\nParameter name: advertiser\r\n", ex.Message);
             return;
         }
         Assert.Fail("Value cannot be null.\r\nParameter name: advertiser\r\n");
     });
 }
Ejemplo n.º 10
0
        public TblFacebookUser TestAddUser_FacebookUser(out AddFacebookUserCommand addFacebookUserCommand)
        {
            addFacebookUserCommand = NextFacebookUserCommand();
            TblFacebookUser facebookUserEntity = NextFacebookUserEntity();

            facebookUserEntity.Id      = addFacebookUserCommand.Id;
            facebookUserEntity.LocalId = addFacebookUserCommand.LocalId;

            RegisterCreatedFacebookUserEntitiesForCleanup(facebookUserEntity);
            InsertFacebookUserIntoDatabsase(facebookUserEntity);
            AddFacebookUserCommand facebookUserCommandForLambdaExpression = addFacebookUserCommand;

            WCFHelper.Using <WCFServiceProxy <IFacebookService> >(new WCFServiceProxy <IFacebookService>("FacebookService"),
                                                                  client =>
            {
                client.Service.AddUser(facebookUserCommandForLambdaExpression);
            });

            long facebookUserId = addFacebookUserCommand.Id;

            facebookUserEntity = GetFacebookUserEntity(facebookUserId);
            return(facebookUserEntity);
        }
Ejemplo n.º 11
0
        public void TestMultipleClientsDoPreCommit_FacebookCampaign()
        {
            ProxySync.ObjectState facebookCampaignObjectState = SyncDataServiceHelper.NextObjectState();
            facebookCampaignObjectState.HostingId        = -1;
            facebookCampaignObjectState.ObjectDetailType = (int)SEMObjectDetailType.FacebookCampaign;
            facebookCampaignObjectState.IsVersionCompare = true;
            facebookCampaignObjectState.EngineType       = (int)SearchEngineType.Facebook;
            facebookCampaignObjectState.LocalId          = SyncDataServiceHelper.GenerateLocalId(facebookCampaignObjectState);

            TblFacebookCampaign facebookCampaignEntity = SyncDataServiceHelper.NextFacebookCampaignEntity();

            facebookCampaignEntity.Id       = facebookCampaignObjectState.ObjectId;
            facebookCampaignEntity.ParentId = facebookCampaignObjectState.ParentId;

            facebookCampaignEntity.Version = facebookCampaignObjectState.LocalVersion;

            SyncDataServiceHelper.RegisterCreatedFacebookCampaignEntityForCleanup(facebookCampaignEntity);
            SyncDataServiceHelper.InsertFacebookCampaignIntoDB(facebookCampaignEntity);

            var taskA = Task.Factory.StartNew <ProxySync.PreCommitResponse[]>(() =>
            {
                ProxySync.PreCommitResponse[] responsesA = null;
                ProxySync.ObjectState facebookCampaignObejctStateForLambdaExpressionA = facebookCampaignObjectState;
                WCFHelper.Using <SyncDataServiceClient>(new SyncDataServiceClient(), client =>
                {
                    responsesA = client.PreCommit(new ProxySync.ObjectState[] { facebookCampaignObejctStateForLambdaExpressionA });
                });
                return(responsesA);
            });

            var taskB = Task.Factory.StartNew <ProxySync.PreCommitResponse[]>(() =>
            {
                ProxySync.PreCommitResponse[] responsesB = null;
                ProxySync.ObjectState facebookCampaignObejctStateForLambdaExpressionB = facebookCampaignObjectState;
                WCFHelper.Using <SyncDataServiceClient>(new SyncDataServiceClient(), client =>
                {
                    responsesB = client.PreCommit(new ProxySync.ObjectState[] { facebookCampaignObejctStateForLambdaExpressionB });
                });
                return(responsesB);
            });

            Task.WaitAll(taskA, taskB);

            //Verify two task results
            if (taskA.Result == null && taskB.Result == null)
            {
                Assert.Fail("The two clients all return NULL!!");
            }
            if (taskA.Result != null && taskB.Result != null)
            {
                Assert.Fail("The two clients all don't return NULL!!");
            }
            if (taskA.Result != null && taskB.Result == null)
            {
                Assert.AreEqual(1, taskA.Result.Length, "The length of PreCommitResponse array should be equal 1!!");
                Assert.AreEqual(facebookCampaignObjectState.LocalId, taskA.Result[0].GrainId, "The inputed objectstate object's LocalId should be equal to PreCommitResponse's GrainId returned from Server!!");
            }
            if (taskA.Result == null && taskB.Result != null)
            {
                Assert.AreEqual(1, taskB.Result.Length, "The length of PreCommitResponse array should be equal 1!!");
                Assert.AreEqual(facebookCampaignObjectState.LocalId, taskB.Result[0].GrainId, "The inputed objectstate object's LocalId should be equal to PreCommitResponse's GrainId returned from Server!!");
            }
        }
Ejemplo n.º 12
0
        public void TestNewDataCommitOneSyncDataObject_FacebookCampaign()
        {
            //Initialize by precommit
            ProxySync.ObjectState       facebookCampaignObjectState;
            ProxySync.PreCommitResponse precommitResponse = SyncDataServiceHelper.DoPreCommitInitialize_FacebookCampaign(out facebookCampaignObjectState);
            Assert.IsNotNull(precommitResponse, "The PreCommitResponse object should be NOT NULL!!");

            //Insert Facebook Account entity
            TblFacebookAccount facebookAccountEntity = SyncDataServiceHelper.NextFacebookAccountEntity();

            facebookAccountEntity.Id = facebookCampaignObjectState.ParentId;
            SyncDataServiceHelper.RegisterCreatedFacebookAccountEntityForCleanup(facebookAccountEntity);
            SyncDataServiceHelper.InsertFacebookAccountIntoDB(facebookAccountEntity);

            //Generate randomized syncdata object
            ProxyDTO.Facebook.FacebookCampaignDTO facebookCampaignDTO = SyncDataServiceHelper.NextFacebookCampaignDTO();
            facebookCampaignDTO.ParentId = facebookAccountEntity.Id;

            //string JsonSerializedFacebookCampaignDTO = ServiceStack.Text.JsonSerializer.SerializeToString(facebookCampaignDTO, typeof(ProxyDTO.Facebook.FacebookCampaignDTO));
            ProxySync.SyncData facebookCampaignSyncData = SyncDataServiceHelper.NextSyncData();

            //Setting property of syncdata object
            facebookCampaignSyncData.ObjectDTO         = facebookCampaignDTO;
            facebookCampaignSyncData.ObjectId          = facebookCampaignObjectState.ObjectId;
            facebookCampaignSyncData.ParentId          = facebookCampaignObjectState.ParentId;
            facebookCampaignSyncData.LocalId           = precommitResponse.GrainId;
            facebookCampaignSyncData.EngineType        = (int)SearchEngineType.Facebook;
            facebookCampaignSyncData.ObjectDetailType  = (int)SEMObjectDetailType.FacebookCampaign;
            facebookCampaignSyncData.Operation         = 0;
            facebookCampaignSyncData.TimeStamp         = precommitResponse.PreCommitToken;
            facebookCampaignSyncData.GrainId           = facebookCampaignSyncData.LocalId;
            facebookCampaignSyncData.HostingCampaignId = -1;
            facebookCampaignSyncData.HostingId         = -1;
            facebookCampaignSyncData.HostingParentId   = -1;

            //Insert sequenceNumber into db
            TblSequenceNumber sequenceNumberEntity = SyncDataServiceHelper.NextSequenceNumberEntity();

            sequenceNumberEntity.EngineType = (int)facebookCampaignSyncData.EngineType;
            SyncDataServiceHelper.RegisterCreatedSequenceNumberEntityForCleanup(sequenceNumberEntity);
            SyncDataServiceHelper.InsertSequenceNumberIntoDB(sequenceNumberEntity);

            ProxySync.CommitResponse[] response = null;
            WCFHelper.Using <SyncDataServiceClient>(new SyncDataServiceClient(), client =>
            {
                response = client.NewDataCommit(new ProxySync.SyncData[] { facebookCampaignSyncData });
            });
            Assert.IsNotNull(response, "The response object should not be NULL!!");
            Assert.AreEqual(sequenceNumberEntity.Id + 1, response[0].HostingId, "The response object's hosting id should be equal to [tblSequenceNumber].[Id]+1");
            Assert.IsTrue(SyncDataServiceHelper.DoesExistSequenceNumberEntityInDB(
                              new TblSequenceNumber
            {
                Id         = sequenceNumberEntity.Id + 1,
                EngineType = sequenceNumberEntity.EngineType
            }));

            TblFacebookCampaign actualFacebookCampaignEntity;

            Assert.IsTrue(SyncDataServiceHelper.DoesExistFacebookCampaignEntityInDB(facebookCampaignDTO.Id, out actualFacebookCampaignEntity), "There should be one facebook campaign enty in db!!");
            SyncDataServiceHelper.CompareFacebookCampaignDTOAndEntityObject(facebookCampaignDTO, actualFacebookCampaignEntity, response[0].HostingId, response[0].HostingParentId, 1);
        }
Ejemplo n.º 13
0
        public void TestCreateAutoRuleSet()
        {
            OptimizationServiceTestHelper.InitializeSEMObjectDB();
            Guid userId           = RandomData.NextGuid();
            long advertiserId     = 10040;
            long campaignObjectId = 6004249897041;
            long accountId        = 46848300;

            //Create AutomationRuleSet object
            AutomationRuleSet automationRuleSet = new AutomationRuleSet();

            automationRuleSet.JobID             = 0;
            automationRuleSet.OptimizationLevel = (int)SEMObjectDetailType.FacebookAdGroup;
            automationRuleSet.RuleSetID         = 0;
            automationRuleSet.UserID            = userId.ToString();
            automationRuleSet.AdvertiserID      = advertiserId;
            automationRuleSet.RotationId        = 0;
            automationRuleSet.Today             = new DateTime();
            automationRuleSet.AutomationType    = (int)SEMObjectDetailType.FacebookCampaign;
            automationRuleSet.ObjectIDs         = new long[] { campaignObjectId };
            automationRuleSet.AccountIDs        = new long[] { accountId };

            //Creating AutomationRuleSet.Rules
            RuleComponent ruleComponent1 = new RuleComponent();

            ruleComponent1.IsValidated          = false;
            ruleComponent1.Name                 = "0";
            ruleComponent1.Active               = true;
            ruleComponent1.Priority             = 0;
            ruleComponent1.ReevaluationBehavior = RuleReevaluationBehavior.Always;

            #region RuleComponent.Condition
            //Creating RuleComponent.Condition
            SimpleExpression simpleExpression = new SimpleExpression();
            simpleExpression.Left     = "Clicks";
            simpleExpression.Operator = Operator.Less;
            simpleExpression.Right    = (Int64)1;

            PerformanceCondition performanceCondition = new AvgPerformanceCondition();
            performanceCondition.Description     = string.Empty;
            performanceCondition.Name            = "0";
            performanceCondition.OPTType         = (int)SEMObjectDetailType.FacebookAdGroup;
            performanceCondition.PerformanceDays = 1;
            performanceCondition.SimpleExpr      = simpleExpression;

            AndConditionComponent andConditionComponent = new AndConditionComponent();
            andConditionComponent.Conditions.Add(performanceCondition);

            OrConditionComponent orConditionComponent = new OrConditionComponent();
            orConditionComponent.Conditions.Add(andConditionComponent);

            ruleComponent1.Condition = new AutomationConditionSet
            {
                Description = string.Empty,
                Name        = string.Empty,
                CondSet     = orConditionComponent,
            };
            #endregion

            #region RuleComponent.ThenActions
            //Creating RuleComponent.ThenActions
            SimpleExpression simpleExpressionForAction1 = new SimpleExpression();
            simpleExpressionForAction1.Left     = "Status";
            simpleExpressionForAction1.Operator = Operator.Equal;
            simpleExpressionForAction1.Right    = (Int32)1;

            ActionWithProtect action1 = new ActionWithProtect();
            action1.Name    = "0";
            action1.OPTType = (int)SEMObjectDetailType.FacebookAdGroup;

            //If IsNeedConfirm is true, then rule engine will not call hosting service, will insert data into cache db.
            //If IsNeedConfirm is false, then rule enginel will call hosting service, and will insert result data into summary db and cache db.
            action1.IsNeedConfirm = false;
            action1.SimpleExpr    = simpleExpressionForAction1;

            SimpleExpression simpleExpressionForAction2 = new SimpleExpression();
            simpleExpressionForAction2.Left     = "MaxBid";
            simpleExpressionForAction2.Operator = Operator.PlusEqual;
            simpleExpressionForAction2.Right    = (Int32)1;

            ActionWithProtect action2 = new ActionWithProtect();
            action2.Name          = "1";
            action2.OPTType       = (int)SEMObjectDetailType.FacebookAdGroup;
            action2.IsNeedConfirm = false;
            action2.SimpleExpr    = simpleExpressionForAction2;

            ruleComponent1.ThenActions.Add(action1);
            ruleComponent1.ThenActions.Add(action2);
            automationRuleSet.Rules.Add(ruleComponent1);
            #endregion

            //Creating RuleSetDefinition
            RuleSetDefinition ruleSetDefinition = new RuleSetDefinition();
            ruleSetDefinition.Description   = RandomData.NextEnglishWordLowercase(10);
            ruleSetDefinition.LastRun       = new DateTime();
            ruleSetDefinition.ModifiedTime  = new DateTime();
            ruleSetDefinition.Name          = RandomData.NextEnglishWordLowercase(10);
            ruleSetDefinition.RulesetID     = 0;
            ruleSetDefinition.RuleSetStatus = 0;
            ruleSetDefinition.RuleType      = 0;//RuleSetTypes.AutoOptimization = 0
            ruleSetDefinition.ValidFrom     = DateTime.Now;
            ruleSetDefinition.Content       = RuleEngineUtils.SerializeAutomationRuleSet <AutomationRuleSet>(automationRuleSet);

            #region RuleSetParameter
            //Setting RuleSetParameter

            //Setting Schedule Parameter
            RuleSetParameter scheduleParameter = new RuleSetParameter();
            scheduleParameter.Name  = "Schedule";
            scheduleParameter.Value = new RuleSetDefinitionSchedule
            {
                IsRunOncek__BackingField     = false,
                RunPeriodTypek__BackingField = RuleSetDefinitionRunPeriodType.Day,
                TimePeriodk__BackingField    = new RuleSetDefinitionRunTimePeriod
                {
                    StartTimek__BackingField = DateTime.Now + new TimeSpan(0, 1, 0),
                },
                WeekPeriodk__BackingField = new DayOfWeek[] { DateTime.Now.DayOfWeek },
            };

            //Setting Enable Parameter
            RuleSetParameter enableParameter = new RuleSetParameter();
            enableParameter.Name  = "Enable";
            enableParameter.Value = 1;

            //Setting ObjectCount Parameter
            RuleSetParameter objectsCountParameter = new RuleSetParameter();
            objectsCountParameter.Name  = "ObjectsCount";
            objectsCountParameter.Value = 1;

            //Setting ObjectDetailType Parameter
            RuleSetParameter objectDetailTypeParameter = new RuleSetParameter();
            objectDetailTypeParameter.Name  = "ObjectDetailType";
            objectDetailTypeParameter.Value = (int)SEMObjectDetailType.FacebookCampaign;

            //Setting AccountId Parameter
            RuleSetParameter accountIdParameter = new RuleSetParameter();
            accountIdParameter.Name  = "AccountIDs";
            accountIdParameter.Value = new long[] { accountId };

            //Setting IsRuleOptimization Parameter
            RuleSetParameter isRuleOptimizationParameter = new RuleSetParameter();
            isRuleOptimizationParameter.Name  = "IsRuleOptimization";
            isRuleOptimizationParameter.Value = true;

            //Setting CronExpression Parameter
            RuleSetParameter cronExpressionParameter = new RuleSetParameter();
            cronExpressionParameter.Name  = "CronExpression";
            cronExpressionParameter.Value = OptimizationServiceTestHelper.CreateCronExperssion((RuleSetDefinitionSchedule)scheduleParameter.Value);

            //Setting TimeZone Parameter
            RuleSetParameter timeZoneParameter = new RuleSetParameter();
            timeZoneParameter.Name  = "TimeZone";
            timeZoneParameter.Value = OptimizationServiceTestHelper.UTCTimeOffset().ToString();

            ruleSetDefinition.Parameters = new RuleSetParameter[] { scheduleParameter, enableParameter, objectsCountParameter, objectDetailTypeParameter, accountIdParameter, isRuleOptimizationParameter, cronExpressionParameter, timeZoneParameter };
            #endregion

            WCFHelper.Using <RuleManagementServiceClient>(new RuleManagementServiceClient(), client =>
            {
                client.CreateAutoRuleSet(userId.ToString(), advertiserId, ruleSetDefinition);
            });
        }