public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Cluster.CreateResponse(Fixtures.EtcdUrl.ToUri()));

                var member = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                                       .Cluster
                                       .CreateMember()
                                       .WithPeerUri(Fixtures.EtcdUrl.ToUri());

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                                .AppendPathSegment(Constants.Etcd.Path_Members)
                    )
                    .WithVerb(HttpMethod.Post)
                    .WithContentType(Constants.Http.ContentType_ApplicationJson)
                    .Times(1);

                member.Should().NotBeNull();

                member.PeerUrls.Should()
                      .NotBeEmpty()
                      .And
                      .ContainSingle(x => Fixtures.EtcdUrl.ToUri().Equals(x));
            }
        }
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(
                    Fixtures.Cluster.ClusterMembersResponse(
                        Fixtures.Cluster.ClusterMemberResponse(),
                        Fixtures.Cluster.ClusterMemberResponse(),
                        Fixtures.Cluster.ClusterMemberResponse(),
                        Fixtures.Cluster.ClusterMemberResponse(),
                        Fixtures.Cluster.ClusterMemberResponse()
                        ));

                var members = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                                        .Cluster
                                        .GetMembers();

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                                .AppendPathSegment(Constants.Etcd.Path_Members)
                    )
                    .WithVerb(HttpMethod.Get)
                    .Times(1);

                members.Should().NotBeNull()
                       .And
                       .HaveCount(5);
            }
        }
Exemple #3
0
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Cluster.ClusterMemberResponse(new[] {Fixtures.EtcdUrl.ToUri()}, new[] {Fixtures.EtcdUrl.ToUri()}));

                var leader = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                                       .Cluster
                                       .GetLeader();

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                                .AppendPathSegment(Constants.Etcd.Path_Members_Leader)
                    )
                    .WithVerb(HttpMethod.Get)
                    .Times(1);

                leader.Should().NotBeNull();

                leader.PeerUrls.Should()
                      .NotBeEmpty()
                      .And
                      .ContainSingle(x => Fixtures.EtcdUrl.ToUri().Equals(x));

                leader.ClientUrls.Should()
                      .NotBeEmpty()
                      .And
                      .ContainSingle(x => Fixtures.EtcdUrl.ToUri().Equals(x));
            }
        }
        public async Task ExpectedValue_ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.CompareAndSwap.DefaultResponse)
                    .RespondWithJson(Fixtures.CompareAndSwap.DefaultResponse);

                var req = Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                    .Atomic.CompareAndSwap(Fixtures.CompareAndSwap.Path)
                    .WithExpectedValue(Fixtures.CompareAndSwap.ExpectedValue)
                    .WithNewValue(Fixtures.CompareAndSwap.NewValue);

                await req;
                await req.Execute();

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                            .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.CompareAndSwap.Path)
                            .SetQueryParam(Constants.Etcd.Parameter_PrevValue, Fixtures.CompareAndSwap.ExpectedValue)
                    )
                    .WithVerb(HttpMethod.Put)
                    .WithRequestBody(Fixtures.CompareAndSwap.DefaultRequest())
                    .Times(2);
            }
        }
		public void when_GetTransaction_is_called_and_not_found_then_we_should_get_a_NotFoundException()
		{
			using (HttpTest httpTest = new HttpTest())
			{
				httpTest.RespondWithJson(404, new { message = "Not Found" });

				var signhostApiClient = new SignHostApiClient(settings);

				Func<Task> getTransaction = () => signhostApiClient.GetTransaction("transaction Id");
				getTransaction.ShouldThrow<ErrorHandling.NotFoundException>();
			}
		}
        public void GetService()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(new Service{Id = "service-id"});

                var service = _cdnService.GetService("service-id");

                Assert.NotNull(service);
                Assert.Equal("service-id", service.Id);
            }
        }
		public void when_GetTransaction_is_called_and_the_authorization_is_bad_then_we_should_get_a_BadAuthorizationException()
		{
			using (HttpTest httpTest = new HttpTest()) {

				httpTest.RespondWithJson(401, new { message = "unauthorized" });

				var signhostApiClient = new SignHostApiClient(settings);

				Func<Task> getTransaction = () => signhostApiClient.GetTransaction("transaction Id");
				getTransaction.ShouldThrow<UnauthorizedAccessException>();
			}
		}
        public void ListFlavors()
        {
            using (var httpTest = new HttpTest())
            {
                var cdnService = new ContentDeliveryNetworkService(Stubs.AuthenticationProvider, DefaultRegion);
                httpTest.RespondWithJson(new FlavorCollection(new[] {new Flavor()}));

                var flavors = cdnService.ListFlavors();

                Assert.NotNull(flavors);
                Assert.Equal(1, flavors.Count());
            }
        }
        public void GetFlavor()
        {
            using (var httpTest = new HttpTest())
            {
                var cdnService = new ContentDeliveryNetworkService(Stubs.AuthenticationProvider, DefaultRegion);
                httpTest.RespondWithJson(new Flavor {Id = "flavor-id"});

                var flavor = cdnService.GetFlavor("flavor-id");

                Assert.NotNull(flavor);
                Assert.Equal("flavor-id", flavor.Id);
            }
        }
		public void when_GetTransaction_is_called_and_unkownerror_like_418_occures_then_we_should_get_a_SignhostException()
		{
			using (HttpTest httpTest = new HttpTest())
			{
				httpTest.RespondWithJson(418, new { message = "418 I'm a teapot" });

				var signhostApiClient = new SignHostApiClient(settings);

				Func<Task> getTransaction = () => signhostApiClient.GetTransaction("transaction Id");
				getTransaction.ShouldThrow<ErrorHandling.SignhostRestApiClientException>()
					.WithMessage("*418*");
			}
		}
        public void FindServiceOnAPage()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(new ServiceCollection(new[] {new Service()})
                {
                    Links = new[] {new Link("next", "http://api.com/next")}
                });
                httpTest.RespondWithJson(new ServiceCollection(new[] {new Service {Name = "MyService"}}));

                var currentPage = _cdnService.ListServices();
                Service myService;
                do
                {
                    myService = currentPage.FirstOrDefault(x => x.Name == "MyService");
                    if (myService != null)
                        break;

                    currentPage = currentPage.GetNextPage();
                } while (currentPage.Any());

                Assert.NotNull(myService);
            }
        }
