Example #1
0
        public void RegisterUser_InvalidUserData_ShouldReturn400_BadRequest()
        {
            // Arrange
            TestingEngine.CleanDatabase();

            // Act -> empty username
            var responseEmptyUsername = TestingEngine.RegisterUserHttpPost("", "#paSSw@rd12345");

            // Assert -> 400 (Bad Request)
            Assert.AreEqual(HttpStatusCode.BadRequest, responseEmptyUsername.StatusCode);

            // Act -> empty password
            var responseEmptyPassword = TestingEngine.RegisterUserHttpPost("maria", "");

            // Assert -> 400 (Bad Request)
            Assert.AreEqual(HttpStatusCode.BadRequest, responseEmptyPassword.StatusCode);

            // Act -> null username
            var responseNullUsername = TestingEngine.RegisterUserHttpPost(null, "#paSSw@rd12345");

            // Assert -> 400 (Bad Request)
            Assert.AreEqual(HttpStatusCode.BadRequest, responseNullUsername.StatusCode);

            // Act -> null password
            var responseNullPassword = TestingEngine.RegisterUserHttpPost("maria", null);

            // Assert -> 400 (Bad Request)
            Assert.AreEqual(HttpStatusCode.BadRequest, responseNullPassword.StatusCode);

            // Act -> no data (empty HTTP body)
            var httpResponse = TestingEngine.HttpClient.PostAsync("/api/user/register", null).Result;

            // Assert -> 400 (Bad Request)
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode);
        }
        public void DeleteChannel_WhenIsExistingAndNonEmpty_ShoulReturn409()
        {
            // Arrange -> create a channel
            TestingEngine.CleanDatabase();

            MessagesDbContext dbContext = new MessagesDbContext();
            var existingChannel         = new Channel()
            {
                Name = "Existing Channel"
            };

            existingChannel.ChannelMessages.Add(new ChannelMessage()
            {
                Id       = 11,
                Text     = "Some text",
                DateSent = DateTime.Now,
                Sender   = null
            });
            dbContext.Channels.Add(existingChannel);
            dbContext.SaveChanges();

            // Act -> delete the channel
            var httpDeleteResponse = TestingEngine.HttpClient.DeleteAsync(
                "/api/channels/" + existingChannel.Id).Result;

            // Assert -> HTTP status code is 409
            Assert.AreEqual(HttpStatusCode.Conflict, httpDeleteResponse.StatusCode);
            var result = httpDeleteResponse.Content.ReadAsStringAsync().Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(1, dbContext.Channels.Count());
        }
        public void EditExistingChannel_ShouldReturn200OK_Modify()
        {
            // Arrange -> create a new channel
            TestingEngine.CleanDatabase();
            var channelName      = "channel" + DateTime.Now.Ticks;
            var httpPostResponse = TestingEngine.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 = TestingEngine.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);
        }
        public void DeleteChannel_WithMessages_ShouldReturn409Conflict()
        {
            // Arrange -> create a channel with a message posted in it
            TestingEngine.CleanDatabase();

            // Create a channel
            var channelName = "channel" + DateTime.Now.Ticks;
            var httpResponseCreateChanel = TestingEngine.CreateChannelHttpPost(channelName);

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

            Assert.AreEqual(1, TestingEngine.GetChannelsCountFromDb());

            // Post an anonymous message in the channel
            var httpResponsePostMsg = TestingEngine.SendChannelMessageHttpPost(channelName, "message");

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

            // Act -> try to delete the channel with the message
            var httpDeleteResponse = TestingEngine.HttpClient.DeleteAsync(
                "/api/channels/" + channel.Id).Result;

            // Assert -> HTTP status code is 409 (Conflict), channel is not empty
            Assert.AreEqual(HttpStatusCode.Conflict, httpDeleteResponse.StatusCode);
            Assert.AreEqual(1, TestingEngine.GetChannelsCountFromDb());
        }
