Пример #1
0
        public async Task When_byte_array_different_should_not_match()
        {
            // Arrange
            var client = new MockHttpClient();

            client
            .When(x => x.Content.IsByteArray(new byte[] { 11, 22, 33 }))
            .Then(HttpStatusCode.OK);

            // Act
            var result = await client.PostAsync(new Uri("http://mockhttphandler.local"), new ByteArrayContent(new byte[] { 10, 20, 30 }));

            // Assert
            Assert.NotEqual(HttpStatusCode.OK, result.StatusCode);
        }
Пример #2
0
        public async Task When_content_not_json_should_not_match()
        {
            // Arrange
            var client = new MockHttpClient();

            client
            .When(x => x.Content.IsJson <TestDto>(x => true))
            .Then(HttpStatusCode.OK);


            // Act
            var result = await client.PostAsync(new Uri("http://mockhttphandler.local"), new StringContent("not-a-json-string"));

            // Assert
            Assert.NotEqual(HttpStatusCode.OK, result.StatusCode);
        }
Пример #3
0
        public async Task When_content_same_json_as_anonymous_should_match()
        {
            // Arrange
            var client = new MockHttpClient();

            client
            .When(x => x.Content.IsJson(new
            {
                FirstName = "Wayne",
            }))
            .Then(HttpStatusCode.OK);

            // Act
            var result = await client.PostAsync(new Uri("http://mockhttphandler.local"), new StringContent(@"{""Firstname"":""Wayne"", ""IsMale"":true}"));

            // Assert
            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }
Пример #4
0
        public async Task When_string_content_same_should_match()
        {
            // Arrange
            var client = new MockHttpClient();

            var content = "name=Wayne";

            client
            .When(x => x.Content.IsString(content))
            .Then(HttpStatusCode.OK);

            // Act
            var result = await client.PostAsync(new Uri("http://mockhttphandler.local"),
                                                new StringContent(content));

            // Assert
            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }
Пример #5
0
        public async Task When_content_same_json_should_match()
        {
            // Arrange
            var testDto = new TestDto
            {
                Firstname = "Wayne",
                IsMale    = true
            };

            var client = new MockHttpClient();

            client
            .When(x => x.Content.IsJson(testDto))
            .Then(HttpStatusCode.OK);

            var content = JsonConvert.SerializeObject(testDto);

            // Act
            var result = await client.PostAsync(new Uri("http://mockhttphandler.local"), new StringContent(content));

            // Assert
            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }