/// <summary>
        /// Puts payload in a batch response.
        /// </summary>
        /// <typeparam name="T">T must be a PayloadTestDescriptor.</typeparam>
        /// <param name="originalPayload">Payload to be inserted into batch.</param>
        /// <param name="statusCode">Status code associated with payload</param>
        /// <param name="random">Use of random makes this method non deterministic</param>
        /// <param name="requestManager">Used to construct the response payload.</param>
        /// <param name="inChangeset">Specifies whether this is in a changeset or an operation.</param>
        /// <param name="operationsBefore">Number of operations/changesets to go before payload.</param>
        /// <param name="operationsAfter">Number of operations/changesets to go after payload.</param>
        /// <param name="version">Maximum version for extra generated payloads</param>
        /// <returns>Test descriptor for the new BatchResponsePayload.</returns>
        public static T InBatchResponse <T>(
            this T originalPayload,
            int statusCode,
            IRandomNumberGenerator random,
            IODataRequestManager requestManager,
            bool inChangeset     = false,
            int operationsBefore = 0,
            int operationsAfter  = 0,
            ODataVersion version = ODataVersion.V4
            ) where T : PayloadTestDescriptor
        {
            ExceptionUtilities.CheckArgumentNotNull(originalPayload, "originalPayload");
            ExceptionUtilities.CheckArgumentNotNull(statusCode, "statusCode");
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckArgumentNotNull(requestManager, "requestManager");
            var payload = (T)originalPayload.Clone();

            var headers = new Dictionary <string, string> {
                { "ResponseHeader", "ResponseValue" }
            };
            var baseUri = new ODataUri(ODataUriBuilder.Root(new Uri("http://www.odata.org/service.svc")));

            IMimePart[] extraoperations = BatchUtils.ExtraResponseChangesets(random, (EdmModel)payload.PayloadEdmModel, version);  // add extraChangesets methods
            extraoperations.Concat(BatchUtils.ExtraResponseOperations(random, (EdmModel)payload.PayloadEdmModel, version));

            //Work out the operations and changesets to go before the payload
            var parts = Enumerable.Range(0, operationsBefore).Select(i => random.ChooseFrom(extraoperations));

            if (!inChangeset)
            {
                extraoperations.ConcatSingle(payload.InResponseOperation(statusCode, requestManager));
            }
            else
            {
                extraoperations.ConcatSingle(payload.InResponseChangeset(statusCode, random, requestManager, random.NextFromRange(0, 2), random.NextFromRange(0, 2), version));
            }

            parts.Concat(Enumerable.Range(0, operationsAfter).Select(i => random.ChooseFrom(extraoperations)));

            var batchResponse = new BatchResponsePayload();

            foreach (var part in parts)
            {
                HttpResponseData operation = part as HttpResponseData;
                if (operation != null)
                {
                    batchResponse.Add(operation.AsBatchFragment());
                }

                BatchResponseChangeset changeset = part as BatchResponseChangeset;
                if (changeset != null)
                {
                    batchResponse.Add(changeset);
                }
            }

            //payload.PayloadEdmModel.Fixup();
            payload.PayloadElement = batchResponse;
            return(payload);
        }
        /// <summary>
        /// Puts payload in a batch request.
        /// </summary>
        /// <typeparam name="T">T must be a PayloadTestDescriptor.</typeparam>
        /// <param name="originalPayload">Payload to put into batch.</param>
        /// <param name="verb">HttpVerb associated with payload.</param>
        /// <param name="random">Use of random makes this method non deterministic.</param>
        /// <param name="requestManager">Used to construct requests.</param>
        /// <param name="operationsBefore">Number of operations/changesets to go before payload.</param>
        /// <param name="operationsAfter">Number of operations/changesets to go after payload.</param>
        /// <param name="version">Maximum version for extra payloads</param>
        /// <returns>The test descriptor for the new BatchRequestPayload</returns>
        public static T InBatchRequest <T>(
            this T originalPayload,
            HttpVerb verb,
            IRandomNumberGenerator random,
            IODataRequestManager requestManager,
            int operationsBefore = 0,
            int operationsAfter  = 0,
            ODataVersion version = ODataVersion.V4
            ) where T : PayloadTestDescriptor
        {
            ExceptionUtilities.CheckArgumentNotNull(originalPayload, "originalPayload");
            ExceptionUtilities.CheckArgumentNotNull(verb, "verb");
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckArgumentNotNull(requestManager, "requestManager");
            var payload = (T)originalPayload.Clone();

            var baseUri = new ODataUri(ODataUriBuilder.Root(new Uri("http://www.odata.org/service.svc")));

            IMimePart[] extraOperations = BatchUtils.ExtraRequestChangesets(random, requestManager, (EdmModel)payload.PayloadEdmModel, baseUri, version);  // add extraChangesets methods
            extraOperations.Concat(BatchUtils.ExtraRequestChangesets(random, requestManager, (EdmModel)payload.PayloadEdmModel, baseUri, version));

            //Work out the operations and changesets to go before the payload
            var parts = Enumerable.Range(0, operationsBefore).Select(i => random.ChooseFrom(extraOperations));

            if (verb != HttpVerb.Get)
            {
                extraOperations.ConcatSingle(payload.InRequestOperation(HttpVerb.Get, baseUri, requestManager));
            }
            else
            {
                extraOperations.ConcatSingle(payload.InRequestChangeset(verb, random, requestManager, random.NextFromRange(0, 2), random.NextFromRange(0, 2), version));
            }

            parts.Concat(Enumerable.Range(0, operationsAfter).Select(i => random.ChooseFrom(extraOperations)));

            var batchRequest = new BatchRequestPayload();

            foreach (var part in parts)
            {
                IHttpRequest operation = part as IHttpRequest;
                if (operation != null)
                {
                    batchRequest.Add(operation.AsBatchFragment());
                }
                BatchRequestChangeset changeset = part as BatchRequestChangeset;
                if (changeset != null)
                {
                    batchRequest.Add(changeset);
                }
            }

            //payload.PayloadEdmModel.Fixup();
            payload.PayloadElement = batchRequest;
            return(payload);
        }
        /// <summary>
        /// When overridden in a derived class, generates a random string of specified length
        /// </summary>
        /// <param name="random">The random number generator to use.</param>
        /// <param name="minLength">Minimum length of the generated string.</param>
        /// <param name="maxLength">Maximum length of the generated string.</param>
        /// <returns>Generated string.</returns>
        protected override string GenerateStringCore(IRandomNumberGenerator random, int minLength, int maxLength)
        {
            this.EnsureAlphabetLoaded();
            var minimumCharacterLength = this.alphabet.Min(w => w.Length);

            var desiredLength = random.NextFromRange(minLength, maxLength);

            // This is an intentionally naive check to determine whether the desired length
            // is actually one that this resource string generator can satisfy. Since the minimum
            // length of existing alphabets is either 1 or 2, and the alphabet that has
            // characters of length 2 has no characters of length 3 or more, then this check works.
            if ((desiredLength % minimumCharacterLength) != 0)
            {
                // Get the closest length to the randomly chosen length that is also a multiple
                // of minimumCharacterLength. Note that the integer division between desiredLength
                // and minimumCharacterLength is intentional.
                desiredLength = (desiredLength / minimumCharacterLength) * minimumCharacterLength;

                if (desiredLength < minLength)
                {
                    desiredLength += minimumCharacterLength;
                }

                if (desiredLength > maxLength)
                {
                    throw new TaupoArgumentException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "This string generator cannot generate a string of a length between {0} and {1}.",
                                  minLength,
                                  maxLength));
                }
            }

            StringBuilder sb = new StringBuilder(desiredLength);

            while (sb.Length < desiredLength)
            {
                var next = random.ChooseFrom(this.alphabet);

                if (next.Length + sb.Length > desiredLength)
                {
                    next = random.ChooseFrom(this.alphabet.Where(w => w.Length == minimumCharacterLength));
                }

                sb.Append(next);
            }

            return(sb.ToString());
        }
