예제 #1
0
        private void OnClientCreated(object sender, ClientCreatedArgs e)
        {
            HttpMockServer mockServer = new HttpMockServer(new SimpleRecordMatcher());

            e.AddHandlerToClient(mockServer);
            mockServers.Add(mockServer);
        }
        public void OnClientCreated(ClientCreatedArgs args)
        {
            var client = args.ODataClient;

            client.SaveChangesDefaultOptions = SaveChangesOptions.BatchWithSingleChangeset;
            client.EntityParameterSendOption = EntityParameterSendOption.SendOnlySetProperties;
            client.Configurations.RequestPipeline.OnEntryStarting((arg) =>
            {
                // do not send reference properties and null values to Dynamics
                arg.Entry.Properties = arg.Entry.Properties.Where((prop) => !prop.Name.StartsWith('_') && prop.Value != null);
            });
            client.BuildingRequest += Client_BuildingRequest;
        }
        public void OnClientCreated(ClientCreatedArgs args)
        {
            var client = args.ODataClient;

            Console.WriteLine($"MaxProtocolVersion = {client.MaxProtocolVersion}");

            // set header and serialization type
            client.SendingRequest2 += (s, e) =>
            {
                client.Format.UseJson();
                e.RequestMessage.SetHeader("api-version", args.ODataClient.Configurations.Properties["api-version"] as string);
            };

            this.counter.ODataInvokeCount++;
        }
        public TClient CreateClientFromEndpoint <TClient>(Uri endpoint, bool registerProviders) where TClient : ServiceClient <TClient>
        {
            var credential = CreateCredentials();

            if (!TestMockSupport.RunningMocked)
            {
                if (registerProviders)
                {
                    RegisterRequiredResourceProviders <TClient>(credential);
                }
            }

            var constructor = typeof(TClient).GetConstructor(new[] { typeof(SubscriptionCloudCredentials), typeof(Uri) });

            if (constructor == null)
            {
                throw new InvalidOperationException(string.Format(Resources.InvalidManagementClientType, typeof(TClient).Name));
            }

            TClient client = (TClient)constructor.Invoke(new object[] { credential, endpoint });

            client.UserAgent.Add(ApiConstants.UserAgentValue);
            EventHandler <ClientCreatedArgs> clientCreatedHandler = OnClientCreated;

            if (clientCreatedHandler != null)
            {
                ClientCreatedArgs args = new ClientCreatedArgs {
                    CreatedClient = client, ClientType = typeof(TClient)
                };
                clientCreatedHandler(this, args);
                client = (TClient)args.CreatedClient;
            }

            if (addRestLogHandlerToAllClients)
            {
                // Add the logging handler
                var     withHandlerMethod = typeof(TClient).GetMethod("WithHandler", new[] { typeof(DelegatingHandler) });
                TClient finalClient       =
                    (TClient)withHandlerMethod.Invoke(client, new object[] { new HttpRestCallLogger() });
                client.Dispose();

                return(finalClient);
            }
            else
            {
                return(client);
            }
        }
 private void OnClientCreated(object sender, ClientCreatedArgs e)
 {
     e.AddHandlerToClient(HttpMockServer.CreateInstance());
     bool runningMocked = (HttpMockServer.Mode == HttpRecorderMode.Playback);
     TestMockSupport.RunningMocked = runningMocked;
     if (runningMocked)
     {
         PropertyInfo initTimeoutProp = e.ClientType.GetProperty("LongRunningOperationInitialTimeout");
         PropertyInfo retryTimeoutProp = e.ClientType.GetProperty("LongRunningOperationRetryTimeout");
         if (initTimeoutProp != null && retryTimeoutProp != null)
         {
             initTimeoutProp.SetValue(e.CreatedClient, 0, null);
             retryTimeoutProp.SetValue(e.CreatedClient, 0, null);
         }
     }
 }
예제 #6
0
        private void OnClientCreated(object sender, ClientCreatedArgs e)
        {
            e.AddHandlerToClient(HttpMockServer.CreateInstance());
            bool runningMocked = (HttpMockServer.Mode == HttpRecorderMode.Playback);

            TestMockSupport.RunningMocked = runningMocked;
            if (runningMocked)
            {
                PropertyInfo initTimeoutProp  = e.ClientType.GetProperty("LongRunningOperationInitialTimeout");
                PropertyInfo retryTimeoutProp = e.ClientType.GetProperty("LongRunningOperationRetryTimeout");
                if (initTimeoutProp != null && retryTimeoutProp != null)
                {
                    initTimeoutProp.SetValue(e.CreatedClient, 0, null);
                    retryTimeoutProp.SetValue(e.CreatedClient, 0, null);
                }
            }
        }