Example #5
0
        public void ListChannelMessages_ExistingChannel_ShouldReturn200OK_SortedMessagesByDate()
        {
            // Arrange -> create a chennel and send a few messages to it
            TestingEngine.CleanDatabase();

            // Create a channel
            var channelName = "channel" + DateTime.Now.Ticks;
            var httpResponseCreateChannel = TestingEngine.CreateChannelHttpPost(channelName);

            Assert.AreEqual(HttpStatusCode.Created, httpResponseCreateChannel.StatusCode);

            // Send a few messages to the channel
            string firstMsg             = "First message";
            var    httpResponseFirstMsg = TestingEngine.SendChannelMessageHttpPost(channelName, firstMsg);

            Assert.AreEqual(HttpStatusCode.OK, httpResponseFirstMsg.StatusCode);
            Thread.Sleep(2);

            string secondMsg             = "Second message";
            var    httpResponseSecondMsg = TestingEngine.SendChannelMessageHttpPost(channelName, secondMsg);

            Assert.AreEqual(HttpStatusCode.OK, httpResponseSecondMsg.StatusCode);
            Thread.Sleep(2);

            string thirdMsg             = "Third message";
            var    httpResponseThirdMsg = TestingEngine.SendChannelMessageHttpPost(channelName, thirdMsg);

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

            // Act -> list the channel messages
            var urlMessages          = "/api/channel-messages/" + WebUtility.UrlEncode(channelName);
            var httpResponseMessages = TestingEngine.HttpClient.GetAsync(urlMessages).Result;

            // Assert -> messages are returned correcty, ordered from the last to the first
            Assert.AreEqual(HttpStatusCode.OK, httpResponseMessages.StatusCode);
            var messages = httpResponseMessages.Content.ReadAsAsync <List <MessageModel> >().Result;

            Assert.AreEqual(3, messages.Count);

            // Check the first message
            Assert.IsTrue(messages[2].Id > 0);
            Assert.AreEqual(firstMsg, messages[2].Text);
            Assert.IsTrue((DateTime.Now - messages[2].DateSent) < TimeSpan.FromMinutes(1));
            Assert.IsNull(messages[2].Sender);

            // Check the second message
            Assert.IsTrue(messages[1].Id > 0);
            Assert.AreEqual(secondMsg, messages[1].Text);
            Assert.IsTrue((DateTime.Now - messages[1].DateSent) < TimeSpan.FromMinutes(1));
            Assert.IsNull(messages[1].Sender);

            // Check the third message
            Assert.IsTrue(messages[0].Id > 0);
            Assert.AreEqual(thirdMsg, messages[0].Text);
            Assert.IsTrue((DateTime.Now - messages[0].DateSent) < TimeSpan.FromMinutes(1));
            Assert.IsNull(messages[0].Sender);
        }
        public void GetChannelById_EmptyDb_ShouldReturn404NotFound()
        {
            // Arrange
            TestingEngine.CleanDatabase();

            // Act
            var httpResponse = TestingEngine.HttpClient.GetAsync("/api/channels/1").Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, httpResponse.StatusCode);
        }
        public void EditNotExistingChannel_ShouldReturn404NotFond()
        {
            // Arrange -> clear the database
            TestingEngine.CleanDatabase();

            // Act -> try to edit non-existing channel
            var httpPutResponse = TestingEngine.EditChannelHttpPut(1, "new name");

            // Assert -> the PUT result is 404 Not Found
            Assert.AreEqual(HttpStatusCode.NotFound, httpPutResponse.StatusCode);
        }
        public void DeleteNonExistingChannel_ShouldReturn404NotFound()
        {
            // Arrange -> clean the DB
            TestingEngine.CleanDatabase();

            // Act -> delete the channel
            var httpDeleteResponse = TestingEngine.HttpClient.DeleteAsync("/api/channels/1").Result;

            // Assert -> HTTP status code is 404 (Not Found)
            Assert.AreEqual(HttpStatusCode.NotFound, httpDeleteResponse.StatusCode);
        }
        public void SendChannelMessage_NonExitingChannel_ShouldReturn404NotFound()
        {
            // Arrange
            TestingEngine.CleanDatabase();
            var channelName = "non-existing-channel";

            // Act -> try to send a message to non-existing channel
            var httpResponse = TestingEngine.SendChannelMessageHttpPost(channelName, "msg");

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, httpResponse.StatusCode);
        }