Пример #4
0
        /// <summary>
        /// Generates an arbitrary top load payload based on the maximum version supplied.
        /// </summary>
        /// <param name="random">Random generator for generating arbitrary payloads</param>
        /// <param name="model">The model to add any new types to</param>
        /// <param name="version">Maximum version for generated payloads.</param>
        /// <returns>A top level payload.</returns>
        public static ODataPayloadElement GetRandomPayload(IRandomNumberGenerator random, EdmModel model, ODataVersion version = ODataVersion.V4)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckArgumentNotNull(model, "model");

            Func<ODataPayloadElement>[] payloadCalls = new Func<ODataPayloadElement>[]
            {
                () => { return GetComplexInstanceCollection(random, model, version); }, 
                () => { return GetComplexProperty(random, model, version); }, 
                () => { return GetDeferredLink(); }, 
                () => { return GetLinkCollection(); }, 
                () => { return GetEntityInstance(random, model, version); }, 
                () => { return GetEntitySetInstance(random, model); }, 
                () => { return GetODataErrorPayload(random); }, 
                () => { return GetPrimitiveCollection(random); }, 
                () => { return GetPrimitiveProperty(random, model); }, 
                () => { return GetPrimitiveValue(random, model); },
            };

            payloadCalls.Concat(new Func<ODataPayloadElement>[]
            {
                () => { return GetComplexMultiValueProperty(random, model, version); }, 
                () => { return GetPrimitiveMultiValueProperty(random); },
            });

            var payloadCall = random.ChooseFrom(payloadCalls);
            return payloadCall();
        }
Пример #5
0
        private static ComplexMultiValueProperty GetComplexMultiValueProperty(IRandomNumberGenerator random, EdmModel model = null, ODataVersion version = ODataVersion.V4)
        {
            int numinstances = random.ChooseFrom(new[] { 0, 1, 3 });
            var instance     = GetComplexInstance(random, model, version);
            var instances    = GenerateSimilarComplexInstances(random, instance, numinstances, true);
            var propertyName = "ComplexMultivalue" + instance.FullTypeName;
            var payload      = new ComplexMultiValueProperty(propertyName,
                                                             new ComplexMultiValue(propertyName, false, instances.ToArray()));

            if (model != null)
            {
                var entityDataType = instance.GetAnnotation <EntityModelTypeAnnotation>().EdmModelType.Definition as IEdmEntityType;
                ExceptionUtilities.CheckObjectNotNull(entityDataType, "Complex Instance must have an EntityModelTypeAnnotation with an EntityDataType");
                var entityType = model.FindDeclaredType(entityDataType.FullName()) as EdmEntityType;

                ExceptionUtilities.CheckObjectNotNull(entityType, "entityType");
                if (entityType.FindProperty(propertyName) != null)
                {
                    entityType.AddStructuralProperty(propertyName, (model.FindDeclaredType(instance.FullTypeName) as EdmComplexType).ToTypeReference());
                }

                payload.WithTypeAnnotation(entityType);
            }

            return(payload);
        }
Пример #6
0
        private static PrimitiveMultiValueProperty GetPrimitiveMultiValueProperty(IRandomNumberGenerator random)
        {
            var val     = random.ChooseFrom(TestValues.CreatePrimitiveCollections(true, true));
            var payload = new PrimitiveMultiValueProperty("ArbitraryMultivalue", val);

            return(payload);
        }
Пример #7
0
        /// <summary>
        /// Generates an arbitrary top load payload based on the maximum version supplied.
        /// </summary>
        /// <param name="random">Random generator for generating arbitrary payloads</param>
        /// <param name="model">The model to add any new types to</param>
        /// <param name="version">Maximum version for generated payloads.</param>
        /// <returns>A top level payload.</returns>
        public static ODataPayloadElement GetRandomPayload(IRandomNumberGenerator random, EdmModel model, ODataVersion version = ODataVersion.V4)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckArgumentNotNull(model, "model");

            Func <ODataPayloadElement>[] payloadCalls = new Func <ODataPayloadElement>[]
            {
                () => { return(GetComplexInstanceCollection(random, model, version)); },
                () => { return(GetComplexProperty(random, model, version)); },
                () => { return(GetDeferredLink()); },
                () => { return(GetLinkCollection()); },
                () => { return(GetEntityInstance(random, model, version)); },
                () => { return(GetEntitySetInstance(random, model)); },
                () => { return(GetODataErrorPayload(random)); },
                () => { return(GetPrimitiveCollection(random)); },
                () => { return(GetPrimitiveProperty(random, model)); },
                () => { return(GetPrimitiveValue(random, model)); },
            };

            payloadCalls.Concat(new Func <ODataPayloadElement>[]
            {
                () => { return(GetComplexMultiValueProperty(random, model, version)); },
                () => { return(GetPrimitiveMultiValueProperty(random)); },
            });

            var payloadCall = random.ChooseFrom(payloadCalls);

            return(payloadCall());
        }