예제 #7
0
        public TClient CreateClient <TClient>(bool registerProviders, params object[] parameters) where TClient : ServiceClient <TClient>
        {
            List <Type> types = new List <Type>();

            foreach (object obj in parameters)
            {
                types.Add(obj.GetType());
            }

            var constructor = typeof(TClient).GetConstructor(types.ToArray());

            if (constructor == null)
            {
                throw new InvalidOperationException(string.Format(Resources.InvalidManagementClientType, typeof(TClient).Name));
            }

            TClient client = (TClient)constructor.Invoke(parameters);

            client.UserAgent.Add(ApiConstants.UserAgentValue);
            EventHandler <ClientCreatedArgs> clientCreatedHandler = OnClientCreated;

            if (clientCreatedHandler != null)
            {
                ClientCreatedArgs args = new ClientCreatedArgs {
                    CreatedClient = client, ClientType = typeof(TClient)
                };
                clientCreatedHandler(this, args);
                client = (TClient)args.CreatedClient;
            }

            if (addRestLogHandlerToAllClients)
            {
                // Add the logging handler
                var     withHandlerMethod = typeof(TClient).GetMethod("WithHandler", new[] { typeof(DelegatingHandler) });
                TClient finalClient       =
                    (TClient)withHandlerMethod.Invoke(client, new object[] { new HttpRestCallLogger() });
                client.Dispose();

                return(finalClient);
            }
            else
            {
                return(client);
            }
        }
 private void OnClientCreated(object sender, ClientCreatedArgs e)
 {
     e.AddHandlerToClient(HttpMockServer.CreateInstance());
     bool runningMocked = (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Playback);
     TestMockSupport.RunningMocked = runningMocked;
     if (runningMocked)
     {
         PropertyInfo initTimeoutProp = e.ClientType.GetProperty("LongRunningOperationInitialTimeout");
         PropertyInfo retryTimeoutProp = e.ClientType.GetProperty("LongRunningOperationRetryTimeout");
         if (initTimeoutProp != null && retryTimeoutProp != null)
         {
             initTimeoutProp.SetValue(e.CreatedClient, 0, null);
             retryTimeoutProp.SetValue(e.CreatedClient, 0, null);
         }
     }
     else
     {
         if (!HttpMockServer.Variables.ContainsKey(Variables.SubscriptionId))
         {
             HttpMockServer.Variables.Add(Variables.SubscriptionId, testSubscrption.SubscriptionId);                    
         }
     }
 }
        private void OnClientCreated(object sender, ClientCreatedArgs e)
        {
            e.AddHandlerToClient(HttpMockServer.CreateInstance());
            bool runningMocked = (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Playback);

            TestMockSupport.RunningMocked = runningMocked;
            if (runningMocked)
            {
                PropertyInfo initTimeoutProp  = e.ClientType.GetProperty("LongRunningOperationInitialTimeout");
                PropertyInfo retryTimeoutProp = e.ClientType.GetProperty("LongRunningOperationRetryTimeout");
                if (initTimeoutProp != null && retryTimeoutProp != null)
                {
                    initTimeoutProp.SetValue(e.CreatedClient, 0, null);
                    retryTimeoutProp.SetValue(e.CreatedClient, 0, null);
                }
            }
            else
            {
                if (!HttpMockServer.Variables.ContainsKey(Variables.SubscriptionId))
                {
                    HttpMockServer.Variables.Add(Variables.SubscriptionId, testSubscrption.SubscriptionId);
                }
            }
        }
 private void OnClientCreated(object sender, ClientCreatedArgs e)
 {
     e.AddHandlerToClient(HttpMockServer.CreateInstance());
 }
예제 #11
0
 private void OnClientCreated(object sender, ClientCreatedArgs e)
 {
     e.AddHandlerToClient(HttpMockServer.CreateInstance());
 }
 private void OnClientCreated(object sender, ClientCreatedArgs e)
 {
     HttpMockServer mockServer = new HttpMockServer(new SimpleRecordMatcher());
     e.AddHandlerToClient(mockServer);
     mockServers.Add(mockServer);
 }