Esempio n. 1
0
        public async Task PostGreeting()
        {
            // Arrange
            CitiesController controller = new CitiesController();
            JObject          greeting   = new JObject();

            greeting["greeting"] = "Hello, Test.";

            //***Test Valid Request***
            // Act
            IHttpActionResult result = await controller.PostGreeting(_CITY_GUID, _USER_GUID, greeting);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(OkResult));
            //*************************

            //***Test Invalid CityGuid Request***
            // Act
            IHttpActionResult resultCityInvalidGuid = await controller.PostGreeting("invalid", _USER_GUID, greeting);

            // Assert
            Assert.IsNotNull(resultCityInvalidGuid);
            Assert.IsInstanceOfType(resultCityInvalidGuid, typeof(BadRequestErrorMessageResult));
            //*************************

            //***Test Invalid UserGuid Request***
            // Act
            IHttpActionResult resultInvalidUserGuid = await controller.PostGreeting(_CITY_GUID, "invalid", greeting);

            // Assert
            Assert.IsNotNull(resultInvalidUserGuid);
            Assert.IsInstanceOfType(resultInvalidUserGuid, typeof(BadRequestErrorMessageResult));
            //*************************

            //***Test Invalid Greeting Request***
            // Act
            greeting["greeting"] = "";
            IHttpActionResult resultInvalidGreeting = await controller.PostGreeting(_CITY_GUID, _USER_GUID, greeting);

            // Assert
            Assert.IsNotNull(resultInvalidGreeting);
            Assert.IsInstanceOfType(resultInvalidGreeting, typeof(BadRequestErrorMessageResult));
            //*************************

            //***Test Invalid Greeting Request***
            // Act
            greeting["greeting"] = "sp$cia| ch@r";
            IHttpActionResult resultInvalidCharGreeting = await controller.PostGreeting(_CITY_GUID, _USER_GUID, greeting);

            // Assert
            Assert.IsNotNull(resultInvalidCharGreeting);
            Assert.IsInstanceOfType(resultInvalidCharGreeting, typeof(BadRequestErrorMessageResult));
            //*************************
        }