Пример #8
0
        private static ComplexInstanceCollection GetComplexInstanceCollection(IRandomNumberGenerator random, EdmModel model = null, ODataVersion version = ODataVersion.V4)
        {
            var complex      = GetComplexInstance(random, model, version);
            int numinstances = random.ChooseFrom(new[] { 0, 1, 3 });
            var payload      = new ComplexInstanceCollection(GenerateSimilarComplexInstances(random, complex, numinstances).ToArray());

            if (model != null)
            {
                var container      = model.EntityContainersAcrossModels().Single() as EdmEntityContainer;
                var collectionType = new EdmCollectionType((model.FindDeclaredType(complex.FullTypeName) as EdmComplexType).ToTypeReference());

                var function       = new EdmFunction(container.Namespace, "GetComplexInstances", collectionType.ToTypeReference());
                var functionImport = container.AddFunctionImport("GetComplexInstances", function);

                payload.AddAnnotation(new FunctionAnnotation()
                {
                    FunctionImport = functionImport
                });
                payload.AddAnnotation(new DataTypeAnnotation()
                {
                    EdmDataType = collectionType
                });
            }

            return(payload);
        }
Пример #9
0
        /// <summary>
        /// Generates random string of specified length
        /// </summary>
        /// <param name="random">The random number generator to use.</param>
        /// <param name="minLength">Minimum length of the generated string.</param>
        /// <param name="maxLength">Maximum length of the generated string.</param>
        /// <returns>Generated string.</returns>
        public string GenerateString(IRandomNumberGenerator random, int minLength, int maxLength)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckValidRange(minLength, "minLength", maxLength, "maxLength");

            int wordCount = random.NextFromRange(2, 10);
            int length = random.NextFromRange(minLength, maxLength);

            StringBuilder sb = new StringBuilder();
            while (sb.Length < length)
            {
                string word = this.wordGenerator.GenerateString(random, 2, Math.Max(3, length / wordCount));

                sb.Append(word);
                if (sb.Length < length)
                {
                    sb.Append(' ');
                    if (random.Next(100) < 30)
                    {
                        sb.Append(random.ChooseFrom(glueWords));
                        sb.Append(' ');
                    }
                }
            }

            if (maxLength > 0 && sb.Length > maxLength - 1)
            {
                sb.Length = maxLength - 1;
                sb.Append(".");

                sb[0] = char.ToUpperInvariant(sb[0]);
            }

            return sb.ToString();
        }
Пример #10
0
        /// <summary>
        /// Generates extra operations for a batch response.
        /// </summary>
        /// <param name="random">Random generator for generating extra payloads.</param>
        /// <param name="model">Model to add any generated types to.</param>
        /// <param name="version">Maximum version of generated types.</param>
        /// <returns></returns>
        public static IMimePart[] ExtraResponseOperations(
            IRandomNumberGenerator random,
            EdmModel model       = null,
            ODataVersion version = ODataVersion.V4)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");

            List <ODataResponse> responses = new List <ODataResponse>();
            ODataResponse        response  = null;

            for (int x = 0; x < 5; ++x)
            {
                response = new ODataResponse(new HttpResponseData()
                {
                    StatusCode = (HttpStatusCode)random.Next(500)
                })
                {
                    RootElement = random.ChooseFrom(new[] { null, RandomPayloadBuilder.GetRandomPayload(random, model, version) })
                };
                response.Headers.Add("ResponseHeader", "ResponseHeaderValue");
                responses.Add(response);
            }

            return(responses.ToArray());
        }
Пример #11
0
        private static EntityInstance GetEntityInstance(IRandomNumberGenerator random, EdmModel model = null, ODataVersion version = ODataVersion.V4)
        {
            var values = TestEntityInstances.CreateEntityInstanceTestDescriptors(model, true);

            var payloadDescriptor = random.ChooseFrom(values);
            var payload           = (EntityInstance)payloadDescriptor.PayloadElement;

            return(payload);
        }
Пример #12
0
        private static PrimitiveCollection GetPrimitiveCollection(IRandomNumberGenerator random)
        {
            TestValues.CreatePrimitiveValuesWithMetadata(true);
            PrimitiveValue val      = random.ChooseFrom(TestValues.CreatePrimitiveValuesWithMetadata(true));
            int            numItems = random.NextFromRange(1, 3);
            var            newItems = Enumerable.Range(0, numItems).Select(x => TestValues.GetDifferentPrimitiveValue(val));
            var            payload  = new PrimitiveCollection(newItems.ToArray());

            return(payload);
        }
Пример #13
0
        /// <summary>
        /// Generates random string of specified length.
        /// </summary>
        /// <param name="random">The random number generator to use.</param>
        /// <param name="minLength">Minimum length of the generated string.</param>
        /// <param name="maxLength">Maximum length of the generated string.</param>
        /// <returns>Generated string.</returns>
        public string GenerateString(IRandomNumberGenerator random, int minLength, int maxLength)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckValidRange(minLength, "minLength", maxLength, "maxLength");

            var selectedGenerator = random.ChooseFrom(this.generators, this.weights);
            if (selectedGenerator == null)
            {
                throw new TaupoInvalidOperationException("Unable to select a string generator. Check the weights.");
            }

            return selectedGenerator.GenerateString(random, minLength, maxLength);
        }
