public void UnregisterServiceOnDataContextChanged()
        {
            Button          control = new Button();
            TestVM          vm1     = TestVM.Create();
            TestVM          vm2     = TestVM.Create();
            TestServiceBase service = new TestServiceBase();

            Interaction.GetBehaviors(control).Add(service);
            control.DataContext = vm1;
            Assert.AreEqual(service, vm1.GetService <ITestService>());
            control.DataContext = vm2;
            Assert.AreEqual(null, vm1.GetService <ITestService>());
            Assert.AreEqual(service, vm2.GetService <ITestService>());
        }
Ejemplo n.º 2
0
        public void GetNonWebExceptionsAreWrappedIfThrown()
        {
            // arrange
            var apiUri = ApiRequestHandler.ApiRequestUri;

            var factory = new TestWebRequestFactory();
            var service = new TestServiceBase(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), factory, null);

            factory.RegisterExceptionForUri <InvalidOperationException>(apiUri.AbsoluteUri);

            // act
            var ex = Assert.Throws <ApiOperationException>(() => service.Get(apiUri));

            // assert
            Assert.IsInstanceOf <InvalidOperationException>(ex.InnerException);
        }
        public void UnregisterServiceOnUnloaded()
        {
            Button          control = new Button();
            TestVM          vm1     = TestVM.Create();
            TestServiceBase service = new TestServiceBase()
            {
                UnregisterOnUnloaded = true
            };

            Interaction.GetBehaviors(control).Add(service);
            control.DataContext = vm1;
            Assert.AreEqual(service, vm1.GetService <ITestService>());
            Window.Content = control;
            Window.Show();
            Assert.AreEqual(service, vm1.GetService <ITestService>());
            Window.Content = null;
            DispatcherHelper.DoEvents();
            Assert.AreEqual(null, vm1.GetService <ITestService>());
        }
        public void T250427()
        {
            Grid            mainV       = new Grid();
            TestVM          mainVM      = TestVM.Create();
            TestServiceBase mainService = new TestServiceBase();

            Interaction.GetBehaviors(mainV).Add(mainService);
            mainV.DataContext = mainVM;

            Grid            childV       = new Grid();
            TestVM          childVM      = TestVM.Create();
            TestServiceBase childService = new TestServiceBase();

            Interaction.GetBehaviors(childV).Add(childService);
            mainV.Children.Add(childV);

            Assert.AreEqual(childService, mainVM.GetService <ITestService>());
            childV.DataContext = childVM;
            Assert.AreEqual(mainService, mainVM.GetService <ITestService>());
            Assert.AreEqual(childService, childVM.GetService <ITestService>());
        }
        public void ServiceBaseGenerates_WebRequestEntities_From_SharedWebRequestFactory()
        {
            // arrange
            var uri     = new Uri("http://www.google.com");
            var factory = new TestWebRequestFactoryEx();
            var user    = new UserContract {
                Name = "Freddie"
            };

            factory.RegisterResultForUri(uri.ToString(), user.ToJson()); // if our hook is working then we should get contracts from google and not a search page

            WebRequestFactory.SetSharedWebRequestFactory(factory);

            // act
            var service = new TestServiceBase(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), null, null);

            // assert
            var contract = service.Get(uri);

            Assert.AreNotSame(user, contract);
            Assert.AreEqual(user.Name, contract.Name);
        }
        public void GetNonWebExceptionsAreWrappedIfThrown()
        {
            // arrange
            var apiUri = ApiRequestHandler.ApiRequestUri;

            var factory = new TestWebRequestFactory();
            var service = new TestServiceBase(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), factory, null);
            factory.RegisterExceptionForUri<InvalidOperationException>(apiUri.AbsoluteUri);

            // act
            var ex = Assert.Throws<ApiOperationException>(() => service.Get(apiUri));

            // assert
            Assert.IsInstanceOf<InvalidOperationException>(ex.InnerException);
        }
        public void OperationCorrectlyHandlesWebExceptionErrors([ValueSource("_operations")] Tuple<Action<TestServiceBase, Uri>, string, bool> operation)
        {
            if (operation.Item3 == false)
            {
                Assert.Inconclusive("Not applicable");
            };

            // arrange
            var apiUri = ApiRequestHandler.ApiRequestUri;

            var keyService = new SimpleOAuthKeyService()
            {
                OAuthResponse = new OAuthTokens() { AccessToken = "<<accesstoken>>", RefreshToken = "<<refreshtoken>>", ExpiresIn = 10 }
            };
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri(OAuthRequestHandler.OAuthRequestUri.AbsoluteUri, new OAuthTokens() { AccessToken = "<<newaccesstoken>>" }.ToJson());
            factory.RegisterExceptionForUri<WebException>(apiUri.AbsoluteUri);

            var service = new TestServiceBase(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), factory, keyService);

            // act
            var ex = Assert.Throws<ApiCommunicationException>(() => operation.Item1(service, apiUri));

            // assert
            Assert.AreEqual(apiUri, ex.URI);
        }
        public void OperationUpdatesKeyServiceWithNewTokensWhenCurrentTokensHaveExpired([ValueSource("_operations")] Tuple<Action<TestServiceBase, Uri>, string, bool> operation)
        {
            // arrange
            var apiUri = ApiRequestHandler.ApiRequestUri;

            var keyService = new SimpleOAuthKeyService()
            {
                OAuthResponse = new OAuthTokens() { AccessToken = "<<accesstoken>>", RefreshToken = "<<refreshtoken>>", ExpiresIn = 10 }
            };
            var factory = new TestWebRequestFactory();
            factory.RegisterResultForUri(OAuthRequestHandler.OAuthRequestUri.AbsoluteUri, new OAuthTokens() { AccessToken = "<<newaccesstoken>>" }.ToJson());
            factory.RegisterResultForUri(apiUri.AbsoluteUri, operation.Item2);

            var service = new TestServiceBase(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "<<redirecturl>>"), factory, keyService);

            // act
            operation.Item1(service, apiUri);

            // assert
            Assert.AreEqual("<<newaccesstoken>>", keyService.OAuthResponse.AccessToken);
        }
