예제 #1
0
        /// <summary>
        /// Initializes the test module.
        /// </summary>
        /// <remarks>
        /// Can be overridden by derived classes to provide extra initialization.
        /// </remarks>
        public override void Init()
        {
            this.rootLogger = this.Log;

            // this is to give LTM a chance to set up our TestParameters (which are not available until just before
            // Init()
            var onInit = this.OnInitialize;

            if (onInit != null)
            {
                onInit(this, new EventArgs());
            }

            if (this.TestParameters.ContainsKey("Help"))
            {
                this.ShowHelp();
                throw new TestSkippedException("Help");
            }

            this.Log.WriteLine(LogLevel.Verbose, typeof(TestModule).Name + " is initializing. Pass Help=true parameter to display list of available options.");
            this.Log.WriteLine(LogLevel.Verbose, "Module-level exploration seed was: {0}", this.ExplorationSeed);
            this.ConfigureDependencyInjectionContainer();
            this.SetupDefaultWorkspace();
            AsyncExecutionContext.EnqueueSynchronousAction(() => this.InjectDependenciesIntoChildren(this));
        }
        internal IAsyncResult BeginInvoke <TRequest>(TRequest request,
                                                     IMarshaller <IRequest, WebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller,
                                                     AsyncCallback callback, object state)
            where TRequest : WebServiceRequest
        {
            ThrowIfDisposed();

            var executionContext = new AsyncExecutionContext(
                new AsyncRequestContext()
            {
                ClientConfig    = this.Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Signer          = Signer,
                Unmarshaller    = unmarshaller,
                Callback        = callback,
                State           = state,
                IsAsync         = true
            },
                new AsyncResponseContext()
                );

            var asyncResult = this.RuntimePipeline.InvokeAsync(executionContext);

            return(asyncResult);
        }
예제 #3
0
        protected IAsyncResult BeginInvoke(AmazonWebServiceRequest request,
                                           InvokeOptionsBase options, AsyncCallback callback, object state)
        {
            ThrowIfDisposed();

            var executionContext = new AsyncExecutionContext(
                new AsyncRequestContext(this.Config.LogMetrics, Signer)
            {
                ClientConfig    = this.Config,
                Marshaller      = options.RequestMarshaller,
                OriginalRequest = request,
                Unmarshaller    = options.ResponseUnmarshaller,
                Callback        = callback,
                State           = state,
                IsAsync         = true,
                ServiceMetaData = this.ServiceMetadata,
                Options         = options
            },
                new AsyncResponseContext()
                );

            SetupCSMHandler(executionContext.RequestContext);
            var asyncResult = this.RuntimePipeline.InvokeAsync(executionContext);

            return(asyncResult);
        }
예제 #4
0
        private static void RunInAsyncContext(Action action)
        {
            ReadOnlyCollection <Action <IAsyncContinuation> > actions;

            using (var context = AsyncExecutionContext.Begin())
            {
                action();
                actions = context.GetQueuedActions();
            }

            ManualResetEvent finishedEvent = new ManualResetEvent(false);
            Exception        lastException = null;

            var continuation = AsyncHelpers.CreateContinuation(
                () => finishedEvent.Set(),
                ex => { lastException = ex; finishedEvent.Set(); });

            AsyncHelpers.RunActionSequence(continuation, actions);
            finishedEvent.WaitOne();

            if (lastException != null)
            {
                throw lastException;
            }
        }
예제 #5
0
        protected IAsyncResult BeginInvoke <TRequest>(TRequest request,
                                                      IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller, AsyncOptions asyncOptions,
                                                      Action <AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper)
            where TRequest : AmazonWebServiceRequest
        {
            ThrowIfDisposed();

            asyncOptions = asyncOptions ?? new AsyncOptions();
            var executionContext = new AsyncExecutionContext(
                new AsyncRequestContext(this.Config.LogMetrics, Signer)
            {
                ClientConfig    = this.Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Unmarshaller    = unmarshaller,
                Action          = callbackHelper,
                AsyncOptions    = asyncOptions,
                IsAsync         = true,
                ServiceMetaData = this.ServiceMetadata
            },
                new AsyncResponseContext()
                );

            return(this.RuntimePipeline.InvokeAsync(executionContext));
        }
예제 #6
0
        public void ConstructorFail2()
        {
            IAsyncExecutionContext context = new AsyncExecutionContext();
            var rc = new AsyncRelayCommand <int>(null, async(i, t) => { });

            Assert.IsNotNull(rc);
        }