Пример #14
0
        /// <summary>
        /// Generates random string of specified length.
        /// </summary>
        /// <param name="random">The random number generator to use.</param>
        /// <param name="minLength">Minimum length of the generated string.</param>
        /// <param name="maxLength">Maximum length of the generated string.</param>
        /// <returns>Generated string.</returns>
        public string GenerateString(IRandomNumberGenerator random, int minLength, int maxLength)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckValidRange(minLength, "minLength", maxLength, "maxLength");

            var selectedGenerator = random.ChooseFrom(this.generators, this.weights);

            if (selectedGenerator == null)
            {
                throw new TaupoInvalidOperationException("Unable to select a string generator. Check the weights.");
            }

            return(selectedGenerator.GenerateString(random, minLength, maxLength));
        }
        /// <summary>
        /// When overridden in a derived class, generates a random string of specified length
        /// </summary>
        /// <param name="random">The random number generator to use.</param>
        /// <param name="minLength">Minimum length of the generated string.</param>
        /// <param name="maxLength">Maximum length of the generated string.</param>
        /// <returns>Generated string.</returns>
        protected override string GenerateStringCore(IRandomNumberGenerator random, int minLength, int maxLength)
        {
            this.EnsureAlphabetLoaded();
            var minimumCharacterLength = this.alphabet.Min(w => w.Length);

            var desiredLength = random.NextFromRange(minLength, maxLength);

            // This is an intentionally naive check to determine whether the desired length
            // is actually one that this resource string generator can satisfy. Since the minimum
            // length of existing alphabets is either 1 or 2, and the alphabet that has
            // characters of length 2 has no characters of length 3 or more, then this check works.
            if ((desiredLength % minimumCharacterLength) != 0)
            {
                // Get the closest length to the randomly chosen length that is also a multiple
                // of minimumCharacterLength. Note that the integer division between desiredLength
                // and minimumCharacterLength is intentional.
                desiredLength = (desiredLength / minimumCharacterLength) * minimumCharacterLength;

                if (desiredLength < minLength)
                {
                    desiredLength += minimumCharacterLength;
                }

                if (desiredLength > maxLength)
                {
                    throw new TaupoArgumentException(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "This string generator cannot generate a string of a length between {0} and {1}.",
                            minLength,
                            maxLength));
                }
            }

            StringBuilder sb = new StringBuilder(desiredLength);
            while (sb.Length < desiredLength)
            {
                var next = random.ChooseFrom(this.alphabet);

                if (next.Length + sb.Length > desiredLength)
                {
                    next = random.ChooseFrom(this.alphabet.Where(w => w.Length == minimumCharacterLength));
                }

                sb.Append(next);
            }

            return sb.ToString();
        }
Пример #16
0
        /// <summary>
        /// Randomly chooses random number of items from the specified list. It may randomly choose 0 or all items.
        /// </summary>
        /// <typeparam name="T">List element type.</typeparam>
        /// <param name="random">The random number generator.</param>
        /// <param name="items">The list to choose from.</param>
        /// <returns>Selected items.</returns>
        public static IEnumerable <T> ChooseRandomNumberOfItemsFrom <T>(this IRandomNumberGenerator random, IEnumerable <T> items)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckArgumentNotNull(items, "items");

            int maxCount = items.Count();

            if (maxCount == 0)
            {
                return(Enumerable.Empty <T>());
            }

            int count = random.Next(maxCount + 1);

            return(random.ChooseFrom(items, count, false));
        }
Пример #17
0
        public static QueryValue ChooseRandomEvaluationResult(this IQueryExpressionEvaluator evaluator, QueryExpression queryExpression, IRandomNumberGenerator random, out QueryCollectionValue collection)
        {
            ExceptionUtilities.CheckArgumentNotNull(evaluator, "evaluator");
            ExceptionUtilities.CheckArgumentNotNull(queryExpression, "queryExpression");
            ExceptionUtilities.CheckArgumentNotNull(random, "random");

            collection = evaluator.Evaluate(queryExpression) as QueryCollectionValue;
            ExceptionUtilities.CheckObjectNotNull(collection, "Query unexpectedly evaluated to null or was not a collection: {0}", queryExpression);
            ExceptionUtilities.Assert(collection.EvaluationError == null, "Query resulted in evaluation error: {0}", collection.EvaluationError);

            if (collection.IsNull || collection.Elements.Count == 0)
            {
                return(null);
            }

            return(random.ChooseFrom(collection.Elements));
        }
        /// <summary>
        /// When overridden in a derived class, generates a random string of specified length
        /// </summary>
        /// <param name="random">The random number generator to use.</param>
        /// <param name="minLength">Minimum length of the generated string.</param>
        /// <param name="maxLength">Maximum length of the generated string.</param>
        /// <returns>Generated string.</returns>
        protected virtual string GenerateStringCore(IRandomNumberGenerator random, int minLength, int maxLength)
        {
            int length = random.NextFromRange(minLength, maxLength);
            var alphabet = this.GetAlphabet();

            StringBuilder sb = new StringBuilder(length);
            while (sb.Length < length)
            {
                sb.Append(random.ChooseFrom(alphabet));
            }

            if (sb.Length > maxLength)
            {
                sb.Length = maxLength;
            }

            return sb.ToString();
        }
Пример #19
0
        /// <summary>
        /// Randomly chooses <paramref name="count"/> number of elements from the specified list.
        /// </summary>
        /// <typeparam name="T">List element type.</typeparam>
        /// <param name="random">The random number generator.</param>
        /// <param name="items">The list to choose from.</param>
        /// <param name="count">The count of elements to choose.</param>
        /// <param name="allowDuplicates">The value indicating if duplicates allowed or not.</param>
        /// <returns>Selected items.</returns>
        public static IEnumerable <T> ChooseFrom <T>(this IRandomNumberGenerator random, IEnumerable <T> items, int count, bool allowDuplicates)
        {
            ExceptionUtilities.CheckArgumentNotNull(items, "items");
            if (count < 0)
            {
                throw new TaupoArgumentException("Count cannot be negative.");
            }

            List <T> values = new List <T>();

            for (int i = 0; i < count; i++)
            {
                T value = random.ChooseFrom(items.Where(item => allowDuplicates || !values.Contains(item)));
                values.Add(value);
            }

            return(values.AsReadOnly());
        }
        /// <summary>
        /// When overridden in a derived class, generates a random string of specified length
        /// </summary>
        /// <param name="random">The random number generator to use.</param>
        /// <param name="minLength">Minimum length of the generated string.</param>
        /// <param name="maxLength">Maximum length of the generated string.</param>
        /// <returns>Generated string.</returns>
        protected virtual string GenerateStringCore(IRandomNumberGenerator random, int minLength, int maxLength)
        {
            int length   = random.NextFromRange(minLength, maxLength);
            var alphabet = this.GetAlphabet();

            StringBuilder sb = new StringBuilder(length);

            while (sb.Length < length)
            {
                sb.Append(random.ChooseFrom(alphabet));
            }

            if (sb.Length > maxLength)
            {
                sb.Length = maxLength;
            }

            return(sb.ToString());
        }
