public void EditExistingChannel_ShouldReturn200OK_Modify()
        {
            // Arrange -> create a new channel
            TestingEngine.CleanDatabase();
            var channelName      = "channel" + DateTime.Now.Ticks;
            var httpPostResponse = this.CreateChannelHttpPost(channelName);

            Assert.AreEqual(HttpStatusCode.Created, httpPostResponse.StatusCode);
            var postedChannel = httpPostResponse.Content.ReadAsAsync <ChannelModel>().Result;

            // Act -> edit the above created channel
            var channelNewName  = "Edited " + channelName;
            var httpPutResponse = this.EditChannelHttpPut(postedChannel.Id, channelNewName);

            // Assert -> the PUT result is 200 OK
            Assert.AreEqual(HttpStatusCode.OK, httpPutResponse.StatusCode);

            // Assert the service holds the modified channel
            var httpGetResponse     = TestingEngine.HttpClient.GetAsync("/api/channels").Result;
            var channelsFromService = httpGetResponse.Content.ReadAsAsync <List <ChannelModel> >().Result;

            Assert.AreEqual(HttpStatusCode.OK, httpGetResponse.StatusCode);
            Assert.AreEqual(1, channelsFromService.Count);
            Assert.AreEqual(postedChannel.Id, channelsFromService.First().Id);
            Assert.AreEqual(channelNewName, channelsFromService.First().Name);
        }
Ejemplo n.º 2
0
        public void CreatePeople_ListAllPeople_ShouldListCreatedPeopleCorrectly()
        {
            // Arrange -> prepare a few people objects
            TestingEngine.CleanDatabase();
            var peopleToAdd = new PersonModel[]
            {
                new PersonModel()
                {
                    Name = "Albert Einstein"
                },
                new PersonModel()
                {
                    Name = "Michael Jordan"
                },
                new PersonModel()
                {
                    Name = "Woody Allan"
                },
            };

            // Act -> submit a few people objects
            foreach (var person in peopleToAdd)
            {
                var httpPostResponse = TestingEngine.CreatePersonHttpPost(person.Name);

                // Assert -> ensure each person is successfully created
                Assert.AreEqual(HttpStatusCode.Created, httpPostResponse.StatusCode);
            }

            // Assert -> list the people and assert their count, order and content are correctAnswer
            var httpResponse = TestingEngine.HttpClient.GetAsync("/api/people/all").Result;

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

            var peopleFromService = httpResponse.Content.ReadAsAsync <List <PersonModel> >().Result;

            Assert.AreEqual(peopleToAdd.Count(), peopleFromService.Count);

            var reversedAddedPeople = peopleToAdd.Reverse().ToList();

            for (int i = 0; i < reversedAddedPeople.Count; i++)
            {
                Assert.IsTrue(peopleFromService[i].Id != 0);
                Assert.AreEqual(reversedAddedPeople[i].Name, peopleFromService[i].Name);
            }
        }
Ejemplo n.º 3
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);
        }