protected void SetupResponse(HttpResponseMessage response)
        {
            var sender = new FakeHttpRequestSender();

            sender.SetupResponse(response);
            this.Actor = ActorFactory.CreateSomeActorWithApiCallAbility(sender);
        }
Exemple #2
0
        public void should_send_request_as_xml_with_content_type_header()
        {
            var actor = ActorFactory.CreateSomeActorWithApiCallAbility(Sender);

            actor.AttemptsTo(GetHttpInteractionWithXmlContent(ContentFactory.SomeContent()));

            Check.That(Sender.GetLastSentMessage().Content.Headers.ContentType.MediaType).IsEqualTo(MediaTypes.ApplicationXml);
        }
Exemple #3
0
        public void should_sent_correct_http_verb()
        {
            var actor = ActorFactory.CreateSomeActorWithApiCallAbility(Sender);

            actor.AttemptsTo(GetHttpInteraction(Urls.UsersApi));

            Check.That(Sender.GetLastSentMessage().Method).IsEqualTo(GetHttpMethod());
        }
Exemple #4
0
        public void should_send_request_with_custom_content()
        {
            var actor   = ActorFactory.CreateSomeActorWithApiCallAbility(Sender);
            var content = ContentFactory.AccessTokenRequest();

            actor.AttemptsTo(GetHttpInteractionWithCustomContent(content));

            Check.That(Sender.GetLastSentMessage().Content.ReadAsStringAsync().Result).IsEqualTo(content);
        }
Exemple #5
0
        public void should_send_request_content_headers()
        {
            var actor = ActorFactory.CreateSomeActorWithApiCallAbility(Sender);

            actor.AttemptsTo(GetHttpInteraction(Urls.UsersApi)
                             .WithHeader(HttpHeaders.ContentEncoding, ContentEncodings.GZip));

            Check.That(Sender.GetLastSentMessage().Content.Headers.ContentEncoding.First()).IsEqualTo(ContentEncodings.GZip);
        }
Exemple #6
0
        public void should_send_request_headers()
        {
            var actor = ActorFactory.CreateSomeActorWithApiCallAbility(Sender);

            actor.AttemptsTo(GetHttpInteraction(Urls.UsersApi)
                             .WithHeader(HttpHeaders.Accept, MediaTypes.ApplicationXml));

            Check.That(Sender.GetLastSentMessage().Headers.Accept.First().MediaType).IsEqualTo(MediaTypes.ApplicationXml);
        }
Exemple #7
0
        public void should_send_request_as_json_with_correct_serialization()
        {
            var content = new Package {
                Title = "Suzianna", Version = "1.0"
            };
            var expectedJson = "{\"Title\":\"Suzianna\",\"Version\":\"1.0\"}";
            var actor        = ActorFactory.CreateSomeActorWithApiCallAbility(Sender);

            actor.AttemptsTo(GetHttpInteractionWithJsonContent(content));

            Check.That(Sender.GetLastSentMessage().Content.ReadAsStringAsync().Result).IsEqualTo(expectedJson);
        }
Exemple #8
0
        public void should_send_request_with_authorization_header_when_actor_has_remembered_access_token()
        {
            var actor = ActorFactory.CreateSomeActorWithApiCallAbility(Sender);
            var token = OAuthTokenFactory.SomeToken();

            actor.Remember(TokenConstants.TokenKey, token);

            actor.AttemptsTo(GetHttpInteraction(Urls.UsersApi));

            Check.That(Sender.GetLastSentMessage().Headers.Authorization.Scheme).IsEqualTo(token.TokenType);
            Check.That(Sender.GetLastSentMessage().Headers.Authorization.Parameter).IsEqualTo(token.AccessToken);
        }
Exemple #9
0
        public void should_send_request_as_xml_with_correct_serialization()
        {
            var content = new Package {
                Title = "Suzianna", Version = "1.0"
            };
            var expectedXml = "<Package><Title>Suzianna</Title><Version>1.0</Version></Package>";
            var actor       = ActorFactory.CreateSomeActorWithApiCallAbility(Sender);

            actor.AttemptsTo(GetHttpInteractionWithXmlContent(content));

            var xml    = Sender.GetLastSentMessage().Content.ReadAsStringAsync().Result;
            var source = Input.FromString(xml).Build();

            Check.That(new XPathEngine().Evaluate("//Package/Title", source)).IsEqualTo("Suzianna");
            Check.That(new XPathEngine().Evaluate("//Package/Version", source)).IsEqualTo("1.0");
        }
Exemple #10
0
        public void should_raise_http_request_sent_event()
        {
            Sender.SetupResponse(new HttpResponseBuilder()
                                 .WithHttpStatusCode(HttpStatusCode.Accepted)
                                 .WithContent(Contents.JackProfile)
                                 .Build());

            var juliet          = ActorFactory.CreateSomeActorWithApiCallAbility(Sender);
            var publishedEvents = new Queue <IEvent>();

            Broadcaster.SubscribeToAllEvents(new DelegatingEventHandler(z => publishedEvents.Enqueue(z)));

            juliet.AttemptsTo(GetHttpInteraction(""));

            Check.That(publishedEvents.CountOfType <HttpRequestSentEvent>()).IsEqualTo(1);
            Check.That(publishedEvents.FirstElementOfType <HttpRequestSentEvent>().ResponseCode).IsEqualTo(HttpStatusCode.Accepted);
            Check.That(publishedEvents.FirstElementOfType <HttpRequestSentEvent>().ResponseContent).IsEqualTo(Contents.JackProfile);
        }
Exemple #11
0
 public RopcFlowTests()
 {
     this.sender = new FakeHttpRequestSender();
     actor       = ActorFactory.CreateSomeActorWithApiCallAbility(sender);
 }
 public TokenParsingTests()
 {
     this._sender = new FakeHttpRequestSender();
     this._actor  = ActorFactory.CreateSomeActorWithApiCallAbility(_sender);
 }
Exemple #13
0
 public PostTests()
 {
     actor = ActorFactory.CreateSomeActorWithApiCallAbility(Sender);
 }