Пример #21
0
        private static PrimitiveValue GetPrimitiveValue(IRandomNumberGenerator random, EdmModel model = null)
        {
            var payload = random.ChooseFrom(TestValues.CreatePrimitiveValuesWithMetadata(true));

            if (model != null)
            {
                EdmEntityType entity = model.FindDeclaredType("AllPrimitiveTypesEntity") as EdmEntityType;
                if (entity == null)
                {
                    entity = new EdmEntityType("TestModel", "AllPrimitiveTypesEntity");
                    entity.AddStructuralProperty("StringPropNullable", EdmPrimitiveTypeKind.String, true);
                    entity.AddStructuralProperty("StringProp", EdmPrimitiveTypeKind.String, false);
                    entity.AddStructuralProperty("Int32PropNullable", EdmPrimitiveTypeKind.Int32, true);
                    entity.AddStructuralProperty("Int32Prop", EdmPrimitiveTypeKind.Int32, false);
                    entity.AddStructuralProperty("BooleanPropNullable", EdmPrimitiveTypeKind.Boolean, true);
                    entity.AddStructuralProperty("BooleanProp", EdmPrimitiveTypeKind.Boolean, false);
                    entity.AddStructuralProperty("BytePropNullable", EdmPrimitiveTypeKind.Byte, true);
                    entity.AddStructuralProperty("ByteProp", EdmPrimitiveTypeKind.Byte, false);
                    entity.AddStructuralProperty("SBytePropNullable", EdmPrimitiveTypeKind.SByte, true);
                    entity.AddStructuralProperty("SByteProp", EdmPrimitiveTypeKind.SByte, false);
                    entity.AddStructuralProperty("Int16PropNullable", EdmPrimitiveTypeKind.Int16, true);
                    entity.AddStructuralProperty("Int16Prop", EdmPrimitiveTypeKind.Int16, false);
                    entity.AddStructuralProperty("DecimalPropNullable", EdmPrimitiveTypeKind.Decimal, true);
                    entity.AddStructuralProperty("DecimalProp", EdmPrimitiveTypeKind.Decimal, false);
                    entity.AddStructuralProperty("SinglePropNullable", EdmPrimitiveTypeKind.Single, true);
                    entity.AddStructuralProperty("SingleProp", EdmPrimitiveTypeKind.Single, false);
                    entity.AddStructuralProperty("Int64PropNullable", EdmPrimitiveTypeKind.Int64, true);
                    entity.AddStructuralProperty("Int64Prop", EdmPrimitiveTypeKind.Int64, false);
                    entity.AddStructuralProperty("DoublePropNullable", EdmPrimitiveTypeKind.Double, true);
                    entity.AddStructuralProperty("DoubleProp", EdmPrimitiveTypeKind.Double, false);
                    entity.AddStructuralProperty("BinaryPropNullable", EdmPrimitiveTypeKind.Binary, true);
                    entity.AddStructuralProperty("BinaryProp", EdmPrimitiveTypeKind.Binary, false);
                    entity.AddStructuralProperty("GuidPropNullable", EdmPrimitiveTypeKind.Guid, true);
                    entity.AddStructuralProperty("GuidProp", EdmPrimitiveTypeKind.Guid, false);
                    model.AddElement(entity);
                }

                payload.WithTypeAnnotation(entity);
            }

            return(payload);
        }
Пример #22
0
        /// <summary>
        /// Generates random string of specified length
        /// </summary>
        /// <param name="random">The random number generator to use.</param>
        /// <param name="minLength">Minimum length of the generated string.</param>
        /// <param name="maxLength">Maximum length of the generated string.</param>
        /// <returns>Generated string.</returns>
        public string GenerateString(IRandomNumberGenerator random, int minLength, int maxLength)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckValidRange(minLength, "minLength", maxLength, "maxLength");

            var alphabet = this.GetWordList();
            int length = random.NextFromRange(minLength, maxLength);

            StringBuilder sb = new StringBuilder(length);
            while (sb.Length < length)
            {
                sb.Append(random.ChooseFrom(alphabet));
            }

            if (sb.Length > maxLength)
            {
                sb.Length = maxLength;
            }

            return sb.ToString();
        }
Пример #23
0
        /// <summary>
        /// Generates random string of specified length
        /// </summary>
        /// <param name="random">The random number generator to use.</param>
        /// <param name="minLength">Minimum length of the generated string.</param>
        /// <param name="maxLength">Maximum length of the generated string.</param>
        /// <returns>Generated string.</returns>
        public string GenerateString(IRandomNumberGenerator random, int minLength, int maxLength)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckValidRange(minLength, "minLength", maxLength, "maxLength");

            var alphabet = this.GetWordList();
            int length   = random.NextFromRange(minLength, maxLength);

            StringBuilder sb = new StringBuilder(length);

            while (sb.Length < length)
            {
                sb.Append(random.ChooseFrom(alphabet));
            }

            if (sb.Length > maxLength)
            {
                sb.Length = maxLength;
            }

            return(sb.ToString());
        }
Пример #24
0
        /// <summary>
        /// Generates random string of specified length
        /// </summary>
        /// <param name="random">The random number generator to use.</param>
        /// <param name="minLength">Minimum length of the generated string.</param>
        /// <param name="maxLength">Maximum length of the generated string.</param>
        /// <returns>Generated string.</returns>
        public string GenerateString(IRandomNumberGenerator random, int minLength, int maxLength)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckValidRange(minLength, "minLength", maxLength, "maxLength");

            int wordCount = random.NextFromRange(2, 10);
            int length    = random.NextFromRange(minLength, maxLength);

            StringBuilder sb = new StringBuilder();

            while (sb.Length < length)
            {
                string word = this.wordGenerator.GenerateString(random, 2, Math.Max(3, length / wordCount));

                sb.Append(word);
                if (sb.Length < length)
                {
                    sb.Append(' ');
                    if (random.Next(100) < 30)
                    {
                        sb.Append(random.ChooseFrom(glueWords));
                        sb.Append(' ');
                    }
                }
            }

            if (maxLength > 0 && sb.Length > maxLength - 1)
            {
                sb.Length = maxLength - 1;
                sb.Append(".");

                sb[0] = char.ToUpperInvariant(sb[0]);
            }

            return(sb.ToString());
        }
Пример #25
0
        private static ComplexMultiValueProperty GetComplexMultiValueProperty(IRandomNumberGenerator random, EdmModel model = null, ODataVersion version = ODataVersion.V4)
        {
            
            int numinstances = random.ChooseFrom(new[] { 0, 1, 3 });
            var instance = GetComplexInstance(random, model, version);
            var instances = GenerateSimilarComplexInstances(random, instance, numinstances, true);
            var propertyName = "ComplexMultivalue" + instance.FullTypeName;
            var payload = new ComplexMultiValueProperty(propertyName,
                new ComplexMultiValue(propertyName, false, instances.ToArray()));
            if (model != null)
            {
                var entityDataType = instance.GetAnnotation<EntityModelTypeAnnotation>().EdmModelType.Definition as IEdmEntityType;
                ExceptionUtilities.CheckObjectNotNull(entityDataType, "Complex Instance must have an EntityModelTypeAnnotation with an EntityDataType");
                var entityType = model.FindDeclaredType(entityDataType.FullName()) as EdmEntityType;

                ExceptionUtilities.CheckObjectNotNull(entityType, "entityType");
                if (entityType.FindProperty(propertyName) != null)
                {
                    entityType.AddStructuralProperty(propertyName, (model.FindDeclaredType(instance.FullTypeName) as EdmComplexType).ToTypeReference());
                }

                payload.WithTypeAnnotation(entityType);
            }

            return payload;
        }
Пример #26
0
        private static EntityInstance GetEntityInstance(IRandomNumberGenerator random, EdmModel model = null, ODataVersion version = ODataVersion.V4)
        {
            var values = TestEntityInstances.CreateEntityInstanceTestDescriptors(model, true);

            var payloadDescriptor = random.ChooseFrom(values);
            var payload = (EntityInstance)payloadDescriptor.PayloadElement;
            
            return payload;
        }
Пример #27
0
        private static ODataErrorPayload GetODataErrorPayload(IRandomNumberGenerator random)
        {
            var testErrors = random.ChooseFrom(TestErrors.CreateErrorTestDescriptors());

            return((ODataErrorPayload)testErrors.PayloadElement);
        }
Пример #28
0
        private static EntitySetInstance GetEntitySetInstance(IRandomNumberGenerator random, EdmModel model = null)
        {
            var payloadDescriptor = random.ChooseFrom(TestFeeds.CreateEntitySetTestDescriptors(model, true));

            return((EntitySetInstance)payloadDescriptor.PayloadElement);
        }
Пример #29
0
        /// <summary>
        /// Generates extra response changesets.
        /// </summary>
        /// <param name="random">For generating arbitrary changesets.</param>
        /// <param name="model">For adding any generated types to.</param>
        /// <param name="version">Maximum version of any generated types.</param>
        /// <returns>An array of response changesets.</returns>
        public static BatchResponseChangeset[] ExtraResponseChangesets(
            IRandomNumberGenerator random,
            EdmModel model       = null,
            ODataVersion version = ODataVersion.V4)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");

            string contentType = HttpUtilities.BuildContentType(MimeTypes.ApplicationXml, Encoding.UTF8.WebName, null);

            var responses = ExtraResponseOperations(random, model, version);
            List <BatchResponseChangeset> changesets = new List <BatchResponseChangeset>();

            for (int x = 0; x < 5; ++x)
            {
                IEnumerable <IMimePart> operations = Enumerable.Range(0, random.Next(4)).Select(i => random.ChooseFrom(responses));
                changesets.Add(BatchPayloadBuilder.ResponseChangeset("changeset_" + Guid.NewGuid().ToString(), contentType, operations.ToArray()));
            }

            return(changesets.ToArray());
        }
Пример #30
0
        private static ComplexInstance GetComplexInstance(IRandomNumberGenerator random, EdmModel model = null, ODataVersion version = ODataVersion.V4)
        {
            var values = TestValues.CreateComplexValues(model, true, true);

            return(random.ChooseFrom(values));
        }
Пример #31
0
        /// <summary>
        /// Generates extra request changesets.
        /// </summary>
        /// <param name="random">For generating arbitrary changesets.</param>
        /// <param name="requestManager">For building changesets.</param>
        /// <param name="model">For adding any generated types to.</param>
        /// <param name="baseUri">Base uri for the changesets.</param>
        /// <param name="version">Maximum version of any generated types.</param>
        /// <returns>An array of request changesets.</returns>
        public static BatchRequestChangeset[] ExtraRequestChangesets(
            IRandomNumberGenerator random,
            IODataRequestManager requestManager,
            EdmModel model,
            ODataUri baseUri,
            ODataVersion version = ODataVersion.V4
            )
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckArgumentNotNull(requestManager, "requestManager");
            ExceptionUtilities.CheckArgumentNotNull(baseUri, "baseUri");

            var headers = new Dictionary<string, string> { { "RequestHeader", "RequestHeaderValue" } };
            string mergeContentType = HttpUtilities.BuildContentType(MimeTypes.ApplicationXml, Encoding.UTF8.WebName, null);

            var requests = ExtraRequestChangesetOperations(random, requestManager, model, baseUri, version);

            List<BatchRequestChangeset> changesets = new List<BatchRequestChangeset>();
            for (int x = 0; x < 5; ++x)
            {
                IEnumerable<IHttpRequest> operations = Enumerable.Range(0, random.Next(10)).Select(i => random.ChooseFrom(requests));
                changesets.Add(BatchPayloadBuilder.RequestChangeset("changeset_" + Guid.NewGuid().ToString(), "", operations.ToArray()));
            }

            return changesets.ToArray();
        }
Пример #32
0
        /// <summary>
        /// Puts the specified <paramref name="payload"/> into a changeset.
        /// </summary>
        /// <param name="response">ODataResponse to add to changeset.</param>
        /// <param name="random">Random generator used for generating payloads.</param>
        /// <param name="model">Model to add generated types to.</param>
        /// <param name="operationsBefore">Number of extra operations before payload.</param>
        /// <param name="operationsAfter">Number of extra operations after payload.</param>
        /// <param name="version">Highest version of allowed features.</param>
        /// <returns>An entry payload with an expanded link that contains the specified<paramref name="payload"/>.</returns>
        public static BatchResponseChangeset InResponseChangeset <T>(
            this ODataResponse response,
            IRandomNumberGenerator random,
            EdmModel model       = null,
            int operationsBefore = 0,
            int operationsAfter  = 0,
            ODataVersion version = ODataVersion.V4
            ) where T : PayloadTestDescriptor
        {
            ExceptionUtilities.CheckArgumentNotNull(response, "response");
            ExceptionUtilities.CheckArgumentNotNull(random, "random");

            var extraOperations = BatchUtils.ExtraResponseOperations(random, model, version);

            // Build the list of all properties
            IEnumerable <IMimePart> operations = Enumerable.Range(0, operationsBefore).Select(i => random.ChooseFrom(extraOperations));

            operations.ConcatSingle(response);
            operations = operations.Concat(Enumerable.Range(0, operationsAfter).Select(i => random.ChooseFrom(extraOperations)));

            var changeset = BatchPayloadBuilder.ResponseChangeset("changeset_" + Guid.NewGuid().ToString(), Encoding.UTF8.WebName, operations.ToArray());

            return(changeset);
        }