예제 #7
0
        public void ActionPredicateInvocation()
        {
            IAsyncExecutionContext context = new AsyncExecutionContext();
            var invoked           = false;
            var canExecuteInvoked = false;

            ICommand rc = new AsyncRelayCommand(context,
                                                async(t) => invoked = true,
                                                () =>
            {
                canExecuteInvoked = true;
                return(true);
            });

            Assert.IsFalse(invoked);
            Assert.IsFalse(canExecuteInvoked);

            Assert.IsTrue(rc.CanExecute(null));

            Assert.IsFalse(invoked);
            Assert.IsTrue(canExecuteInvoked);

            canExecuteInvoked = false;

            rc.Execute(null);

            Assert.IsTrue(invoked);
            Assert.IsTrue(canExecuteInvoked);
        }
예제 #8
0
        public void Constructor()
        {
            IAsyncExecutionContext context = new AsyncExecutionContext();
            var rc = new AsyncRelayCommand(context, async(t) => { });

            Assert.IsNotNull(rc);
        }
예제 #9
0
        /// <summary>
        /// Initialize the workspace with streams data
        /// </summary>
        public override void Init()
        {
            base.Init();

            if (!this.SkipNamedStreamsDataPopulation)
            {
                AsyncExecutionContext.EnqueueAsynchronousAction(c => this.StreamsServices.PopulateStreamsData(c));
            }
        }
예제 #10
0
        /// <summary>
        /// Builds the workspace.
        /// </summary>
        /// <returns>
        /// Returns instance of a class which derives from <see cref="Workspace"/>. The instance is not fully
        /// initialized until the current method (Init() or variation) completes asynchronously.
        /// </returns>
        public AstoriaWorkspace BuildWorkspace()
        {
            ExceptionUtilities.CheckAllRequiredDependencies(this);

            var workspace = new AstoriaWorkspace(this);

            AsyncExecutionContext.EnqueueAsynchronousAction(cb => this.BuildWorkspaceAsync(workspace, cb));

            return(workspace);
        }
예제 #11
0
        public void ParameterTransferTest()
        {
            IAsyncExecutionContext context = new AsyncExecutionContext();
            var param = 12356;

            var rc = new AsyncRelayCommand <int>(
                context,
                async(i, t) => Assert.AreEqual(param, i),
                i => i == param);

            rc.Execute(param);
        }
예제 #12
0
 /// <summary>
 /// Configures the child test items in the test case
 /// </summary>
 protected virtual void ConfigureChildTestItems()
 {
     this.testCaseDependencyInjectionContainer.RegisterInstance <IDependencyInjector>(this.testCaseDependencyInjectionContainer);
     this.testCaseDependencyInjectionContainer.InjectDependenciesInto(this);
     this.SetupTestCaseSpecificWorkspace();
     AsyncExecutionContext.EnqueueSynchronousAction(
         () =>
     {
         this.testCaseDependencyInjectionContainer.InjectDependenciesInto(this);
         this.InjectDependenciesIntoChildren();
     });
 }
예제 #13
0
        public void ActionInvokation()
        {
            IAsyncExecutionContext context = new AsyncExecutionContext();
            var invoked = false;

            var rc = new AsyncRelayCommand <int>(context, async(i, t) => invoked = true);

            Assert.IsFalse(invoked);

            rc.Execute(0);

            Assert.IsTrue(invoked);
        }
예제 #14
0
        /// <summary>
        /// Verify the passed expression tree.
        /// </summary>
        /// <param name="expression">The expression tree which will be verified</param>
        public virtual void Verify(QueryExpression expression)
        {
            ExceptionUtilities.CheckAllRequiredDependencies(this);

            this.ThrowSkippedExceptionIfQueryExpressionNotSupported(expression);

            if (this.pendingQueries.Count == 0)
            {
                AsyncExecutionContext.EnqueueAsynchronousAction(this.VerifyAllQueries);
            }

            this.pendingQueries.Add(expression);
        }
예제 #15
0
        public void ActionPredicateInvocationOnExecute()
        {
            IAsyncExecutionContext context = new AsyncExecutionContext();
            var invoked           = false;
            var canExecuteInvoked = false;

            var rc = new AsyncRelayCommand <int>(context, async(i, t) => invoked = true,
                                                 i => { canExecuteInvoked = true; return(true); });

            Assert.IsFalse(invoked);
            Assert.IsFalse(canExecuteInvoked);

            rc.Execute(0);

            Assert.IsTrue(invoked);
            Assert.IsTrue(canExecuteInvoked);
        }
