コード例 #1
0
        public async Task CanDoBasicPut()
        {
            var client = new DummyRestClient();
            var path   = "/posts/1";

            var originalPost = await client.Get().SendAsync(
                path,
                _Deserialize <Post>
                );

            var modifiedPost = new Post
            {
                Id     = originalPost.Id,
                UserId = 12345,
                Title  = Guid.NewGuid().ToString(),
                Body   = Guid.NewGuid().ToString(),
            };

            var updatedPost = await client.Put(_AsJsonContent).SendAsync(
                path,
                modifiedPost,
                _Deserialize <Post>
                );

            Assert.Equal(originalPost.Id, updatedPost.Id);
            Assert.NotEqual(originalPost.UserId, updatedPost.UserId);
            Assert.NotEqual(originalPost.Title, updatedPost.Title);
            Assert.NotEqual(originalPost.Body, updatedPost.Body);

            Assert.Equal(modifiedPost.Id, updatedPost.Id);
            Assert.Equal(modifiedPost.UserId, updatedPost.UserId);
            Assert.Equal(modifiedPost.Title, updatedPost.Title);
            Assert.Equal(modifiedPost.Body, updatedPost.Body);
        }
コード例 #2
0
        public async Task CanDoBasicGet()
        {
            var client = new DummyRestClient();

            var posts = await client.Get().SendAsync(
                "/posts",
                _Deserialize <IEnumerable <Post> >
                );

            Assert.NotEmpty(posts);
        }
コード例 #3
0
        public async Task CanDoBasicPost()
        {
            var client    = new DummyRestClient();
            var localPost = new Post
            {
                UserId = 3,
                Title  = "This is a Title",
                Body   = "This is a body.",
            };

            var createdPost = await client.Post(_AsJsonContent).SendAsync(
                "/posts",
                localPost,
                _Deserialize <Post>
                );

            Assert.NotEqual(localPost.Id, createdPost.Id);
            Assert.Equal(localPost.UserId, createdPost.UserId);
            Assert.Equal(localPost.Title, createdPost.Title);
            Assert.Equal(localPost.Body, createdPost.Body);
        }