Exemple #12
0
        public async Task Get_ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Key.DefaultResponse);

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                    .GetKey(Fixtures.Key.Path);

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                            .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path)
                    )
                    .WithVerb(HttpMethod.Get)
                    .Times(1);
            }
        }
        public void ShouldThrowExistingPeerAddressExceptionOnDuplicatePeerAddress()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(HttpStatusCode.Conflict, Fixtures.CreateErrorMessage(Constants.Etcd.ErrorCode_ExistingPeerAddress));

                Func<Task> action = async () =>
                {
                    await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                              .Cluster
                              .CreateMember()
                              .WithPeerUri(Fixtures.EtcdUrl.ToUri());
                };

                action.ShouldThrowExactly<ExistingPeerAddressException>()
                      .And
                      .IsExistingPeerAddress.Should().BeTrue();
            }
        }
Exemple #14
0
        public async Task Get_ShouldCallTheCorrectUrlWithQuorumTrueOption()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Key.DefaultResponse);

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                    .GetKey(Fixtures.Key.Path)
                    .WithQuorum();

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                            .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path)
                            .SetQueryParam(Constants.Etcd.Parameter_Quorum, Constants.Etcd.Parameter_True)
                    )
                    .WithVerb(HttpMethod.Get)
                    .Times(1);
            }
        }
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(
                    Fixtures.Cluster.ClusterMemberResponse(
                        peerUris : new[]
                        {
                            Fixtures.EtcdUrl.ToUri(),
                            Fixtures.EtcdUrl.ToUri()
                        }));

                var memberId = StaticRandom.Instance.Next().ToString();

                var member = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                                       .Cluster
                                       .UpdateMemberPeerUrls()
                                       .WithMemberId(memberId)
                                       .WithPeerUri(Fixtures.EtcdUrl.ToUri(), Fixtures.EtcdUrl.ToUri());

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                                .AppendPathSegment(Constants.Etcd.Path_Members)
                                .AppendPathSegment(memberId)
                    )
                    .WithVerb(HttpMethod.Put)
                    .WithContentType(Constants.Http.ContentType_ApplicationJson)
                    .Times(1);

                member.Should().NotBeNull();
                member.PeerUrls
                      .Should()
                      .HaveCount(2)
                      .And
                      .ContainInOrder(
                          Fixtures.EtcdUrl.ToUri(),
                          Fixtures.EtcdUrl.ToUri()
                    );
            }
        }
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Queue.DefaultResponse);

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                    .Atomic
                    .Enqueue(Fixtures.Queue.Path)
                    .WithValue(Fixtures.Queue.DefaultValue);

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                            .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Queue.Path)
                    )
                    .WithVerb(HttpMethod.Post)
                    .WithRequestBody(Fixtures.Queue.DefaultRequest())
                    .Times(1);
            }
        }