Example #10
0
        public void SendAnonymousPersonalMessage_InvalidRecipient_ShouldReturn400BadRequest()
        {
            // Arrange
            TestingEngine.CleanDatabase();
            var username = "******";

            // Act -> send a message to invalid recipient user
            var httpResponse = TestingEngine.SendPersonalMessageHttpPost(username, "Some message");

            // Assert -> 400 (Bad Request)
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode);
        }
        public void ListChannelMessages_NonExistingChannel_ShouldReturn404NotFound()
        {
            // Arrange
            TestingEngine.CleanDatabase();
            var channelName = "non-existing-channel";

            // Act
            var urlMessages          = "/api/channel-messages/" + WebUtility.UrlEncode(channelName);
            var httpResponseMessages = TestingEngine.HttpClient.GetAsync(urlMessages).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, httpResponseMessages.StatusCode);
        }
Example #12
0
        public void RegisterUser_DuplicatedUsername_ShouldReturn400_BadRequest()
        {
            // Arrange
            TestingEngine.CleanDatabase();

            // Act
            var responseFirstRegistration  = TestingEngine.RegisterUserHttpPost("maria", "#paSSw@rd12345");
            var responseSecondRegistration = TestingEngine.RegisterUserHttpPost("maria", "0th3RPassw@rd");

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, responseFirstRegistration.StatusCode);
            Assert.AreEqual(HttpStatusCode.BadRequest, responseSecondRegistration.StatusCode);
        }
Example #13
0
        public void UserLogin_InvalidUser_ShouldReturn400_BadRequest()
        {
            // Arrange
            TestingEngine.CleanDatabase();
            var username = "******";
            var password = "******";

            // Act
            var loginResponse = TestingEngine.LoginUserHttpPost(username, password);

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, loginResponse.StatusCode);
        }
        public void DeleteChannel_WhenIsNonExisting_ShoulReturn404()
        {
            // Arrange -> create a channel
            TestingEngine.CleanDatabase();
            var nonExistingChannelId = 5;

            // Act -> delete the channel
            var httpDeleteResponse = TestingEngine.HttpClient.DeleteAsync(
                "/api/channels/" + nonExistingChannelId).Result;

            // Assert -> HTTP status code is 404
            Assert.AreEqual(HttpStatusCode.NotFound, httpDeleteResponse.StatusCode);
        }
        public void DeleteChannel_DeleteExistingChannel_ShouldReturn200OK()
        {
            // Arrange -> prepare a few channels
            TestingEngine.CleanDatabase();
            var channelName = "deleteme";

            // Act -> create a few channels
            this.CreateChannelHttpPost(channelName);
            var deleteResponseMessage = this.DeleteChannelHttpDelete(channelName);

            Assert.AreEqual(HttpStatusCode.OK, deleteResponseMessage.StatusCode);
            Assert.AreEqual("", deleteResponseMessage.Content);
            Assert.AreEqual(0, TestingEngine.GetChannelsCountFromDb());
        }
        public void CreateNewChannel_EmptyBody_ShouldReturn400BadRequest()
        {
            // Arrange
            TestingEngine.CleanDatabase();

            // Act
            var httpResponse = TestingEngine.HttpClient.PostAsync("/api/channels", null).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode);
            var channelsCountInDb = TestingEngine.GetChannelsCountFromDb();

            Assert.AreEqual(0, channelsCountInDb);
        }
        public void ListChannels_EmptyDb_ShouldReturn200Ok_EmptyList()
        {
            // Arrange
            TestingEngine.CleanDatabase();

            // Act
            var httpResponse = TestingEngine.HttpClient.GetAsync("/api/channels").Result;
            var channels     = httpResponse.Content.ReadAsAsync <List <ChannelModel> >().Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode);
            Assert.AreEqual(httpResponse.Content.Headers.ContentType.MediaType, "application/json");
            Assert.AreEqual(0, channels.Count);
        }
        public void CreateNewChannel_NameTooLong_ShouldReturn400BadRequest()
        {
            // Arrange
            TestingEngine.CleanDatabase();
            var tooLongChannelName = new string('a', 101);

            // Act
            var httpResponse = TestingEngine.CreateChannelHttpPost(tooLongChannelName);

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode);
            var channelsCountInDb = TestingEngine.GetChannelsCountFromDb();

            Assert.AreEqual(0, channelsCountInDb);
        }
        public void CreateNewChannel_InvalidData_ShouldReturn400BadRequest()
        {
            // Arrange
            TestingEngine.CleanDatabase();
            var invalidChannelName = string.Empty;

            // Act
            var httpResponse = TestingEngine.CreateChannelHttpPost(invalidChannelName);

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode);
            var channelsCountInDb = TestingEngine.GetChannelsCountFromDb();

            Assert.AreEqual(0, channelsCountInDb);
        }