예제 #16
0
        /// <summary>
        /// Verify the passed query tree.
        /// </summary>
        /// <param name="expression">The query tree which will be verified</param>
        public virtual void Verify(QueryExpression expression)
        {
            ExceptionUtilities.CheckAllRequiredDependencies(this);
            ExceptionUtilities.Assert(this.IsAsync, "this verifier can only run async");

            this.ThrowSkippedExceptionIfQueryExpressionNotSupported(expression);

            var resolvedQuery      = this.LinqQueryResolver.Resolve(expression);
            var dataServiceContext = this.DataServiceContextCreator.CreateContext(this.DataServiceContextScope, this.workspace.ContextType, this.workspace.ServiceUri);

            if (this.IsExecuteURI)
            {
                // TODO: update this verifier to call ExecuteUriAndCompare if ExecuteURI test parameter is set to true
            }
            else
            {
                ClientQueryGenerator queryGenerator      = new ClientQueryGenerator(new CSharpGenericTypeBuilder());
                DataServiceContext   clientContext       = dataServiceContext.Product as DataServiceContext;
                CoreLinq.Expression  queryLinqExpression = queryGenerator.Generate(resolvedQuery, clientContext);
                IQueryProvider       queryProvider       = clientContext.CreateQuery <int>("Set").Provider as IQueryProvider;
                DataServiceQuery     dataServiceQuery    = queryProvider.CreateQuery(queryLinqExpression) as DataServiceQuery;

                this.ResultComparer.EnqueueNextQuery(resolvedQuery);
                AsyncExecutionContext.EnqueueAsynchronousAction((queryContinuation) =>
                {
                    this.Log.WriteLine(LogLevel.Info, dataServiceQuery.ToString());
                    QueryValue baselineValue = this.GetBaselineValue(resolvedQuery);
                    DataServiceProtocolVersion maxProtocolVersion = this.workspace.ConceptualModel.GetMaxProtocolVersion();
#if  WINDOWS_PHONE
                    DataServiceProtocolVersion maxClientProtocolVersion = DataServiceProtocolVersion.V4;
#else
                    DataServiceProtocolVersion maxClientProtocolVersion = ((DSC.DataServiceProtocolVersion)dataServiceContext.MaxProtocolVersion.Product).ToTestEnum();
#endif
                    // Calculate version errors
                    ExpectedClientErrorBaseline clientError = this.LinqToAstoriaErrorCalculator.CalculateExpectedClientVersionError(resolvedQuery, true, maxClientProtocolVersion, maxProtocolVersion);
                    if (clientError != null)
                    {
                        this.Log.WriteLine(LogLevel.Info, "Expected client exception: " + clientError.ExpectedExceptionType.ToString());
                    }

                    Type queryType = dataServiceQuery.ElementType;
                    MethodInfo genericExecuteMethod = this.ResultComparer.GetType().GetMethod("ExecuteAndCompare").MakeGenericMethod(queryType);
                    genericExecuteMethod.Invoke(this.ResultComparer, new object[] { queryContinuation, this.IsAsync, dataServiceQuery, baselineValue, clientContext, clientError });
                });
            }
        }
예제 #17
0
        protected IAsyncResult BeginInvoke <TRequest>(TRequest request, IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller, AsyncCallback callback, object state) where TRequest : AmazonWebServiceRequest
        {
            ThrowIfDisposed();
            AsyncExecutionContext executionContext = new AsyncExecutionContext(new AsyncRequestContext(Config.LogMetrics)
            {
                ClientConfig    = Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Signer          = Signer,
                Unmarshaller    = unmarshaller,
                Callback        = callback,
                State           = state,
                IsAsync         = true
            }, new AsyncResponseContext());

            return(RuntimePipeline.InvokeAsync(executionContext));
        }
예제 #18
0
        private AsyncExecutionContext CreateAsyncExecutionContextForListBuckets()
        {
            var listBucketsRequest = new ListBucketsRequest();
            var executionContext   = new AsyncExecutionContext(
                new AsyncRequestContext(true)
            {
                ClientConfig    = new AmazonS3Config(),
                Marshaller      = new ListBucketsRequestMarshaller(),
                OriginalRequest = listBucketsRequest,
                Request         = new ListBucketsRequestMarshaller().Marshall(listBucketsRequest),
                Unmarshaller    = new ListBucketsResponseUnmarshaller()
            },
                new AsyncResponseContext()
                );

            executionContext.RequestContext.Request.Endpoint = new Uri(@"http://ListBuckets");
            return(executionContext);
        }
