コード例 #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);
        }
コード例 #2
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);
        }