Example #20
0
        public void ListUserMessages_EmptyDb_ShouldReturn200Ok_EmptyList()
        {
            // Arrange -> create a new user
            TestingEngine.CleanDatabase();
            var userSession = TestingEngine.RegisterUser("maria", "P@ssW01345");

            // Act -> list user messages
            var httpResponseMessages = 
                TestingEngine.GetPersonalMessagesForUserHttpGet(userSession.Access_Token);

            // Assert -> expect empty list of messages
            Assert.AreEqual(HttpStatusCode.OK, httpResponseMessages.StatusCode);
            var messages = httpResponseMessages.Content.ReadAsAsync<List<MessageModel>>().Result;
            Assert.AreEqual(0, messages.Count);
        }
        public void CreateDuplicatedChannels_ShouldReturn409Conflict()
        {
            // Arrange
            TestingEngine.CleanDatabase();
            var channelName = "channel" + DateTime.Now.Ticks;

            // Act
            var httpResponseFirst = TestingEngine.CreateChannelHttpPost(channelName);

            Assert.AreEqual(HttpStatusCode.Created, httpResponseFirst.StatusCode);

            var httpResponseSecond = TestingEngine.CreateChannelHttpPost(channelName);

            // Assert
            Assert.AreEqual(HttpStatusCode.Conflict, httpResponseSecond.StatusCode);
        }
Example #22
0
        public void UserLogin_ValidUser_ShouldReturn200Ok_AccessToken()
        {
            // Arrange
            TestingEngine.CleanDatabase();
            var username = "******";
            var password = "******";

            // Act
            var userSessionRegister = TestingEngine.RegisterUser(username, password);
            var userSessionLogin    = TestingEngine.LoginUser(username, password);

            // Assert
            Assert.AreEqual(username, userSessionRegister.UserName);
            Assert.AreEqual(username, userSessionLogin.UserName);
            Assert.AreEqual(userSessionLogin.UserName, userSessionRegister.UserName);
            Assert.AreNotEqual(userSessionLogin.Access_Token, userSessionRegister.Access_Token);
        }
        public void EditChannel_LeaveSameName_ShouldReturn200OK()
        {
            // Arrange -> create a channel
            TestingEngine.CleanDatabase();

            var channelName      = "channel" + DateTime.Now.Ticks;
            var httpPostResponse = TestingEngine.CreateChannelHttpPost(channelName);

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

            // Act -> try to edit the channel and leave its name the same
            var httpPutResponse = TestingEngine.EditChannelHttpPut(channel.Id, channelName);

            // Assert -> HTTP status code is 200 (OK)
            Assert.AreEqual(HttpStatusCode.OK, httpPutResponse.StatusCode);
        }
        public void EditChannel_EmptyBody_ShouldReturn400BadRequest()
        {
            // Arrange -> create a new channel
            TestingEngine.CleanDatabase();
            var channelName      = "channel" + DateTime.Now.Ticks;
            var httpPostResponse = TestingEngine.CreateChannelHttpPost(channelName);

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

            // Act -> try to edit the above created channel
            var httpPutResponse = TestingEngine.HttpClient.PutAsync(
                "/api/channels/" + postedChannel.Id, null).Result;

            // Assert -> the PUT result is 400 Bad Request
            Assert.AreEqual(HttpStatusCode.BadRequest, httpPutResponse.StatusCode);
        }
