Ejemplo n.º 1
0
        public void CreateQuoteAndPerson_GetQuoteAuthor_ShouldReturnCorrectAuthorName()
        {
            // Arrange -> prepare a quote and a person
            TestingEngine.CleanDatabase();
            var text       = "Quiet people have the loudest minds.";
            var personName = "Stephen Hawking";

            // Act -> submit a person
            var createPersonHttpPostResponse = TestingEngine.CreatePersonHttpPost(personName);

            // Assert -> ensure the person is successfully created
            Assert.AreEqual(HttpStatusCode.Created, createPersonHttpPostResponse.StatusCode);

            // Act -> submit a quote
            var createQuoteHttpResponse = TestingEngine.CreateQuoteHttpPost(text, personName);

            // Assert -> ensure the quote is successfully created
            Assert.AreEqual(HttpStatusCode.Created, createQuoteHttpResponse.StatusCode);

            var httpResponse = TestingEngine.HttpClient.GetAsync("/api/quotes/all").Result;

            Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode);

            var quotesFromService = httpResponse.Content.ReadAsAsync <List <QuoteModel> >().Result;
            var quoteFromService  = quotesFromService
                                    .FirstOrDefault(q => q.Text == text);
            var peopleFromServiceHttpResponse = TestingEngine.HttpClient.GetAsync("/api/people/all").Result;

            Assert.AreEqual(HttpStatusCode.OK, peopleFromServiceHttpResponse.StatusCode);

            var peopleFromService = peopleFromServiceHttpResponse.Content.ReadAsAsync <List <PersonModel> >().Result;
            var personFromService = peopleFromService
                                    .FirstOrDefault(p => p.Name == personName);

            // Assert -> ensure the quote author is correctAnswer
            Assert.AreEqual(personFromService.Name, quoteFromService.PersonName);
        }