Ejemplo n.º 1
0
        public async void  CountryListService_EndpointWorks()
        {
            var testApiPath = "/countries";

            var mockedData = new CountryListDTO
            {
                CountryCollection = new List <CountryDetailsDTO>
                {
                    new CountryDetailsDTO
                    {
                        TranslatedName = "Norge",
                        Code           = "no"
                    }
                }
            };

            ApiStubHelper.StubServer
            .Given(Request.Create().WithPath(testApiPath).UsingGet())
            .RespondWith(
                Response.Create()
                .WithStatusCode(System.Net.HttpStatusCode.OK)
                .WithBody(Newtonsoft.Json.JsonConvert.SerializeObject(mockedData))
                );
            var baseService = new BaseWebService();

            ApiResponse <CountryListDTO> response = await baseService.Get <CountryListDTO>(ApiStubHelper.StubServerUrl + testApiPath);

            Assert.True(response.IsSuccessfull);
            Assert.Equal(mockedData.CountryCollection.Count, response.Data.CountryCollection.Count);
            Assert.Equal(mockedData.CountryCollection[0].Code, response.Data.CountryCollection[0].Code);
            Assert.Equal(mockedData.CountryCollection[0].TranslatedName, response.Data.CountryCollection[0].TranslatedName);
        }
Ejemplo n.º 2
0
        public async Task Get_SendGetRequest_ReturnSuccessResponseWithCorrectTextResult()
        {
            var testApiPath   = "/testGetText";
            var testApiResult = @"
{
	""Test"": ""Test String"",
	""TestBool"": false
}
";

            ApiStubHelper.StubServer
            .Given(Request.Create().WithPath(testApiPath).UsingGet())
            .RespondWith(
                Response.Create()
                .WithStatusCode(System.Net.HttpStatusCode.OK)
                .WithBody(testApiResult)
                );
            var baseService = new BaseWebService();
            ApiResponse <TestModelToParse> response = await baseService.Get <TestModelToParse>(ApiStubHelper.StubServerUrl + testApiPath);

            response.StatusCode.Should().Be((int)HttpStatusCode.OK);
            response.IsSuccessfull.Should().BeTrue();
            response.Data.Test.Should().Be("Test String");
            response.Data.TestBool.Should().BeFalse();
        }