Exemple #17
0
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            var expected = true;
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Cluster.ClusterHealthResponse(expected));

                var healthResult = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                    .Cluster
                    .GetHealth();

                http.Should()
                    .HaveCalled(Fixtures.EtcdUrl.AppendPathSegment(Constants.Etcd.Path_Health))
                    .WithVerb(HttpMethod.Get)
                    .Times(1);

                healthResult.Should().NotBeNull();

                healthResult.Value.Should()
                    .Be(expected);
            }
        }
        public async Task Get_ShouldUseConfiguredValueConverter()
        {
            var dto = Fixtures.Dto.SimpleDataContract();
            var converter = new XmlValueConverter();
            var expected = converter.Write(dto);

            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Key.UpsertResponse(Fixtures.Key.Path, expected));

                var client = Etcd.ClientFor(Fixtures.EtcdUrl.ToUri());
                client.Configure(x => x.ValueConverter = converter);

                var response = await client
                    .GetKey(Fixtures.Key.Path);

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                            .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path)
                    )
                    .WithVerb(HttpMethod.Get)
                    .Times(1);

                response.Should().NotBeNull();
                response.Data.Should().NotBeNull();
                response.Data.RawValue.Should().NotBeNullOrWhiteSpace();
                response.Data.RawValue.Should().Be(expected);

                SimpleDataContractDto responseDto = null;
                Action getValue = () => responseDto = response.Data.GetValue<SimpleDataContractDto>();
                getValue.ShouldNotThrow();

                responseDto.Should().NotBeNull();

                responseDto.Id.Should().Be(dto.Id);
                responseDto.Name.Should().Be(dto.Name);
            }
        }
