public void Does_handle_Exceptions()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

            try
            {
                var response = encryptedClient.Send(new HelloSecure());
                Assert.Fail("Should throw");
            }
            catch (WebServiceException ex)
            {
                Assert.That(ex.ResponseStatus.ErrorCode, Is.EqualTo(typeof(ArgumentNullException).Name));
                Assert.That(ex.ResponseStatus.Message, Is.EqualTo($"Value cannot be null.{Environment.NewLine}Parameter name: Name"));
            }

            try
            {
                var response = encryptedClient.Send(new HelloAuthenticated());
                Assert.Fail("Should throw");
            }
            catch (WebServiceException ex)
            {
                Assert.That(ex.StatusCode, Is.EqualTo((int)HttpStatusCode.Unauthorized));
                Assert.That(ex.StatusDescription, Is.EqualTo("Unauthorized"));
            }
        }
        public void Can_authenticate_and_call_authenticated_Service()
        {
            try
            {
                var client = CreateClient();
                IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

                var authResponse = encryptedClient.Send(new Authenticate
                {
                    provider = CredentialsAuthProvider.Name,
                    UserName = "******",
                    Password = "******",
                });

                var encryptedClientCookies = client.GetCookieValues();
                Assert.That(encryptedClientCookies.Count, Is.EqualTo(0));

                var response = encryptedClient.Send(new HelloAuthenticated
                {
                    SessionId = authResponse.SessionId,
                });

                Assert.That(response.IsAuthenticated);
                Assert.That(response.Email, Is.EqualTo("*****@*****.**"));
                Assert.That(response.SessionId, Is.EqualTo(authResponse.SessionId));

                encryptedClientCookies = client.GetCookieValues();
                Assert.That(encryptedClientCookies.Count, Is.EqualTo(0));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Does_populate_Request_metadata()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

            var authResponse = encryptedClient.Send(new Authenticate
            {
                provider = CredentialsAuthProvider.Name,
                UserName = "******",
                Password = "******",
            });

            var encryptedClientCookies = client.GetCookieValues();

            Assert.That(encryptedClientCookies.Count, Is.EqualTo(0));

            encryptedClient.Version   = 1;
            encryptedClient.SessionId = authResponse.SessionId;

            var response = encryptedClient.Send(new HelloAuthenticated());

            Assert.That(response.SessionId, Is.EqualTo(encryptedClient.SessionId));
            Assert.That(response.Version, Is.EqualTo(encryptedClient.Version));

            encryptedClientCookies = client.GetCookieValues();
            Assert.That(encryptedClientCookies.Count, Is.EqualTo(0));

            client.SessionId = authResponse.SessionId;
            client.Version   = 2;

            response = client.Send(new HelloAuthenticated());
            Assert.That(response.SessionId, Is.EqualTo(client.SessionId));
            Assert.That(response.Version, Is.EqualTo(client.Version));
        }
        public void Does_handle_Exceptions()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

            try
            {
                var response = encryptedClient.Send(new HelloSecure());
                Assert.Fail("Should throw");
            }
            catch (WebServiceException ex)
            {
                Assert.That(ex.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest));
                Assert.That(ex.StatusDescription, Is.EqualTo("ArgumentNullException"));
            }

            try
            {
                var response = encryptedClient.Send(new HelloAuthenticated());
                Assert.Fail("Should throw");
            }
            catch (WebServiceException ex)
            {
                Assert.That(ex.StatusCode, Is.EqualTo((int)HttpStatusCode.Unauthorized));
                Assert.That(ex.StatusDescription, Is.EqualTo("Unauthorized"));
            }
        }
        public void Can_Authenticate_with_JWT_then_call_AuthOnly_Services_with_ServiceClients()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

            encryptedClient.BearerToken = JwtBearerToken;

            var response = encryptedClient.Get(new HelloAuthenticated());
        }
    public void Can_Send_Encrypted_EmptyRequest_with_ServiceClients()
    {
        var client = CreateClient();
        IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get(new GetPublicKey()));

        var response = encryptedClient.Delete(new EncryptedDelete());

        Assert.That(response, Is.Not.Null);
    }
        public void Can_Send_Encrypted_OneWay_Message_with_ServiceClients()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get(new GetPublicKey()));

            encryptedClient.Send(new HelloOneWay {
                Name = "World"
            });
        }
        public void Can_call_GET_only_Services()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

            var response = encryptedClient.Get(new GetSecure {
                Name = "World"
            });

            Assert.That(response.Result, Is.EqualTo("Hello, World!"));
        }
        public void Can_Send_Encrypted_OneWay_Message_with_ServiceClients()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get(new GetPublicKey()));

            encryptedClient.Send(new HelloOneWay {
                Name = "World"
            });

            Assert.That(HelloOneWay.LastName, Is.EqualTo("World"));
        }
        public void Can_Send_Encrypted_Message_with_ServiceClients()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get(new GetPublicKey()));

            var response = encryptedClient.Send(new HelloSecure {
                Name = "World"
            });

            Assert.That(response.Result, Is.EqualTo("Hello, World!"));
        }
        public void Can_send_PublishAll_requests()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

            var names    = new[] { "Foo", "Bar", "Baz" };
            var requests = names.Map(x => new HelloSecure {
                Name = x
            });

            encryptedClient.PublishAll(requests);
        }
        public void Can_send_auto_batched_requests()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

            var names    = new[] { "Foo", "Bar", "Baz" };
            var requests = names.Map(x => new HelloSecure {
                Name = x
            });

            var responses     = encryptedClient.SendAll(requests);
            var responseNames = responses.Map(x => x.Result);

            Assert.That(responseNames, Is.EqualTo(names.Map(x => "Hello, {0}!".Fmt(x))));
        }
        public void Can_send_large_messages()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

            var request = new LargeMessage
            {
                Messages = 100.Times(i => new HelloSecure {
                    Name = "Name" + i
                })
            };

            var response = encryptedClient.Send(request);

            Assert.That(response.Messages.Count, Is.EqualTo(request.Messages.Count));
        }
        public void Can_Authenticate_then_call_AuthOnly_Services_with_ServiceClients_Temp()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

            var authResponse = encryptedClient.Send(new Authenticate
            {
                provider = CredentialsAuthProvider.Name,
                UserName = "******",
                Password = "******",
            });

            client.SetCookie("ss-id", authResponse.SessionId);
            var response = client.Get(new HelloAuthSecure {
                Name = "World"
            });
        }
        public void Can_Authenticate_then_call_AuthOnly_Services_with_ServiceClients_Perm()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

            var authResponse = encryptedClient.Send(new Authenticate
            {
                provider   = "credentials",
                UserName   = "******",
                Password   = "******",
                RememberMe = true,
            });

            client.SetCookie("ss-pid", authResponse.SessionId);
            client.SetCookie("ss-opt", "perm");
            var response = client.Get(new HelloAuthSecure {
                Name = "World"
            });
        }
        public void Can_send_large_messages()
        {
            var client = CreateClient();
            IEncryptedClient encryptedClient = client.GetEncryptedClient(client.Get <string>("/publickey"));

            var messages = new List <HelloSecure>();

            for (var i = 0; i < 100; i++)
            {
                messages.Add(new HelloSecure {
                    Name = "Name" + i
                });
            }

            var request = new LargeMessage
            {
                Messages = messages
            };

            var response = encryptedClient.Send(request);

            Assert.That(response.Messages.Count, Is.EqualTo(request.Messages.Count));
        }
Beispiel #17
0
 public static TResponse Put <TResponse>(this IEncryptedClient client, IReturn <TResponse> request)
 {
     return(client.Send(HttpMethods.Put, request));
 }
Beispiel #18
0
 public static void Send(this IEncryptedClient client, IReturnVoid request)
 {
     client.Publish(request);
 }