예제 #19
0
        /// <summary>
        /// Executes the variation asynchonously.
        /// </summary>
        /// <param name="continuation">The continuation.</param>
        public void ExecuteAsync(IAsyncContinuation continuation)
        {
            try
            {
                IEnumerable <Action <IAsyncContinuation> > actions = null;
                using (var context = AsyncExecutionContext.Begin())
                {
                    this.Execute();
                    actions = context.GetQueuedActions();
                }

                AsyncHelpers.RunActionSequence(continuation, actions);
            }
            catch (TargetInvocationException ex)
            {
                continuation.Fail(ex.InnerException);
            }
        }
예제 #20
0
        public void TerminateAsync(IAsyncContinuation continuation)
        {
            ExceptionUtilities.CheckArgumentNotNull(continuation, "continuation");

            try
            {
                IEnumerable <Action <IAsyncContinuation> > actions = null;
                using (var context = AsyncExecutionContext.Begin())
                {
                    this.Terminate();
                    actions = context.GetQueuedActions();
                }

                AsyncHelpers.RunActionSequence(continuation, actions);
            }
            catch (Exception ex)
            {
                continuation.Fail(ex);
            }
        }
예제 #21
0
        public void ConstructorFail()
        {
            IAsyncExecutionContext context = new AsyncExecutionContext();

            _ = new AsyncRelayCommand <int>(context, null);
        }
예제 #22
0
        private void PostObject(PostObjectRequest request, AsyncOptions options, Action <AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper)
        {
            string url;
            string subdomain = request.Region.Equals(RegionEndpoint.USEast1) ? "s3" : "s3-" + request.Region.SystemName;
            IDictionary <string, string> headers = new Dictionary <string, string>();

            if (request.Bucket.IndexOf('.') > -1)
            {
                url = string.Format(CultureInfo.InvariantCulture, "https://{0}.amazonaws.com/{1}/", subdomain, request.Bucket);
            }
            else
            {
                url = string.Format(CultureInfo.InvariantCulture, "https://{0}.{1}.amazonaws.com", request.Bucket, subdomain);
            }
            Uri uri = new Uri(url);

            IHttpRequest <string> webRequest = null;

            if (AWSConfigs.HttpClient == AWSConfigs.HttpClientOption.UnityWWW)
            {
                webRequest = new UnityWwwRequest(uri);
            }
            else
            {
                webRequest = new UnityRequest(uri);
            }

            var boundary = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Replace('=', 'z');

            headers[HeaderKeys.ContentTypeHeader] = string.Format(CultureInfo.InvariantCulture, "multipart/form-data; boundary={0}", boundary);
            headers[HeaderKeys.UserAgentHeader]   = AWSSDKUtils.UserAgentHeader;

            webRequest.Method = "POST";

            using (var reqStream = new MemoryStream())
            {
                request.WriteFormData(boundary, reqStream);

                byte[] boundaryBytes = Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, "--{0}\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n", boundary));

                reqStream.Write(boundaryBytes, 0, boundaryBytes.Length);
                using (var inputStream = null == request.Path ? request.InputStream : File.OpenRead(request.Path))
                {
                    byte[] buf = new byte[1024];
                    int    bytesRead;
                    while ((bytesRead = inputStream.Read(buf, 0, 1024)) > 0)
                    {
                        reqStream.Write(buf, 0, bytesRead);
                    }
                }
                byte[] endBoundaryBytes = Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, "\r\n--{0}--", boundary));
                reqStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
                webRequest.WriteToRequestBody(null, reqStream.ToArray(), headers);

                var callback = ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)request).StreamUploadProgressCallback;
                if (callback != null)
                {
                    webRequest.SetupProgressListeners(reqStream, 0, request, callback);
                }
            }

            var executionContext = new AsyncExecutionContext(
                new AsyncRequestContext(this.Config.LogMetrics, new NullSigner())
            {
                ClientConfig    = this.Config,
                OriginalRequest = request,
                Action          = callbackHelper,
                AsyncOptions    = options,
                IsAsync         = true
            },
                new AsyncResponseContext()
                );

            webRequest.SetRequestHeaders(headers);
            executionContext.RuntimeState = webRequest;


            executionContext.ResponseContext.AsyncResult =
                new RuntimeAsyncResult(executionContext.RequestContext.Callback,
                                       executionContext.RequestContext.State);
            executionContext.ResponseContext.AsyncResult.AsyncOptions = executionContext.RequestContext.AsyncOptions;
            executionContext.ResponseContext.AsyncResult.Action       = executionContext.RequestContext.Action;
            executionContext.ResponseContext.AsyncResult.Request      = executionContext.RequestContext.OriginalRequest;

            webRequest.BeginGetResponse(new AsyncCallback(ProcessPostResponse), executionContext);
        }