Example #25
0
        public void SendAnonymousPersonalMessage_InvalidData_ShouldReturn400BadRequest()
        {
            // Arrange
            TestingEngine.CleanDatabase();

            // Act -> POST an empty (null) message
            var httpResponseNullData = TestingEngine.HttpClient.PostAsync(
                "/api/user/personal-messages", null).Result;

            // Assert -> 400 (Bad Request)
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponseNullData.StatusCode);

            // Act -> send an empty message to empty recipient
            var httpResponseEmptyData = TestingEngine.SendPersonalMessageHttpPost("", "");

            // Assert -> 400 (Bad Request)
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponseEmptyData.StatusCode);
        }
        public void ListChannelMessages_EmptyDb_ShouldReturn200Ok_EmptyList()
        {
            // Arrange -> create a new channel
            TestingEngine.CleanDatabase();
            var channelName = "channel" + DateTime.Now.Ticks;
            var httpResponseCreateChannel = TestingEngine.CreateChannelHttpPost(channelName);

            Assert.AreEqual(HttpStatusCode.Created, httpResponseCreateChannel.StatusCode);

            // Act -> list channel messages
            var urlMessages          = "/api/channel-messages/" + WebUtility.UrlEncode(channelName);
            var httpResponseMessages = TestingEngine.HttpClient.GetAsync(urlMessages).Result;

            // Assert -> expect empty list of messages
            Assert.AreEqual(HttpStatusCode.OK, httpResponseMessages.StatusCode);
            var messages = httpResponseMessages.Content.ReadAsAsync <List <MessageModel> >().Result;

            Assert.AreEqual(0, messages.Count);
        }
        public void ListChannelMessagesWithInvalidLimit_ShouldReturn400BadRequest()
        {
            // Arrange -> create a chennel and send a few messages to it
            TestingEngine.CleanDatabase();

            // Create a channel
            var channelName = "channel" + DateTime.Now.Ticks;
            var httpResponseCreateChannel = TestingEngine.CreateChannelHttpPost(channelName);

            Assert.AreEqual(HttpStatusCode.Created, httpResponseCreateChannel.StatusCode);

            // Send a few messages to the channel
            string firstMsg             = "First message";
            var    httpResponseFirstMsg = TestingEngine.SendChannelMessageHttpPost(channelName, firstMsg);

            Assert.AreEqual(HttpStatusCode.OK, httpResponseFirstMsg.StatusCode);
            Thread.Sleep(2);

            string secondMsg             = "Second message";
            var    httpResponseSecondMsg = TestingEngine.SendChannelMessageHttpPost(channelName, secondMsg);

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

            // Act -> list the channel messages with limit 1001
            var urlMessages  = "/api/channel-messages/" + WebUtility.UrlEncode(channelName);;
            var httpResponse = TestingEngine.HttpClient.GetAsync(urlMessages + "?limit=1001").Result;

            // Assert -> 400 (Bad Request)
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode);

            // Act -> list the channel messages with limit 0
            httpResponse = TestingEngine.HttpClient.GetAsync(urlMessages + "?limit=0").Result;

            // Assert -> 400 (Bad Request)
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode);

            // Act -> list the channel messages with limit "invalid"
            httpResponse = TestingEngine.HttpClient.GetAsync(urlMessages + "?limit=invalid").Result;

            // Assert -> 400 (Bad Request)
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode);
        }
