public void RestSharpApiCallerCanCallEndpointWithSerializedParameters()
        {
            //Setup
            var createPostRequest = new CreatePostRequest
                                        {
                                            Text = @"@jdscolam this is another #Rapptor #testpost, with links and stuff.  https://github.com/jdscolam/Rapptor and Rapptor NuGet"
                                            , ReplyTo = "197934"
                                        };
            IApiCaller restSharpApiCaller = new RestSharpApiCaller(ACCESS_TOKEN);

            //Execute
            var parameters = PostsService.GetPostRequestParameters(createPostRequest);
            var postCreated = restSharpApiCaller.ApiPost<Post>("posts/", null, parameters.ToArray());

            //Verify
            postCreated.Data.ShouldNotBeNull();
            postCreated.Data.Id.ShouldNotBeNull();
            postCreated.Data.CreatedAt.ShouldNotBeNull();
            postCreated.Data.Text.ShouldNotBeNull();
            postCreated.Data.Text.ShouldEqual(createPostRequest.Text);
            postCreated.Data.Entities.ShouldNotBeNull();
            postCreated.Data.Entities.Links.ShouldNotBeNull();
            postCreated.Data.Entities.Links[0].ShouldNotBeNull();
            postCreated.Data.ReplyTo.ShouldNotBeNull();
            postCreated.Data.ReplyTo.ShouldEqual(createPostRequest.ReplyTo);

            //Teardown
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses a CreatePostRequest instance into the proper request parameters for App.net.
        /// </summary>
        /// <param name="createPostRequest"></param>
        /// <returns></returns>
        public static IEnumerable<RequestParameter> GetPostRequestParameters(CreatePostRequest createPostRequest)
        {
            if(createPostRequest == null)
                return null;

            var requestParameters = new List<RequestParameter>();

            if (!string.IsNullOrWhiteSpace(createPostRequest.Text)) requestParameters.Add(new RequestParameter { Name = "text", Value = createPostRequest.Text });
            if (!string.IsNullOrWhiteSpace(createPostRequest.ReplyTo)) requestParameters.Add(new RequestParameter { Name = "reply_to", Value = createPostRequest.ReplyTo });

            return requestParameters.Count > 0 ? requestParameters : null;
        }
Exemplo n.º 3
0
        public void PostsServiceCanCreateAPost()
        {
            //Setup
            var createdAt = DateTime.Now;
            var createPostRequest = new CreatePostRequest
                                        {
                                            Text = @"@jdscolam this is a test #post, with links and stuff.  https://github.com/jdscolam/Rapptor and Rapptor NuGet"
                                            , ReplyTo = "197934"
                                        };
            var apiCaller = A.Fake<IApiCaller>();
            var postsService = new PostsService(apiCaller);
            A.CallTo(apiCaller).WithReturnType<ResponseEnvelope<Post>>().Returns(new ResponseEnvelope<Post>
            {
                Data = new Post
                             {
                                 Id = "1"
                                 , CreatedAt = createdAt
                                 , Text = createPostRequest.Text
                                 , ReplyTo = createPostRequest.ReplyTo
                             }
            });

            //Execute
            var postCreated = postsService.CreatePost(createPostRequest);

            //Verify
            postCreated.Data.ShouldNotBeNull();
            postCreated.Data.Id.ShouldNotBeNull();
            postCreated.Data.CreatedAt.ShouldNotBeNull();
            postCreated.Data.CreatedAt.ShouldEqual(createdAt);
            postCreated.Data.Text.ShouldNotBeNull();
            postCreated.Data.Text.ShouldEqual(createPostRequest.Text);
            postCreated.Data.ReplyTo.ShouldNotBeNull();
            postCreated.Data.ReplyTo.ShouldEqual(createPostRequest.ReplyTo);

            //Teardown
        }
        public void RestSharpApiCallerCanCreatePostWithAnnotations()
        {
            //Setup
            var annotationValue = new MyAnnotationClass
                                      {
                                          Name = "My test parameter annotation"
                                          , Value = 23.5M
                                      };
            var annotation = new Annotation
                                 {
                                     Type = "net.raptorapp.test.request.parameter"
                                     , Value = annotationValue
                                 };

            var createPostRequest = new CreatePostRequest
            {
                Text = @"@jdscolam this is another #Rapptor #testpost, with links and stuff.  https://github.com/jdscolam/Rapptor and Rapptor NuGet"
                , ReplyTo = "197934"
                , Annotations = new List<Annotation> { annotation }
            };
            var postStreamGeneralParameters = new PostStreamGeneralParameters { IncludeAnnotations = 1 };
            IApiCaller restSharpApiCaller = new RestSharpApiCaller(ACCESS_TOKEN);

            //Execute
            var parameters = PostsService.GetGeneralParameters(postStreamGeneralParameters).ToArray();
            var postCreated = restSharpApiCaller.ApiPost<CreatePostRequest, Post>("posts/", null, createPostRequest);

            //Verify
            postCreated.Data.ShouldNotBeNull();
            postCreated.Data.Id.ShouldNotBeNull();

            postCreated = restSharpApiCaller.ApiGet<Post>("posts/" + postCreated.Data.Id + "/", null, requestParameters: parameters);

            postCreated.Data.Annotations.ShouldNotBeNull();
            postCreated.Data.Annotations.ShouldHaveCount(1);
            postCreated.Data.Annotations.First().Type.ShouldEqual(annotation.Type);

            var myAnnotationObjectValue = postCreated.Data.Annotations.First().Value as MyAnnotationClass;
            myAnnotationObjectValue.ShouldNotBeNull();
            // ReSharper disable PossibleNullReferenceException
            myAnnotationObjectValue.Name.ShouldEqual(annotationValue.Name);
            // ReSharper restore PossibleNullReferenceException
            myAnnotationObjectValue.Value.ShouldEqual(annotationValue.Value);

            //Teardown
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a new post as the current AccessToken.
        /// </summary>
        /// <param name="createPostRequest"></param>
        /// <returns></returns>
        public ResponseEnvelope<Post> CreatePost(CreatePostRequest createPostRequest)
        {
            var post = _apiCaller.ApiPost<CreatePostRequest, Post>(POSTS_ENDPOINT, null, createPostRequest);

            return post;
        }