Example #1
0
        public static IEnumerable <T> RandomArrayFromArray <T>(this RandomService service, IEnumerable <T> array)
        {
            if (array.Count() == 0)
            {
                return(Enumerable.Empty <T>());
            }

            var resultArray = new List <T>();
            var itemsCount  = service.Int(array.Count() - 1);

            if (itemsCount == 0)
            {
                itemsCount = array.Count() / 2;
            }

            for (var i = 0; i < itemsCount; i++)
            {
                var newItem = array.ToList()[service.Int(array.Count() - 1)];

                if (!resultArray.Contains(newItem))
                {
                    resultArray.Add(newItem);
                }
            }

            return(resultArray);
        }
Example #2
0
        public static string DomainUserEmail(this RandomService service)
        {
            var emailString = RunnerEnvironmentUtils.GetEnvironmentVariable(EnvironmentConsts.DefaultTestDomainUserEmails);

            if (!string.IsNullOrEmpty(emailString))
            {
                var emails = emailString.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                return(emails[service.Int(emails.Length)]);
            }

            throw new Exception(string.Format("Environment value [{0}] is NULL", EnvironmentConsts.DefaultTestDomainUserEmails));
        }
Example #3
0
 public static string VersionString(this RandomService service)
 {
     return(new Version(service.Int(10), service.Int(10), service.Int(10), service.Int(10)).ToString());
 }
Example #4
0
 public static DateTime DateUtc(this RandomService service, int days)
 {
     return(DateTime.UtcNow.AddDays(service.Int(days)));
 }
Example #5
0
 public static uint UInt(this RandomService service, uint maxValue)
 {
     return((uint)service.Int((int)maxValue));
 }
Example #6
0
 public static byte Byte(this RandomService service, byte maxValue)
 {
     return((byte)service.Int(maxValue));
 }
Example #7
0
 public static short Short(this RandomService service, short maxValue)
 {
     return((short)service.Int(maxValue));
 }
Example #8
0
 public static T RandomFromArray <T>(this RandomService service, IEnumerable <T> array)
 {
     return(array.ToList()[service.Int(array.Count() - 1)]);
 }
Example #9
0
        public ModelNode GenerateModelTreeForDefinition(Type definitionType, SPObjectModelType objectModelType)
        {
            ModelNode result = null;

            var rootHostType   = GetRootHostType(definitionType, objectModelType);
            var parentHostType = GetParentHostType(definitionType, objectModelType);

            var currentDefinition       = GetRandomDefinition(definitionType);
            var expectManyInstancesAttr = definitionType.GetCustomAttribute <ExpectManyInstances>(false);

            var manyInstances = new List <DefinitionBase>();

            if (expectManyInstancesAttr != null)
            {
                var maxCount = expectManyInstancesAttr.MinInstancesCount +
                               Rnd.Int(expectManyInstancesAttr.MaxInstancesCount -
                                       expectManyInstancesAttr.MinInstancesCount);

                for (int i = 0; i < maxCount; i++)
                {
                    manyInstances.Add(GetRandomDefinition(definitionType));
                }
            }

            CurrentDefinitions.Clear();

            CurrentDefinitions.Add(currentDefinition);
            CurrentDefinitions.AddRange(manyInstances);

            //CurrentDefinition = currentDefinition;

            var defs = new List <GeneratedNodes>();

            LookupModelTree(rootHostType, definitionType, defs, objectModelType);

            if (defs.Count > 0)
            {
                defs.Reverse();

                var rootHost = defs[0].ModelNode;
                parentHostType = rootHost.Value.GetType();

                defs.RemoveAt(0);

                ModelNode model = null;

                if (parentHostType == typeof(FarmDefinition))
                {
                    model = SPMeta2Model.NewFarmModel();
                }

                if (parentHostType == typeof(WebApplicationDefinition))
                {
                    model = SPMeta2Model.NewWebApplicationModel();
                }

                if (parentHostType == typeof(SiteDefinition))
                {
                    model = SPMeta2Model.NewSiteModel();
                }

                if (parentHostType == typeof(WebDefinition))
                {
                    model = SPMeta2Model.NewWebModel();
                }

                var _m = model;

                foreach (var def in defs)
                {
                    _m.ChildModels.Add(def.ModelNode);
                    _m = def.ModelNode;
                }

                _m.AddDefinitionNode(currentDefinition);

                foreach (var manyDef in manyInstances)
                {
                    _m.AddDefinitionNode(manyDef);
                }

                result = model;
            }
            else
            {
                ModelNode resultModel = null;

                if (currentDefinition.GetType() == typeof(FarmDefinition))
                {
                    resultModel = SPMeta2Model.NewFarmModel();
                }

                if (currentDefinition.GetType() == typeof(WebApplicationDefinition))
                {
                    resultModel = SPMeta2Model.NewWebApplicationModel();
                }

                if (currentDefinition.GetType() == typeof(SiteDefinition))
                {
                    resultModel = SPMeta2Model.NewSiteModel();
                }

                if (currentDefinition.GetType() == typeof(WebDefinition))
                {
                    resultModel = SPMeta2Model.NewWebModel();
                }

                if (resultModel == null)
                {
                    throw new SPMeta2NotImplementedException(string.Format("Cannot find host model for type:[{0}]. Ensure correct RootHostAttribute/ParentHostAttribute/SPObjectTypeAttribute attributes.", definitionType.AssemblyQualifiedName));
                }

                resultModel.Value = currentDefinition;
                result            = resultModel;
            }

            // ProcessAdditionalArtifacts(result, defs);

            return(result);
        }