Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
4.5 kB
3
Indexable
Never
        [Test, Order(1)]
        public void CreateNewIdea_WithCorrectData_ShouldSucceed()
        {
            var requestData = new IdeaDTO()
            {
                Title = "TestTitle",
                Description = "TestDescription",
            };

            var request = new RestRequest("/api/Idea/Create");
            request.AddJsonBody(requestData);

            var response = client.Execute(request, Method.Post);
            var responseData = JsonSerializer.Deserialize<ApiResponseDTO>(response.Content);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(responseData.Msg, Is.EqualTo("Successfully created!"));
        }

        [Test, Order(2)]
        public void GetAllIdeas_ShouldReturnNonEmptyArray()
        {
            var requestData = new IdeaDTO()
            {
                Title = "TestTitle",
                Description = "TestDescription",
            };

            var request = new RestRequest("/api/Idea/All");
            request.AddJsonBody(requestData);

            var response = client.Execute(request, Method.Get);
            var responseDataArray = JsonSerializer.Deserialize<ApiResponseDTO[]>(response.Content);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(responseDataArray.Length, Is.GreaterThan(0));

            lastIdeaId = responseDataArray[responseDataArray.Length - 1].IdeaId;
        }

        [Test, Order(3)]
        public void EditIdea_WithCorrectData_ShouldSucceed()
        {
            var requestData = new IdeaDTO()
            {
                Title = "EditedTestTitle",
                Description = "TestDescription With Edits",
            };

            var request = new RestRequest("/api/Idea/Edit");
            request.AddQueryParameter("IdeaId", lastIdeaId);
            request.AddJsonBody(requestData);

            var response = client.Execute(request, Method.Put);
            var responseData = JsonSerializer.Deserialize<ApiResponseDTO>(response.Content);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(responseData.Msg, Is.EqualTo("Edited successfully"));
        }

        [Test, Order(4)]
        public void DeleteIdea_ShouldSucceed()
        {
  
            var request = new RestRequest("/api/Idea/Delete");
            request.AddQueryParameter("IdeaId", lastIdeaId);
            

            var response = client.Execute(request, Method.Delete);
            
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(response.Content, Does.Contain("The idea is deleted!"));
        }

        [Test, Order(5)]
        public void CreateNewIdea_WithoutCorrectData_ShouldFail()
        {
            var requestData = new IdeaDTO()
            {
                Title = "TestTitle"
                
            };

            var request = new RestRequest("/api/Idea/Create");
            request.AddJsonBody(requestData);

            var response = client.Execute(request, Method.Post);
            var responseData = JsonSerializer.Deserialize<ApiResponseDTO>(response.Content);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            
        }

        [Test, Order(6)]
        public void EditIdea_WithWrongId_ShouldFail()
        {
            var requestData = new IdeaDTO()
            {
                Title = "EditedTestTitle",
                Description = "TestDescription With Edits",
            };

            var request = new RestRequest("/api/Idea/Edit");
            request.AddQueryParameter("IdeaId", "112233");
            request.AddJsonBody(requestData);

            var response = client.Execute(request, Method.Put);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.That(response.Content, Does.Contain("There is no such idea!"));
        }

        [Test, Order(7)]
        public void DeleteIdea_WithWrongId_ShouldFail()
        {

            var request = new RestRequest("/api/Idea/Delete");
            request.AddQueryParameter("IdeaId", "2233444");


            var response = client.Execute(request, Method.Delete);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.That(response.Content, Does.Contain("There is no such idea!"));
        }

    }
}
Leave a Comment