Example #28
0
        public void SendPersonalMessage_ListPersonalMessages_ShouldReturn200Ok_MessagesList()
        {
            // Arrange -> register sender and recipient users
            TestingEngine.CleanDatabase();
            string senderUsername    = "******";
            var    senderUserSession = TestingEngine.RegisterUser(senderUsername, "P@ssW01345");
            string recipientUsername = "******";
            var    recipientSession  = TestingEngine.RegisterUser(recipientUsername, "#testAZx$27");
            var    messages          = new string[] {
                "Hello Peter " + DateTime.Now.Ticks,
                "Hello Peter (again) " + DateTime.Now.Ticks + 1,
                "Hello Peter (one more time) " + DateTime.Now.Ticks + 2
            };

            // Act -> send several messages to the user
            foreach (var message in messages)
            {
                var httpResponse = TestingEngine.SendPersonalMessageHttpPost(
                    senderUserSession.Access_Token, recipientUsername, message);
                Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode);
            }

            // Assert -> expect to get the messages correctly
            var httpResponseMessages =
                TestingEngine.GetPersonalMessagesForUserHttpGet(recipientSession.Access_Token);
            var messagesFromService =
                httpResponseMessages.Content.ReadAsAsync <List <MessageModel> >().Result;

            Assert.AreEqual(messages.Count(), messagesFromService.Count);

            // Expect the messages to arrive ordered by date (from the last to the first)
            messagesFromService.Reverse();
            for (int i = 0; i < messages.Length; i++)
            {
                Assert.IsTrue(messagesFromService[i].Id > 0);
                Assert.AreEqual(senderUsername, messagesFromService[i].Sender);
                Assert.IsNotNull(messagesFromService[i].DateSent);
                Assert.IsTrue((DateTime.Now - messagesFromService[0].DateSent) < TimeSpan.FromMinutes(1));
                Assert.AreEqual(messages[i], messagesFromService[i].Text);
            }
        }
        public void DeleteExistingChannel_ShouldReturn200OK()
        {
            // Arrange -> create a channel
            TestingEngine.CleanDatabase();

            var channelName      = "channel" + DateTime.Now.Ticks;
            var httpPostResponse = TestingEngine.CreateChannelHttpPost(channelName);

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

            Assert.AreEqual(1, TestingEngine.GetChannelsCountFromDb());

            // Act -> delete the channel
            var httpDeleteResponse = TestingEngine.HttpClient.DeleteAsync(
                "/api/channels/" + channel.Id).Result;

            // Assert -> HTTP status code is 200 (OK)
            Assert.AreEqual(HttpStatusCode.OK, httpDeleteResponse.StatusCode);
            Assert.AreEqual(0, TestingEngine.GetChannelsCountFromDb());
        }
        public void CreateNewChannel_ShouldCreateChannel_Return201Created()
        {
            // Arrange
            TestingEngine.CleanDatabase();
            var channelName = "channel" + DateTime.Now.Ticks;

            // Act
            var httpResponse = TestingEngine.CreateChannelHttpPost(channelName);

            // Assert
            Assert.AreEqual(HttpStatusCode.Created, httpResponse.StatusCode);
            Assert.IsNotNull(httpResponse.Headers.Location);
            var newChannel = httpResponse.Content.ReadAsAsync <ChannelModel>().Result;

            Assert.IsTrue(newChannel.Id != 0);
            Assert.AreEqual(newChannel.Name, channelName);

            var channelsCountInDb = TestingEngine.GetChannelsCountFromDb();

            Assert.AreEqual(1, channelsCountInDb);
        }