Exemple #19
0
        public async Task ShouldCallTheCorrectUrlWithTtlOptionUsingTimeSpan()
        {
            var expectedTtlValue = TimeSpan.FromMinutes(3) + TimeSpan.FromSeconds(16);
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Queue.DefaultResponse);

                var result = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                    .Atomic
                    .Enqueue(Fixtures.Queue.Path)
                    .WithValue(Fixtures.Queue.DefaultValue)
                    .WithTimeToLive(expectedTtlValue);

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                            .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Queue.Path)
                    )
                    .WithVerb(HttpMethod.Post)
                    .WithRequestBody(Fixtures.Key.TtlTimeSpanRequest(Fixtures.Queue.DefaultValue, expectedTtlValue))
                    .Times(1);
            }
        }
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Cluster.CreateResponse(Fixtures.EtcdUrl.ToUri()));

                var memberId = StaticRandom.Instance.Next();

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                          .Cluster
                          .DeleteMember()
                          .WithMemberId(memberId.ToString());

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                                .AppendPathSegment(Constants.Etcd.Path_Members)
                                .AppendPathSegment(memberId.ToString())
                    )
                    .WithVerb(HttpMethod.Delete)
                    .Times(1);
            }
        }
		public void when_CreateTransaction_is_called_with_invalid_email_then_we_should_get_a_BadRequestException()
		{
			using (HttpTest httpTest = new HttpTest())
			{
				httpTest.RespondWithJson(400, new { message = "Bad Request" });

				var signhostApiClient = new SignHostApiClient(settings);

				Signer testSigner = new Signer();
				testSigner.Email = "firstname.lastnamegmail.com";

				Transaction testTransaction = new Transaction();
				testTransaction.Signers.Add(testSigner);

				Func<Task> getTransaction = () => signhostApiClient.CreateTransaction(testTransaction);
				getTransaction.ShouldThrow<ErrorHandling.BadRequestException>();

				httpTest.ShouldHaveCalled($"{settings.Endpoint}transaction")
					.WithVerb(HttpMethod.Post)
					.WithContentType("application/json")
					.Times(1);
			}
		}
		public void when_a_function_is_called_with_a_wrong_endpoint_we_should_get_a_SignhostRestApiClientException()
		{
			using (HttpTest httpTest = new HttpTest())
			{
				httpTest.RespondWithJson(502, new { message = "Bad Gateway" });

				var signhostApiClient = new SignHostApiClient(settings);

				Func<Task> getTransaction = () => signhostApiClient.GetTransaction("transaction Id");
				getTransaction.ShouldThrow<ErrorHandling.SignhostRestApiClientException>();
			}
		}
        public void WaitForServiceDeleted_ThrowsAnException_WhenTheOperationFailed()
        {
            using (var httpTest = new HttpTest())
            {
                var failedServiceDeployment = new Service
                {
                    Status = ServiceStatus.Failed,
                    Errors = new[] { new ServiceError { Message = "Random error." } }
                };
                httpTest.RespondWithJson(failedServiceDeployment);

                var ex = Assert.Throws<ServiceOperationFailedException>(() => _cdnService.WaitForServiceDeleted("failed-service-id"));
                Assert.NotEmpty(ex.Errors);
            }
        }
        public async void WaitForServiceDeleted_StopsWhenTimeoutIsReached()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(new Service { Status = ServiceStatus.CreateInProgress });

                await Assert.ThrowsAsync<TimeoutException>(() => _cdnService.WaitForServiceDeletedAsync("service-id", TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(1)));
            }
        }
        public void WaitForServiceDeleted_StopsWhenUserTokenIsCancelled()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(new Service { Status = ServiceStatus.DeleteInProgress });

                var timedToken = new CancellationTokenSource(TimeSpan.FromSeconds(1));

                Assert.ThrowsAsync<TaskCanceledException>(() => _cdnService.WaitForServiceDeletedAsync("service-id", Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan, null, timedToken.Token));
            }
        }
        public void WaitForServiceDeleted()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(new Service { Status = ServiceStatus.DeleteInProgress });
                httpTest.RespondWith((int)HttpStatusCode.NotFound, "All gone!");

                _cdnService.WaitForServiceDeleted("service-id", TimeSpan.FromMilliseconds(1));
            }
        }
        public void WaitForServiceDeployed()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(new Service { Status = ServiceStatus.CreateInProgress });
                httpTest.RespondWithJson(new Service { Status = ServiceStatus.UpdateInProgress });
                httpTest.RespondWithJson(new Service { Status = ServiceStatus.Deployed });

                var service = _cdnService.WaitForServiceDeployed("service-id", TimeSpan.FromMilliseconds(1));
                Assert.NotNull(service);
            }
        }
		public void when_GetTransaction_is_called_and_there_is_an_InternalServerError_then_we_should_get_a_InternalServerErrorException()
		{
			using (HttpTest httpTest = new HttpTest())
			{

				httpTest.RespondWithJson(500, new { message = "Internal Server Error" });

				var signhostApiClient = new SignHostApiClient(settings);

				Func<Task> getTransaction = () => signhostApiClient.GetTransaction("transaction Id");
				getTransaction.ShouldThrow<ErrorHandling.InternalServerErrorException>();
			}
		}
        public void Watch_ShouldStopPollingWhenSubscriptionIsDisposed()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Watch.DefaultResponse)
                    .RespondWithJson(Fixtures.Watch.DefaultResponse)
                    .RespondWithJson(Fixtures.Watch.DefaultResponse)
                    .RespondWithJson(Fixtures.Watch.DefaultResponse)
                    .RespondWithJson(Fixtures.Watch.DefaultResponse);

                Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                    .Watch(Fixtures.Watch.Path)
                    .SubscribeFor(3)
                    .Wait();

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                            .AppendPathSegment(Constants.Etcd.Path_Keys)
                            .AppendPathSegment(Fixtures.Watch.Path)
                            .SetQueryParam(Constants.Etcd.Parameter_Wait, Constants.Etcd.Parameter_True)
                    )
                    .WithVerb(HttpMethod.Get);

                http.CallLog.Should()
                    .HaveCount(3);
            }
        }
Exemple #30
0
        public async Task Upsert_ShouldCallTheCorrectUrlWithTtlOption()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Key.DefaultResponse);

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                    .UpsertKey(Fixtures.Key.Path)
                    .WithValue(Fixtures.Key.DefaultValue)
                    .WithTimeToLive(Fixtures.Key.DefaultTtl);

                http.Should()
                    .HaveCalled(
                        Fixtures.EtcdUrl
                            .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path)
                    )
                    .WithVerb(HttpMethod.Put)
                    .WithRequestBody(Fixtures.Key.TtlRequest())
                    .Times(1);
            }
        }