Пример #33
0
        private static PrimitiveMultiValueProperty GetPrimitiveMultiValueProperty(IRandomNumberGenerator random)
        {
            var val = random.ChooseFrom(TestValues.CreatePrimitiveCollections(true, true));
            var payload = new PrimitiveMultiValueProperty("ArbitraryMultivalue", val);

            return payload;
        }
Пример #34
0
        private static PrimitiveValue GetPrimitiveValue(IRandomNumberGenerator random, EdmModel model = null)
        {
            var payload = random.ChooseFrom(TestValues.CreatePrimitiveValuesWithMetadata(true));
            
            if (model != null)
            {
                EdmEntityType entity = model.FindDeclaredType("AllPrimitiveTypesEntity") as EdmEntityType; 
                if (entity == null)
                {
                    entity = new EdmEntityType("TestModel", "AllPrimitiveTypesEntity");
                    entity.AddStructuralProperty("StringPropNullable", EdmPrimitiveTypeKind.String, true);
                    entity.AddStructuralProperty("StringProp", EdmPrimitiveTypeKind.String, false);
                    entity.AddStructuralProperty("Int32PropNullable", EdmPrimitiveTypeKind.Int32, true);
                    entity.AddStructuralProperty("Int32Prop", EdmPrimitiveTypeKind.Int32, false);
                    entity.AddStructuralProperty("BooleanPropNullable", EdmPrimitiveTypeKind.Boolean, true);
                    entity.AddStructuralProperty("BooleanProp", EdmPrimitiveTypeKind.Boolean, false);
                    entity.AddStructuralProperty("BytePropNullable", EdmPrimitiveTypeKind.Byte, true);
                    entity.AddStructuralProperty("ByteProp", EdmPrimitiveTypeKind.Byte, false);
                    entity.AddStructuralProperty("SBytePropNullable", EdmPrimitiveTypeKind.SByte, true);
                    entity.AddStructuralProperty("SByteProp", EdmPrimitiveTypeKind.SByte, false);
                    entity.AddStructuralProperty("Int16PropNullable", EdmPrimitiveTypeKind.Int16, true);
                    entity.AddStructuralProperty("Int16Prop", EdmPrimitiveTypeKind.Int16, false);
                    entity.AddStructuralProperty("DecimalPropNullable", EdmPrimitiveTypeKind.Decimal, true);
                    entity.AddStructuralProperty("DecimalProp", EdmPrimitiveTypeKind.Decimal, false);
                    entity.AddStructuralProperty("SinglePropNullable", EdmPrimitiveTypeKind.Single, true);
                    entity.AddStructuralProperty("SingleProp", EdmPrimitiveTypeKind.Single, false);
                    entity.AddStructuralProperty("Int64PropNullable", EdmPrimitiveTypeKind.Int64, true);
                    entity.AddStructuralProperty("Int64Prop", EdmPrimitiveTypeKind.Int64, false);
                    entity.AddStructuralProperty("DoublePropNullable", EdmPrimitiveTypeKind.Double, true);
                    entity.AddStructuralProperty("DoubleProp", EdmPrimitiveTypeKind.Double, false);
                    entity.AddStructuralProperty("BinaryPropNullable", EdmPrimitiveTypeKind.Binary, true);
                    entity.AddStructuralProperty("BinaryProp", EdmPrimitiveTypeKind.Binary, false);
                    entity.AddStructuralProperty("GuidPropNullable", EdmPrimitiveTypeKind.Guid, true);
                    entity.AddStructuralProperty("GuidProp", EdmPrimitiveTypeKind.Guid, false);
                    model.AddElement(entity);
                }

                payload.WithTypeAnnotation(entity);
            }

            return payload;
        }
Пример #35
0
        /// <summary>
        /// Generates extra response changesets.
        /// </summary>
        /// <param name="random">For generating arbitrary changesets.</param>
        /// <param name="model">For adding any generated types to.</param>
        /// <param name="version">Maximum version of any generated types.</param>
        /// <returns>An array of response changesets.</returns>
        public static BatchResponseChangeset[] ExtraResponseChangesets(
            IRandomNumberGenerator random, 
            EdmModel model = null, 
            ODataVersion version = ODataVersion.V4)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            
            string contentType = HttpUtilities.BuildContentType(MimeTypes.ApplicationXml, Encoding.UTF8.WebName, null);

            var responses = ExtraResponseOperations(random, model, version);
            List<BatchResponseChangeset> changesets = new List<BatchResponseChangeset>();
            for (int x = 0; x < 5; ++x)
            {
                IEnumerable<IMimePart> operations = Enumerable.Range(0, random.Next(4)).Select(i => random.ChooseFrom(responses));
                changesets.Add(BatchPayloadBuilder.ResponseChangeset("changeset_" + Guid.NewGuid().ToString(), contentType, operations.ToArray()));
            }

            return changesets.ToArray();
        }
Пример #36
0
        /// <summary>
        /// Generates extra operations for a batch response.
        /// </summary>
        /// <param name="random">Random generator for generating extra payloads.</param>
        /// <param name="model">Model to add any generated types to.</param>
        /// <param name="version">Maximum version of generated types.</param>
        /// <returns></returns>
        public static IMimePart[] ExtraResponseOperations(
            IRandomNumberGenerator random, 
            EdmModel model = null, 
            ODataVersion version = ODataVersion.V4)
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");

            List<ODataResponse> responses = new List<ODataResponse>();
            ODataResponse response = null;
            for (int x = 0; x < 5; ++x)
            {
                response = new ODataResponse(new HttpResponseData() { StatusCode = (HttpStatusCode)random.Next(500) })
                {
                    RootElement = random.ChooseFrom(new[] { null, RandomPayloadBuilder.GetRandomPayload(random, model, version) })
                };
                response.Headers.Add("ResponseHeader", "ResponseHeaderValue");
                responses.Add(response);
            }

            return responses.ToArray();
        }
Пример #37
0
        private static ComplexInstance GetComplexInstance(IRandomNumberGenerator random, EdmModel model = null, ODataVersion version = ODataVersion.V4)
        {
            var values = TestValues.CreateComplexValues(model, true, true);

            return random.ChooseFrom(values);
        }
Пример #38
0
 private static ODataErrorPayload GetODataErrorPayload(IRandomNumberGenerator random)
 {
     var testErrors = random.ChooseFrom(TestErrors.CreateErrorTestDescriptors());
     return (ODataErrorPayload)testErrors.PayloadElement;
 }
