Пример #1
0
        public void Test_40_Delete_WhenSendTestresults_ShouldDeleteExisting()
        {
            //Arrange
            var NewEntry = new TestResultPostRequestDto
            {
                id        = 900,
                fullName  = testPrefix + "AutoTestMan",
                gender    = "M",
                birthDate = "2019-01-01",
                city      = "BugLand",
                mainSkill = "ForcedDebug",
                phone     = "911",
            };

            postRequest.AddJsonBody(NewEntry);

            //Act
            var postRequestResponse      = client.Execute <TestResult>(postRequest);
            var postResponseDeserialized = JsonConvert.DeserializeObject <TestResult>(postRequestResponse.Content);

            Assert.AreEqual(true, postRequestResponse.IsSuccessful);
            CreatedEntitys.Add(postResponseDeserialized.id);

            var deleteRequest         = new RestRequest($"/superheroes/{postResponseDeserialized.id}", Method.DELETE);
            var deleteRequestResponse = client.Execute <TestResult>(deleteRequest);

            Assert.AreEqual(true, deleteRequestResponse.IsSuccessful);

            var getByIdRequest  = new RestRequest($"/superheroes/{postResponseDeserialized.id}", Method.GET);
            var getByIdResponse = client.Execute <TestResult>(getByIdRequest);

            //Assert
            Assert.That(getByIdResponse.IsSuccessful, Is.False);
            Assert.That(getByIdResponse.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
Пример #2
0
        public void Test_20_Post_WhenSendTestresults_ShouldCreateNewResult(
            int id, string fullName, string gender, String birthDate, string city, string mainSkill, string phone)
        {
            TestResultPostRequestDto testResultPostRequestDto = default(TestResultPostRequestDto);

            //Arrange
            if (phone != string.Empty)
            {
                testResultPostRequestDto = new TestResultPostRequestDto
                {
                    id        = id,
                    fullName  = testPrefix + fullName,
                    gender    = gender,
                    birthDate = birthDate,
                    city      = city,
                    mainSkill = mainSkill,
                    phone     = phone,
                };
            }
            else
            {
                testResultPostRequestDto = new TestResultPostRequestDto
                {
                    id        = id,
                    fullName  = testPrefix + fullName,
                    gender    = gender,
                    birthDate = birthDate,
                    city      = city,
                    mainSkill = mainSkill,
                };
            }


            postRequest.AddJsonBody(testResultPostRequestDto);

            //Act
            var postResponse             = client.Execute <TestResult>(postRequest);
            var postResponseDeserialized = JsonConvert.DeserializeObject <TestResult>(postResponse.Content);

            Assert.AreEqual(true, postResponse.IsSuccessful);
            CreatedEntitys.Add(postResponseDeserialized.id);

            var getResponse             = client.Execute <TestResult>(getRequest);
            var getResponseDeserialized = JsonConvert.DeserializeObject <List <TestResult> >(getResponse.Content);

            var getByIdRequest  = new RestRequest($"/superheroes/{postResponseDeserialized.id}", Method.GET);
            var getByIdResponse = client.Execute <TestResult>(getByIdRequest);

            Assert.AreEqual(true, getByIdResponse.IsSuccessful);
            var getByIdResponseDeserialized = JsonConvert.DeserializeObject <TestResult>(getByIdResponse.Content);

            //Assert
            Assert.That(getResponseDeserialized.Any(x => x.id == postResponseDeserialized.id));
            Assert.That(getResponseDeserialized.Any(x => x.fullName == postResponseDeserialized.fullName));
            //Floating error on get by id like 1/2 times
            Assert.AreEqual(postResponseDeserialized.id, getByIdResponseDeserialized.id);
        }
Пример #3
0
        public void Test_30_Put_WhenSendTestresults_ShouldRefreshWholeResult()
        {
            //Arrange
            var editedCity = "DebuggedLand";
            var NewEntry   = new TestResultPostRequestDto
            {
                id        = 900,
                fullName  = testPrefix + "AutoTestMan",
                gender    = "M",
                birthDate = "2019-01-01",
                city      = "BugLand",
                mainSkill = "ForcedDebug",
                phone     = "911",
            };

            postRequest.AddJsonBody(NewEntry);

            //Act
            var postRequestResponse      = client.Execute <List <TestResult> >(postRequest);
            var postResponseDeserialized = JsonConvert.DeserializeObject <TestResult>(postRequestResponse.Content);

            Assert.AreEqual(true, postRequestResponse.IsSuccessful);
            CreatedEntitys.Add(postResponseDeserialized.id);

            var putRequest = new RestRequest($"/superheroes/{postResponseDeserialized.id}", Method.PUT);

            putRequest.AddJsonBody(new TestResult
            {
                id        = 900,
                fullName  = testPrefix + "AutoTestMan",
                gender    = "M",
                birthDate = "2019-01-01",
                city      = editedCity,
                mainSkill = "ForcedDebug",
                phone     = "911",
            });

            var putRequestResponse = client.Execute <TestResultPostRequestDto>(putRequest);

            Assert.AreEqual(true, putRequestResponse.IsSuccessful);

            var getByIdRequest  = new RestRequest($"/superheroes/{postResponseDeserialized.id}", Method.GET);
            var getByIdResponse = client.Execute <TestResult>(getByIdRequest);

            Assert.AreEqual(true, getByIdResponse.IsSuccessful);
            var getByIdResponseDeserialized = JsonConvert.DeserializeObject <TestResult>(getByIdResponse.Content);

            //Assert
            Assert.AreEqual(getByIdResponseDeserialized.city, editedCity);
        }
Пример #4
0
        public void Test_70_AssumeRegressTesting()
        {
            var testResultPostRequestDto = new TestResultPostRequestDto
            {
                id        = 900,
                fullName  = testPrefix + "AutoTestMan",
                gender    = "M",
                birthDate = "2019-01-01",
                city      = "BugLand",
                mainSkill = "ForcedDebug",
                phone     = "911",
            };

            postRequest.AddJsonBody(testResultPostRequestDto);

            //Act
            var postResponse             = client.Execute <TestResult>(postRequest);
            var postResponseDeserialized = JsonConvert.DeserializeObject <TestResult>(postResponse.Content);

            Assert.AreEqual(true, postResponse.IsSuccessful);
            CreatedEntitys.Add(postResponseDeserialized.id);

            var getResponse             = client.Execute <TestResult>(getRequest);
            var getResponseDeserialized = JsonConvert.DeserializeObject <List <TestResult> >(getResponse.Content);

            IRestResponse <TestResult> getByIdResponse = default(IRestResponse <TestResult>);

            IRestResponse <TestResult> GetByIdResponse()
            {
                var getByIdRequest  = new RestRequest($"/superheroes/{postResponseDeserialized.id}", Method.GET);
                var getByIdResponse = client.Execute <TestResult>(getByIdRequest);

                if (getByIdResponse.StatusCode == HttpStatusCode.BadRequest)
                {
                    throw new HttpListenerException(400, $"REST fault on GetById for superhero id {postResponseDeserialized}");
                }
                else
                {
                    return(getByIdResponse);
                }
            }

            getByIdResponse = RetryHelper.Do(() => GetByIdResponse(), timeBetweenRetrys, retrysToFail);

            var getByIdResponseDeserialized = JsonConvert.DeserializeObject <TestResult>(getByIdResponse.Content);

            //Assert
            Assert.AreEqual(postResponseDeserialized.id, getByIdResponseDeserialized.id);
        }
Пример #5
0
        public void Test_60_PostNegative_WhenSendCorruptedTestresults_ShouldThrow()
        {
            //Arrange
            var NewBadEntry = new TestResultPostRequestDto
            {
                id        = 900,
                gender    = "M",
                birthDate = "2019-01-01",
                city      = "BugLand",
                mainSkill = "ForcedDebug",
                phone     = "911",
            };

            postRequest.AddJsonBody(NewBadEntry);

            //Act
            var postResponse = client.Execute <TestResult>(postRequest);

            Assert.AreEqual(false, postResponse.IsSuccessful);
            Assert.AreEqual(postResponse.StatusCode, HttpStatusCode.Forbidden);
        }
Пример #6
0
        public void Test_50_PostNegative_WhenSendBadTestresults_ShouldReturnBadRequest(
            int id, string fullName, string gender, String birthDate, string city, string mainSkill, string phone)
        {
            //Arrange
            var NewEntry = new TestResultPostRequestDto
            {
                id        = id,
                fullName  = testPrefix + fullName,
                gender    = gender,
                birthDate = birthDate,
                city      = city,
                mainSkill = mainSkill,
                phone     = phone,
            };

            postRequest.AddJsonBody(NewEntry);

            //Act
            var postResponse = client.Execute <TestResult>(postRequest);

            Assert.AreEqual(false, postResponse.IsSuccessful);
            Assert.AreEqual(postResponse.StatusCode, HttpStatusCode.Forbidden);
        }