Esempio n. 1
0
        public async Task Should_post_a_valid_Registration_message()
        {
            // Arrange
            var http = new FakeHttpMessageHandler("http://baseaddress/");
            var directory = new Directory() { NewRegistration = new Uri("http://baseaddress/registration")};
            var registration = new RegistrationResponse();

            var client = 
                http.RequestTo("directory").Returns(directory).WithNonce("nonce").
                RequestTo("registration").Returns(registration).WithNonce("nonce").
                GetHttpClient();
            
            var sut = new AcmeClient(client, new RSACryptoServiceProvider());

            // Act
            var registrationResponse =  await sut.RegisterAsync("agreementUri", new []{ "mailto:[email protected]"});

            // Assert
            registrationResponse.Should().NotBeNull();
            http.ReceivedRequestsTo("directory").Single().HasMethod(HttpMethod.Get);
            http.ReceivedRequestsTo("registration").Single().HasMethod(HttpMethod.Post).HasJwsPayload<NewRegistrationRequest>(r =>
            {
                r.Agreement.Should().Be("agreementUri");               
                r.Contact.Should().Contain("mailto:[email protected]");
            });
        }
Esempio n. 2
0
        public async Task Should_POST_to_get_registration_details_if_the_registration_already_exists()
        {
            // Arrange
            var http = new FakeHttpMessageHandler("http://baseaddress/");
            var directory = new Directory() { NewRegistration = new Uri("http://baseaddress/registration") };
            var registration = new RegistrationResponse();

            var client =
                http.RequestTo("directory").Returns(directory).WithNonce("nonce").
                RequestTo("registration").Returns(new Problem(), "application/problem+json").HasStatusCode(HttpStatusCode.Conflict).WithHeader("Location", "http://baseaddress/existingreguri").WithNonce("nonce").
                RequestTo("existingreguri").Returns(registration).WithNonce("nonce").
                GetHttpClient();

            var sut = new AcmeClient(client, new RSACryptoServiceProvider());

            // Act
            var registrationResponse = await sut.RegisterAsync("agreementUri", new[] { "mailto:[email protected]" });

            // Assert
            registrationResponse.Should().NotBeNull();
            http.ReceivedRequestsTo("directory").Single().HasMethod(HttpMethod.Get);
            http.ReceivedRequestsTo("registration").Single().HasMethod(HttpMethod.Post).HasJwsPayload<NewRegistrationRequest>(r =>
            {
                r.Agreement.Should().Be("agreementUri");
                r.Contact.Should().Contain("mailto:[email protected]");
            });
            http.ReceivedRequestsTo("existingreguri").Single().HasMethod(HttpMethod.Post).HasJwsPayload<UpdateRegistrationRequest>(r =>
            {
                r.Agreement.Should().BeNull();
                r.Contact.Should().BeNull();
            });
        }