Ejemplo n.º 9
0
 public static void BindService(grpc::ServiceBinderBase serviceBinder, TestServiceBase serviceImpl)
 {
     serviceBinder.AddMethod(__Method_DoSimple, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Google.Api.Gax.Grpc.IntegrationTests.SimpleRequest, global::Google.Api.Gax.Grpc.IntegrationTests.SimpleResponse>(serviceImpl.DoSimple));
     serviceBinder.AddMethod(__Method_EchoHeaders, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Google.Api.Gax.Grpc.IntegrationTests.EchoHeadersRequest, global::Google.Api.Gax.Grpc.IntegrationTests.EchoHeadersResponse>(serviceImpl.EchoHeaders));
 }
Ejemplo n.º 10
0
 public static grpc::ServerServiceDefinition BindService(TestServiceBase serviceImpl)
 {
     return(grpc::ServerServiceDefinition.CreateBuilder()
            .AddMethod(__Method_DoSimple, serviceImpl.DoSimple)
            .AddMethod(__Method_EchoHeaders, serviceImpl.EchoHeaders).Build());
 }
Ejemplo n.º 11
0
 /// <summary>Creates service definition that can be registered with a server</summary>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static grpc::ServerServiceDefinition BindService(TestServiceBase serviceImpl)
 {
     return(grpc::ServerServiceDefinition.CreateBuilder()
            .AddMethod(__Method_GetTime, serviceImpl.GetTime)
            .AddMethod(__Method_SaySomething, serviceImpl.SaySomething).Build());
 }
 /// <summary>Register service method with a service binder with or without implementation. Useful when customizing the  service binding logic.
 /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
 /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static void BindService(grpc::ServiceBinderBase serviceBinder, TestServiceBase serviceImpl)
 {
 }
 /// <summary>Creates service definition that can be registered with a server</summary>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static grpc::ServerServiceDefinition BindService(TestServiceBase serviceImpl)
 {
     return(grpc::ServerServiceDefinition.CreateBuilder().Build());
 }
Ejemplo n.º 14
0
 /// <summary>Creates service definition that can be registered with a server</summary>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static ServerServiceDefinition BindService(TestServiceBase serviceImpl)
 {
     return(ServerServiceDefinition.CreateBuilder()
            .AddMethod(__Method_DoSimple, serviceImpl.DoSimple).Build());
 }
Ejemplo n.º 15
0
 /// <summary>Creates service definition that can be registered with a server</summary>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static grpc::ServerServiceDefinition BindService(TestServiceBase serviceImpl)
 {
     return(grpc::ServerServiceDefinition.CreateBuilder()
            .AddMethod(__Method_GetMessages, serviceImpl.GetMessages).Build());
 }