Beispiel #1
0
        public async Task TestGetById()
        {
            _sut = new CrudServiceClient(new Dictionary <string, string>(), $"http://*****:*****@"{""id"": 2,""firstname"": ""Daenerys"",""Lastname"": ""Targaryen"",""status"": ""Riding a dragon""}";

            _server
            .Given(Request.Create().WithPath("/users/2").UsingGet())
            .RespondWith(
                Response.Create()
                .WithStatusCode(SuccessStatusCode)
                .WithBody(successResponseBody)
                );


            var result = await _sut.GetById <User>("2");

            Check.That(result.Id).IsEqualTo(user.Id);
            Check.That(result.Firstname).IsEqualTo(user.Firstname);
            Check.That(result.Lastname).IsEqualTo(user.Lastname);
            Check.That(result.Status).IsEqualTo(user.Status);
        }
Beispiel #2
0
        public async Task TestPatchById()
        {
            _sut = new CrudServiceClient(new Dictionary <string, string>(), $"http://*****:*****@"{""result"":""ok""}";

            _server
            .Given(Request.Create().WithPath("/v3/users/42").WithBody(JsonConvert.SerializeObject(requestBody)).UsingPatch())
            .RespondWith(
                Response.Create()
                .WithStatusCode(SuccessStatusCode)
                .WithBody(successResponseBody)
                );


            var result = await _sut.PatchById <User>("42", requestBody);

            var jsonStringResult = await result.ReadAsStringAsync();

            Check.That(jsonStringResult).IsEqualTo(successResponseBody);
        }
Beispiel #3
0
        public async Task TestGet()
        {
            _sut = new CrudServiceClient(new Dictionary <string, string>(), $"http://*****:*****@"[{""id"": 1,""firstname"": ""John"",""Lastname"": ""Snow"",""status"": ""Learning things""},{""id"": 2,""firstname"": ""Daenerys"",""Lastname"": ""Targaryen"",""status"": ""Riding a dragon""}]";

            var query = new Dictionary <string, string> {
                { "foo", "bar" }
            };

            _server
            .Given(Request.Create().WithPath("/v3/users/").WithParam("foo", "bar").UsingGet())
            .RespondWith(
                Response.Create()
                .WithStatusCode(SuccessStatusCode)
                .WithBody(successResponseBody)
                );

            var result = await _sut.Get <User>(query);

            Check.That(result.Count).IsEqualTo(successDeserializedBody.Count);
            Check.That(result[0].Lastname).IsEqualTo("Snow");
            Check.That(result[1].Lastname).IsEqualTo("Targaryen");
        }
Beispiel #4
0
        public async Task TestPostBulk()
        {
            _sut = new CrudServiceClient(new Dictionary <string, string>(), $"http://*****:*****@"{""result"":""ok""}";

            _server
            .Given(Request.Create().WithPath("/v3/users/bulk").UsingPost())
            .RespondWith(
                Response.Create()
                .WithStatusCode(SuccessStatusCode)
                .WithBody(successResponseBody)
                );

            var result = await _sut.PostBulk(newUsers);

            var jsonStringResult = await result.ReadAsStringAsync();

            Check.That(jsonStringResult).IsEqualTo(successResponseBody);
        }
Beispiel #5
0
        public async Task TestPatchBulk()
        {
            _sut = new CrudServiceClient(new Dictionary <string, string>(), $"http://*****:*****@"{""result"":""ok""}";

            _server
            .Given(Request.Create().WithPath("/v3/users/bulk").WithBody(JsonConvert.SerializeObject(requestBody)).UsingPatch())
            .RespondWith(
                Response.Create()
                .WithStatusCode(SuccessStatusCode)
                .WithBody(successResponseBody)
                );


            var result = await _sut.PatchBulk <User>(requestBody);

            var jsonStringResult = await result.ReadAsStringAsync();

            Check.That(jsonStringResult).IsEqualTo(successResponseBody);
        }
Beispiel #6
0
        public async Task TestCount()
        {
            _sut = new CrudServiceClient(new Dictionary <string, string>(), $"http://localhost:{_server.Ports.First()}");

            _server
            .Given(Request.Create().WithPath("/users/count").UsingGet())
            .RespondWith(
                Response.Create()
                .WithStatusCode(SuccessStatusCode)
                .WithBody("42")
                );


            var result = await _sut.Count <User>();

            Check.That(result).IsEqualTo(42);
        }
Beispiel #7
0
        public async Task TestExport()
        {
            _sut = new CrudServiceClient(new Dictionary <string, string>(), $"http://*****:*****@"{""result"":""ok""}";

            _server
            .Given(Request.Create().WithPath("/users/export").UsingGet())
            .RespondWith(
                Response.Create()
                .WithStatusCode(SuccessStatusCode)
                .WithBody(successResponseBody)
                );

            var result = await _sut.Export <User>();

            var jsonStringResult = await result.ReadAsStringAsync();

            Check.That(jsonStringResult).IsEqualTo(successResponseBody);
        }
Beispiel #8
0
        public async Task TestPostValidate()
        {
            _sut = new CrudServiceClient(new Dictionary <string, string>(), $"http://*****:*****@"{""result"":""ok""}";

            _server
            .Given(Request.Create().WithPath("/v3/users/validate").UsingPost())
            .RespondWith(
                Response.Create()
                .WithStatusCode(SuccessStatusCode)
                .WithBody(successResponseBody)
                );

            var result = await _sut.PostValidate <User>(newUser);

            Check.That(result).IsEqualTo(SuccessStatusCode);
        }
Beispiel #9
0
        public async Task TestPost()
        {
            _sut = new CrudServiceClient(new Dictionary <string, string>(), $"http://*****:*****@"{""id"":3,""firstname"":""Arya"",""Lastname"":""Stark"",""status"":""Being no one""}";

            _server
            .Given(Request.Create().WithPath("/v3/users/").UsingPost())
            .RespondWith(
                Response.Create()
                .WithStatusCode(SuccessStatusCode)
                .WithBody(successResponseBody)
                );

            var result = await _sut.Post(newUser);

            var jsonStringResult = await result.ReadAsStringAsync();

            Check.That(jsonStringResult).IsEqualTo(successResponseBody);
        }