private static void Trace(ReponsePreparee reponsePreparee)
 {
     Console.WriteLine("+++ Ajout d'une réponse préparée +++ ");
     Console.WriteLine("");
     Console.WriteLine(reponsePreparee);
     Console.WriteLine("------------------------------------------");
 }
Exemplo n.º 2
0
        private static async Task WhenPreparerReponse(ReponsePreparee reponsePreparee)
        {
            var stringPayload = JsonConvert.SerializeObject(reponsePreparee);

            var httpContent = AsStringContent(stringPayload);

            await new HttpClient().PostAsync($"{Program.BaseUrl}/prepared-response", httpContent);
        }
        private ActionResult ResponseBuiltFrom(ReponsePreparee reponsePreparee)
        {
            var response = StatusCode(reponsePreparee.StatusCodeOrDefaultForVerbe(), reponsePreparee.Payload);

            foreach (var(key, value) in reponsePreparee.CustomHeaders)
            {
                Response.Headers.Add(key, value);
            }
            return(response);
        }
        public IActionResult Post([FromBody] ReponsePreparee reponsePreparee)
        {
            Trace(reponsePreparee);
            if (!ResponsesPrepareesRepository.ResponsesPreparees.ContainsKey(reponsePreparee.ScenarioId))
            {
                ResponsesPrepareesRepository.ResponsesPreparees[reponsePreparee.ScenarioId] = new List <ReponsePreparee>();
            }

            ResponsesPrepareesRepository.ResponsesPreparees[reponsePreparee.ScenarioId].Add(reponsePreparee);

            return(StatusCode(201));
        }
Exemplo n.º 5
0
        public async void SupporteLeRetourDeHeadersSpecifies()
        {
            var reponsePreparee = new ReponsePreparee
            {
                StatusCode    = 203,
                Url           = "/carrots",
                Verbe         = "GET",
                Payload       = "[{x:1}]",
                CustomHeaders = new Dictionary <string, string>
                {
                    { "coucou", "allo" }
                }
            };

            await WhenPreparerReponse(reponsePreparee);

            var response = new HttpClient().GetAsync($"{Program.BaseUrl}/carrots").Result;

            response.StatusCode.Should().Be(203);
            response.Content.ReadAsStringAsync().Result.Should().Be("[{x:1}]");
            response.Headers.GetValues("coucou").Should().Contain("allo");
        }
Exemplo n.º 6
0
        public async void SupprimeLesReponsesPreparees_ParScenarioId()
        {
            var reponsePrepareeScenario1 = new ReponsePreparee
            {
                StatusCode = 200,
                Url        = "/institutionsFinancieres",
                Verbe      = "GET",
                Payload    = "[{id:815}]",
                ScenarioId = "1"
            };

            var reponsePrepareeScenario2 = new ReponsePreparee
            {
                StatusCode = 200,
                Url        = "/institutionsFinancieres",
                Verbe      = "GET",
                Payload    = "[{id:6}]",
                ScenarioId = "2"
            };

            await WhenPreparerReponse(reponsePrepareeScenario1);
            await WhenPreparerReponse(reponsePrepareeScenario2);

            await new HttpClient().DeleteAsync($"{Program.BaseUrl}/prepared-response?scenarioId=1");

            var httpClientScenario1 = new HttpClient();

            httpClientScenario1.DefaultRequestHeaders.Add("scenario-id", "1");
            var response1 = httpClientScenario1.GetAsync($"{Program.BaseUrl}/institutionsFinancieres").Result;

            response1.StatusCode.Should().Be(501);

            var httpClientScenario2 = new HttpClient();

            httpClientScenario2.DefaultRequestHeaders.Add("scenario-id", "2");
            var response2 = httpClientScenario2.GetAsync($"{Program.BaseUrl}/institutionsFinancieres").Result;

            response2.StatusCode.Should().Be(200);
        }
Exemplo n.º 7
0
        public async void PrepareReponseARetourner_ParScenarioId()
        {
            var reponsePrepareeScenario1 = new ReponsePreparee
            {
                StatusCode = 200,
                Url        = "/institutionsFinancieres",
                Verbe      = "GET",
                Payload    = "[{id:815}]",
                ScenarioId = "1"
            };

            var reponsePrepareeScenario2 = new ReponsePreparee
            {
                StatusCode = 200,
                Url        = "/institutionsFinancieres",
                Verbe      = "GET",
                Payload    = "[{id:6}]",
                ScenarioId = "2"
            };

            await WhenPreparerReponse(reponsePrepareeScenario1);
            await WhenPreparerReponse(reponsePrepareeScenario2);

            var httpClientScenario1 = new HttpClient();

            httpClientScenario1.DefaultRequestHeaders.Add("scenario-id", "1");
            var response1 = httpClientScenario1.GetAsync($"{Program.BaseUrl}/institutionsFinancieres").Result;

            response1.Content.ReadAsStringAsync().Result.Should().Be("[{id:815}]");

            var httpClientScenario2 = new HttpClient();

            httpClientScenario2.DefaultRequestHeaders.Add("scenario-id", "2");
            var response2 = httpClientScenario2.GetAsync($"{Program.BaseUrl}/institutionsFinancieres").Result;

            response2.Content.ReadAsStringAsync().Result.Should().Be("[{id:6}]");
        }
 private bool Matching(ReponsePreparee r)
 {
     return(string.Equals(r.Url, Request.HttpContext.Request.Path.ToString() + Request.HttpContext.Request.QueryString, StringComparison.InvariantCultureIgnoreCase) &&
            string.Equals(r.Verbe, Request.HttpContext.Request.Method, StringComparison.InvariantCultureIgnoreCase));
 }