Пример #39
0
 /// <summary>
 /// Predefined data generator which selects a value from a predefined set of values
 /// </summary>
 /// <typeparam name="TData">The data type</typeparam>
 /// <param name="random">A Random number generator to allow the framework to pick a random value from the set of values</param>
 /// <param name="values">The set of allowed values</param>
 /// <returns>predefined data generator</returns>
 public static IDataGenerator <TData> PredefinedValues <TData>(IRandomNumberGenerator random, params TData[] values)
 {
     ExceptionUtilities.CheckArgumentNotNull(random, "random");
     ExceptionUtilities.CheckCollectionNotEmpty(values, "values");
     return(new DelegatedDataGenerator <TData>(() => random.ChooseFrom(values)));
 }
Пример #40
0
 private static EntitySetInstance GetEntitySetInstance(IRandomNumberGenerator random, EdmModel model = null)
 {
     var payloadDescriptor = random.ChooseFrom(TestFeeds.CreateEntitySetTestDescriptors(model, true));
     return (EntitySetInstance)payloadDescriptor.PayloadElement;
 }
Пример #41
0
        /// <summary>
        /// Puts the specified <paramref name="payload"/> into a changeset.
        /// </summary>
        /// <param name="payload">The payload to be used as content for the expanded link.</param>
        /// <param name="verb">The verb associated with the payload.</param>
        /// <param name="random">Use of random makes this method non deterministic.</param>
        /// <param name="requestManager">Used to construct requests</param>
        /// <param name="operationsBefore">Number of extra operations before payload.</param>
        /// <param name="operationsAfter">Number of extra operations after payload.</param>
        /// <param name="version">Highest version of allowed features</param>
        /// <returns>An entry payload with an expanded link that contains the specified <paramref name="payload"/>.</returns>
        public static BatchRequestChangeset InRequestChangeset <T>(
            this T payload,
            HttpVerb verb,
            IRandomNumberGenerator random,
            IODataRequestManager requestManager,
            int operationsBefore = 0,
            int operationsAfter  = 0,
            ODataVersion version = ODataVersion.V4
            ) where T : PayloadTestDescriptor
        {
            ExceptionUtilities.CheckArgumentNotNull(payload, "payload");
            ExceptionUtilities.CheckArgumentNotNull(verb, "verb");
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckArgumentNotNull(requestManager, "requestManager");

            var baseUri         = new ODataUri(ODataUriBuilder.Root(new Uri("http://www.odata.org/service.svc")));
            var extraOperations = BatchUtils.ExtraRequestChangesetOperations(random, requestManager, (EdmModel)payload.PayloadEdmModel, baseUri, version);

            // Build the list of all properties
            IEnumerable <IHttpRequest> operations = Enumerable.Range(0, operationsBefore).Select(i => random.ChooseFrom(extraOperations));

            operations.ConcatSingle(payload.InRequestOperation(verb, baseUri, requestManager));
            operations = operations.Concat(Enumerable.Range(0, operationsAfter).Select(i => extraOperations[extraOperations.Length - 1 - (i % extraOperations.Length)]));

            var changeset = BatchPayloadBuilder.RequestChangeset("changeset_" + Guid.NewGuid().ToString(), Encoding.UTF8.WebName, operations.ToArray());

            return(changeset);
        }
Пример #42
0
        /// <summary>
        /// Generates extra request changesets.
        /// </summary>
        /// <param name="random">For generating arbitrary changesets.</param>
        /// <param name="requestManager">For building changesets.</param>
        /// <param name="model">For adding any generated types to.</param>
        /// <param name="baseUri">Base uri for the changesets.</param>
        /// <param name="version">Maximum version of any generated types.</param>
        /// <returns>An array of request changesets.</returns>
        public static BatchRequestChangeset[] ExtraRequestChangesets(
            IRandomNumberGenerator random,
            IODataRequestManager requestManager,
            EdmModel model,
            ODataUri baseUri,
            ODataVersion version = ODataVersion.V4
            )
        {
            ExceptionUtilities.CheckArgumentNotNull(random, "random");
            ExceptionUtilities.CheckArgumentNotNull(requestManager, "requestManager");
            ExceptionUtilities.CheckArgumentNotNull(baseUri, "baseUri");

            var headers = new Dictionary <string, string> {
                { "RequestHeader", "RequestHeaderValue" }
            };
            string mergeContentType = HttpUtilities.BuildContentType(MimeTypes.ApplicationXml, Encoding.UTF8.WebName, null);

            var requests = ExtraRequestChangesetOperations(random, requestManager, model, baseUri, version);

            List <BatchRequestChangeset> changesets = new List <BatchRequestChangeset>();

            for (int x = 0; x < 5; ++x)
            {
                IEnumerable <IHttpRequest> operations = Enumerable.Range(0, random.Next(10)).Select(i => random.ChooseFrom(requests));
                changesets.Add(BatchPayloadBuilder.RequestChangeset("changeset_" + Guid.NewGuid().ToString(), "", operations.ToArray()));
            }

            return(changesets.ToArray());
        }
Пример #43
0
        private static PrimitiveCollection GetPrimitiveCollection(IRandomNumberGenerator random)
        {
            TestValues.CreatePrimitiveValuesWithMetadata(true);
            PrimitiveValue val = random.ChooseFrom(TestValues.CreatePrimitiveValuesWithMetadata(true));
            int numItems = random.NextFromRange(1, 3);
            var newItems = Enumerable.Range(0, numItems).Select(x => TestValues.GetDifferentPrimitiveValue(val));
            var payload = new PrimitiveCollection(newItems.ToArray());

            return payload;
        }
Пример #44
0
        private static ComplexInstanceCollection GetComplexInstanceCollection(IRandomNumberGenerator random, EdmModel model = null, ODataVersion version = ODataVersion.V4)
        {
            var complex = GetComplexInstance(random, model, version);
            int numinstances = random.ChooseFrom(new[] { 0, 1, 3 });
            var payload = new ComplexInstanceCollection(GenerateSimilarComplexInstances(random, complex, numinstances).ToArray());
            if (model != null)
            {
                var container = model.EntityContainersAcrossModels().Single() as EdmEntityContainer;
                var collectionType = new EdmCollectionType((model.FindDeclaredType(complex.FullTypeName) as EdmComplexType).ToTypeReference());

                var function = new EdmFunction(container.Namespace, "GetComplexInstances", collectionType.ToTypeReference());
                var functionImport = container.AddFunctionImport("GetComplexInstances", function);

                payload.AddAnnotation(new FunctionAnnotation() { FunctionImport = functionImport });
                payload.AddAnnotation(new DataTypeAnnotation() { EdmDataType = collectionType });
            }

            return payload;
        }