Exemplo n.º 1
0
 //Constructor
 public ResourceContainer(String name, ResourceType baseType, params Node[] nodes)
     : base(name, nodes)
 {
     _baseType = baseType;
     if (nodes != null)
     {
         _derivedTypes = nodes.OfType <ResourceType>().Where(rt => rt.BaseTypes.Contains(baseType));
         _initial      = new fxList <ResourceAssociationSet>(nodes.OfType <ResourceAssociationSet>().ToArray());
     }
     _desc = "ResourceContainer";
 }
Exemplo n.º 2
0
        public override NodeValue CreateRandomValueForFacets(NodeFacets propertyFacets)
        {
            fxList <byte> bytes      = new fxList <byte>();
            int           maxSize    = propertyFacets.MaxSize != null ? propertyFacets.MaxSize.Value : 512;
            int           actualSize = maxSize;

            if (!propertyFacets.FixedLength)
            {
                //Set max size to be random
                actualSize = AstoriaTestProperties.Random.Next(maxSize);
                if (actualSize > 1000)
                {
                    actualSize = 1000;
                }
            }
            for (int i = 0; i < actualSize; i++)
            {
                bytes.Add((byte)AstoriaTestProperties.Random.Next(byte.MinValue, byte.MaxValue));
            }
            return(new NodeValue(new System.Data.Linq.Binary(bytes.ToArray()), this));
        }
Exemplo n.º 3
0
        public static AstoriaRequest BuildRandomRequest(Workspace workspace, RequestVerb verb, SerializationFormatKind format)
        {
            IEnumerable <ResourceContainer> safeContainers =
                workspace.ServiceContainer.ResourceContainers
                .Where(c => IsSafeOperation(verb, c));

            if (verb != RequestVerb.Get)
            {
                safeContainers = safeContainers.Where(c => c.ResourceTypes.Any(t => IsSafeOperation(verb, c, t)));
            }

            fxList <ResourceContainer> containers = new fxList <ResourceContainer>(safeContainers);

            if (!containers.Any())
            {
                return(null);
            }

            AstoriaRequest request = null;

            while (request == null && containers.Any())
            {
                ResourceContainer container = null;
                ResourceType      type      = null;
                KeyExpression     key       = null;

                while (container == null && containers.Any())
                {
                    container = containers.Choose();

                    if (verb == RequestVerb.Get)
                    {
                        key = workspace.GetRandomExistingKey(container);
                        if (key == null)
                        {
                            containers.Remove(container);
                            container = null;
                        }
                    }
                    else
                    {
                        fxList <ResourceType> types = new fxList <ResourceType>(container.ResourceTypes.Where(t => IsSafeOperation(verb, container, t)));

                        if (!types.Any())
                        {
                            containers.Remove(container);
                            container = null;
                        }

                        if (verb != RequestVerb.Delete)
                        {
                            type = types.Choose();
                        }
                        else
                        {
                            while (key == null && types.Any())
                            {
                                type = types.Choose();
                                key  = workspace.GetRandomExistingKey(container, type);
                                if (key == null)
                                {
                                    types.Remove(type);
                                }
                            }

                            if (key == null)
                            {
                                containers.Remove(container);
                                container = null;
                            }
                        }
                    }
                }

                // if we ran out of containers before finding one that would work
                //
                if (container == null)
                {
                    return(null);
                }

                // if the Build___ method returns null, we'll come back around with a different container/key
                //
                switch (verb)
                {
                case RequestVerb.Get:
                    request = BuildGet(workspace, key, HttpStatusCode.OK, format);
                    break;

                case RequestVerb.Post:
                    request = BuildInsert(workspace, container, type, HttpStatusCode.Created, format);
                    break;

                case RequestVerb.Put:
                case RequestVerb.Patch:
                    request = BuildUpdate(workspace, container, type, (verb == RequestVerb.Put), HttpStatusCode.NoContent, format);
                    break;

                case RequestVerb.Delete:
                    request = BuildDelete(workspace, key, HttpStatusCode.NoContent, format);
                    break;

                default:
                    throw new ArgumentException("Unsupported verb: " + verb.ToString());
                }
            }

            // might be null, but we did our best
            //
            return(request);
        }