Пример #1
0
        public virtual void RunModel()
        {
            QueryModel model = new QueryModel(_workspace, _kind, null);
            ModelEngine engine = new ModelEngine(model);
            engine.Options.WeightScheme = WeightScheme.Custom;
            engine.Options.Timeout = 100;

            engine.RunUntil(delegate()
            {
                return model.Actions.Accessed > 5;
            });


            _query = model.QueryResult;
            _container = model.ResContainer;
            _pType = model.ResultType;

            if (_query != null || _pType != null)
            {
                switch (_queryType)
                {
                    case "server":
                        VerifyServer(_query);
                        break;
                    case "client":
                        VerifyClient(model);
                        break;
                    case "linq":
                        VerifyClientLinq(model);
                        break;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Constructor which takes multiple models.
        /// </summary>
        /// <param name="models">object of type Model</param>
        public ModelEngine(ModelEngine parent, params Model[] models)
            : base(null, null)
        {
            _parent = parent;
            _caller = parent;

            //Options
            if (parent != null)
            {
                _options = (ModelEngineOptions)parent.Options.Clone();    //Copy from parent
            }
            else
            {
                _options = (ModelEngineOptions)ModelEngineOptions.Default.Clone();          //Defaults
            }
            //Use passed in models, instead of finding them
            //Saves perf, and the user having to first clear, then add
            _models = new Models(this);
            _models.Add(models);
        }
Пример #3
0
        /// <summary>
        /// Constructor which takes multiple models.
        /// </summary>
        /// <param name="models">object of type Model</param>
        public ModelEngine(ModelEngine parent, params Model[] models)
            : base(null, null)
        {
            _parent = parent;
            _caller = parent;
            
            //Options
            if(parent != null)
                _options = (ModelEngineOptions)parent.Options.Clone();    //Copy from parent
		    else
		        _options = (ModelEngineOptions)ModelEngineOptions.Default.Clone();  //Defaults

            //Use passed in models, instead of finding them
            //Saves perf, and the user having to first clear, then add
            _models = new Models(this);
            _models.Add(models);
        }
Пример #4
0
 public ModelException(ModelEngine engine, string message, Exception inner)
     : this(null, "Engine: " + message, inner, engine.ActionsTrace)
 {
     //Delegate
 }
Пример #5
0
        private void ModifyEntity(bool IsSource)
        {
            AstoriaTestLog.WriteLine("--Running Update Model");
            ModelEngine engine = new ModelEngine();
            engine.Options.Timeout = UpdateModelDuration;

            UpdateModel targetUpdate = null;
            if (IsSource)
            {
                targetUpdate = new UpdateModel(workSpace, Context, Source, SourceContainer, null);
            }
            else
            {
                targetUpdate = new UpdateModel(workSpace, Context, Target, TargetContainer, null);
            }
            engine.Models.Add(targetUpdate);
            engine.Run();
        }
Пример #6
0
        public void Modify1NLink()
        {
            AstoriaTestLog.WriteLine("Modify1NLink");
            QueryResourceTypesByAssociationsForUpdate(Multiplicity.One, Multiplicity.Many, false,
                       true, true,
                          delegate(ResourceContainer sourceContainer, ResourceType sourceResourceType,
                                                  ResourceContainer destinationContainer, ResourceType destinationType)
                          {
                              //
                              ResourceType source = sourceResourceType.AssociationsOneToMany.First.Source.ResourceType;
                              if (!sourceContainer.ResourceTypes.Contains(source))
                              {
                                  //Do this if the source and target come out reversed
                                  ResourceContainer temp = sourceContainer;
                                  sourceContainer = destinationContainer;
                                  destinationContainer = temp;
                                  ResourceType resTemp = sourceResourceType;
                                  sourceResourceType = destinationType;
                                  destinationType = resTemp;
                              }
                              AstoriaTestLog.WriteLine("Source : {0} , Target :{1}", sourceContainer.Name, destinationContainer.Name);
                              ModelEngine engine = new ModelEngine();

                              LinkModel model = new LinkModel(sourceContainer,
                                  sourceResourceType,
                                  destinationContainer,
                                  destinationType,
                                  sourceResourceType.GetAssociation(destinationType), sourceContainer.Workspace, null
                                  );
                              model.Context = this.Context;
                              model.RunningUnderScenarioModel = true;
                              model.TargetMultiplicity = Multiplicity.One;
                              engine.Models.Add(model);
                              engine.Options.Timeout = Timeout;
                              engine.Run();
                              return false;
                          });
        }
Пример #7
0
        public void QueryEntities()
        {

            string entitySetName = ""; object entity = null;
            ResourceContainer resContainer = null;
            while (resContainer == null)
            {
                entity = GetResource(out entitySetName, out resContainer);
            }

            QueryModel queryModel = new QueryModel(workSpace, SerializationFormatKind.Atom, null);
            queryModel.RunningUnderScenarioModel = true;
            queryModel.ResContainer = resContainer;
            ModelEngine engine = new ModelEngine(queryModel);
            engine.Options.WeightScheme = WeightScheme.Custom;
            engine.Options.Timeout = Timeout;
            engine.Run();
            UriQueryBuilder ub = new UriQueryBuilder(workSpace, "");
            string ruri = ub.Build(queryModel.QueryResult);

            string uriRel = ruri.Substring(ruri.LastIndexOf(".svc/") + 5);

            if ((Context.BaseUri + "/" + uriRel).Length > 260) { return; }
            AstoriaTestLog.WriteLineIgnore(Context.BaseUri + "/" + uriRel);

            ResolveClientType(workSpace, Context, queryModel.ResultType);

            object enumerable = ExecuteQuery(Context, queryModel.ResultType, uriRel, "sync");

        }
Пример #8
0
        public void Modify11Link()
        {
            AstoriaTestLog.WriteLine("Modify11Link");
            QueryResourceTypesByAssociationsForUpdate(Multiplicity.One, Multiplicity.One, false,
                       true, true,
                          delegate(ResourceContainer sourceContainer, ResourceType sourceResourceType,
                                                  ResourceContainer destinationContainer, ResourceType destinationType)
                          {
                              AstoriaTestLog.WriteLine("Source : {0} , Target :{1}", sourceContainer.Name, destinationContainer.Name);
                              ModelEngine engine = new ModelEngine();

                              LinkModel model = new LinkModel(sourceContainer,
                                  sourceResourceType,
                                  destinationContainer,
                                  destinationType,
                                  sourceResourceType.GetAssociation(destinationType), sourceContainer.Workspace, null
                                  );
                              model.RunningUnderScenarioModel = true;
                              model.Context = this.Context;
                              model.TargetMultiplicity = Multiplicity.Many;
                              engine.Models.Add(model);
                              engine.Options.Timeout = Timeout;
                              engine.Run();
                              return false;
                          });
        }
Пример #9
0
		public ModelException(ModelEngine engine, string message, Exception inner)
			: this(null, "Engine: " + message, inner, engine.ActionsTrace)
		{
			//Delegate
		}
Пример #10
0
        protected object GetResource(bool existing, out string entitySetName, out ResourceContainer resContainer)
        {
            ScanModel model = new ScanModel(_workspace);
            ModelEngine engine = new ModelEngine();
            engine.Models.Add(model);
            engine.Run();
            entitySetName = "";
            resContainer = null;

            if (!model.CanInsert)
                return null;

            object newResource = Activator.CreateInstance(model.Result.ClientClrType);

            string propName = null;
            object propValue = null;

            entitySetName = model.ResultContainer.Name;
            resContainer = model.ResultContainer;

            foreach (ResourceProperty property in model.Result.Properties.Where(p => p.PrimaryKey != null || p.Facets.Nullable == false))
            {
                if (!property.IsComplexType && !property.IsNavigation) //&& !property.Facets.ServerGenerated)
                {
                    propValue = Resource.CreateValue(property).ClrValue;
                    propName = property.Name;
                    newResource.GetType().GetProperty(propName).SetValue(newResource, propValue, new object[] { });
                }
            }
            if (existing)
            {
                KeyExpression key = _workspace.GetRandomExistingKey(model.ResultContainer, model.Result);

                if (key != null)
                    newResource.GetType().GetProperty(key.Properties[0].Name).SetValue(newResource, key.Values[0].ClrValue, new object[] { });
                else
                    return null;
            }

            return newResource;
        }
Пример #11
0
        public virtual void AttachObject()
        {
            //if (RunningUnderLinkModel)
            //    {
            //    object detachMe = RandomTrackedResource;
            //    Context.Detach( RandomTrackedResource );
            //    Context.AttachTo( CurrentResourceSet, detachMe );
            //    }
            //else
            {
                ScanModel model = new ScanModel(_workspace);
                ModelEngine engine = new ModelEngine();
                engine.Models.Add(model);
                engine.Run();

                if (!model.CanInsert)
                    return;

                object newResource = Activator.CreateInstance(model.Result.ClientClrType);
                KeyExpression key = Workspace.GetRandomExistingKey(model.ResultContainer, model.Result);

                if (key != null)
                    newResource.GetType().GetProperty(key.Properties[0].Name).SetValue(newResource, key.Values[0].ClrValue, new object[] { });
                else
                    return;

                try
                {
                    Context.AttachTo(model.ResultContainer.Name, newResource);
                }
                catch (InvalidOperationException e)
                {
                    return;
                }

                AstoriaTestLog.WriteLine("Attaching entity " + model.ResultContainer.BaseType.Name);

                _action = LastAction.AttachObject;
                _state = EntityState.Unchanged;
                this.CurrentResource = newResource;
                this.CanInsert = model.CanInsert;
                this.CanDelete = model.CanDelete;
                this.ResContainer = model.ResultContainer;
                this.ResType = model.Result;
            }
        }
Пример #12
0
 public virtual T                        Choose(ModelEngine engine)
 {
     return(this.Choose(engine.Options.Random, engine.Options.WeightScheme));
 }
Пример #13
0
        public void Sort(bool bAsc)
        {
            //Sub model - sort
            SortModel model = new SortModel(this._workspace, _fromContainer.BaseType);
            ModelEngine engine = new ModelEngine(this.Engine, model);
            engine.Run();

            PropertyExpression[] ordervalues = model.SortResult;

           if (_query is TopExpression)
                _query = ((TopExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
            else if (_query is SkipExpression)
                _query = ((SkipExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
            else if (_query is CountExpression)
                _query = ((CountExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
            else if (_query is ExpandExpression)
                _query = ((ExpandExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
            else if (_query is NavigationExpression)
                _query = ((NavigationExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
           else if (_query is PredicateExpression)
               _query = ((PredicateExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;
           else if (_query is ScanExpression)
               _query = ((ScanExpression)_query).Sort(ordervalues, bAsc) as OrderByExpression;

            bSort = true;
            _action = LastAction.OrderBy;
            bIsOption = true;
            AstoriaTestLog.WriteLineIgnore(".OrderBy(" + ordervalues.ToString() + ")");
        }
Пример #14
0
        public virtual void Where()
            {

                AstoriaTestLog.WriteLineIgnore("Calling Where");

            //Sub model - projections
            PredicateModel model = new PredicateModel( this.Workspace, this.ResContainer, this.property, this.ParentRelKey, this.ResType );
            ModelEngine engine = new ModelEngine( this.Engine, model );
            engine.Run();

            ExpNode e = model.Result;

            this.ParentRelKey = e as KeyExpression;
            if (null == _parentKey)
                {
                /* no keys for resource type*/
                this.Reload();
                return;
                }

            int i = this.Engine.Options.Random.Next( 0, 10 );
            if (i % 7 == 0)
                {
                e = ((KeyExpression)e).Predicate;
                bFilter = true;
                }

            if (e != null)
                {
                if (_query is ScanExpression)
                    _query = ((ScanExpression)_query).Where( e ) as PredicateExpression;
                else if (_query is NavigationExpression)
                    _query = ((NavigationExpression)_query).Where( e ) as PredicateExpression;
                
                bWhere = true;
                IsKey = true;
                _action = LastAction.Where;
                AstoriaTestLog.WriteLineIgnore( ".Where()" );
                }
            }
Пример #15
0
        public virtual void From()
            {
            if (RunningUnderScenarioModel)
                {
                _query = Query.From( Exp.Variable( ResContainer ) );
                _pType = ResContainer.BaseType.ClientClrType;
                AstoriaTestLog.WriteLineIgnore( "Query.From(" + ResContainer.Name + ")" );
                }
            else
                {
                ScanModel model = new ScanModel( _workspace );
                ModelEngine engine = new ModelEngine( this.Engine, model );
                engine.Run();

                this.ResContainer = model.ResultContainer;
                _query = Query.From( Exp.Variable( model.ResultContainer ) );
                _pType = model.ResultContainer.BaseType.ClientClrType;
                AstoriaTestLog.WriteLineIgnore( "Query.From(" + model.ResultContainer.Name + ")" );
                }


            _action = LastAction.From;
            IsCount = false;

            }
Пример #16
0
        public virtual void DirectedTests()
        {
            QueryModel model = new QueryModel(_workspace, SerializationFormatKind.Atom, null);
            ModelEngine engine = new ModelEngine(model);

            engine.Options.WeightScheme = WeightScheme.Custom;
            engine.Options.Timeout = 100;

            engine.RunUntil(delegate()
            {
                return engine.Models.Actions.AllCovered;
            });

            //engine.RunScenario(model.Actions.Find("From", "Where", " Navigation","Select","Expand"));
            //engine.RunUntil(delegate()
            //{
            //    return model.Actions.Accessed > 4;
            //});

             _query = model.QueryResult;
            _container = model.ResContainer;
            _pType = model.ResultType;

            if (_query != null || _pType != null)
            {
                VerifyClient(model);
            }
        }
Пример #17
0
 public void ModifyEntity()
 {
     string entitySetName = ""; object entity = null;
     ResourceContainer resContainer = null;
     while (resContainer == null)
     {
         entity = GetResource(out entitySetName, out resContainer);
     }
     UpdateModel updModel = new UpdateModel(workSpace, Context, entity, resContainer, null);
     updModel.RunningUnderLinkModel = true;
     ModelEngine engine = new ModelEngine();
     engine.Models.Add(updModel);
     engine.Options.Timeout = Timeout;
     engine.Run();
 }
Пример #18
0
        //Constructors

        ///<summary>Constructor</summary>
        ///<param name="engine">The engine context for this collection.</param>
        public Models(ModelEngine engine)
        {
            _engine = engine;
        }