Example #1
0
        public void Post_Invalid_UserId_Test()
        {
            // Arrange
            Sport sportObjAsInput = new Sport();

            sportObjAsInput.name   = "Sport 1";
            sportObjAsInput.userId = -1;

            var mockRepository = new Mock <ISportRepository>();

            var controller = new SportController(mockRepository.Object);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            // Act
            HttpResponseMessage response = controller.Post(sportObjAsInput);

            // Assert
            string responseJSONStr = response.Content.ReadAsStringAsync().Result;
            string responseStr     = Helper.Deserialize <string>(responseJSONStr);

            Assert.IsNotNull(response);
            Assert.AreEqual(response.StatusCode, HttpStatusCode.PartialContent);
            Assert.AreEqual(responseStr, "User Id is empty.");
        }
Example #2
0
        public void Post_Valid_Test()
        {
            // Arrange
            Sport sportObjAsInput = new Sport();

            sportObjAsInput.name   = "Sport 1";
            sportObjAsInput.userId = 1;

            var mockRepository = new Mock <ISportRepository>();

            mockRepository.Setup(x => x.InsertSport(sportObjAsInput))
            .Returns(1);

            var controller = new SportController(mockRepository.Object);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            // Act
            HttpResponseMessage response = controller.Post(sportObjAsInput);

            // Assert
            string responseJSONStr = response.Content.ReadAsStringAsync().Result;
            string responseStr     = Helper.Deserialize <string>(responseJSONStr);

            Assert.IsNotNull(response);
            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
            Assert.AreEqual(responseStr, "Sport added successfully.");
        }
Example #3
0
        public void Post_Null_Input_Test()
        {
            // Arrange
            var mockRepository = new Mock <ISportRepository>();

            var controller = new SportController(mockRepository.Object);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            // Act
            HttpResponseMessage response = controller.Post(null);

            // Assert
            string responseJSONStr = response.Content.ReadAsStringAsync().Result;
            string responseStr     = Helper.Deserialize <string>(responseJSONStr);

            Assert.IsNotNull(response);
            Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent);
            Assert.AreEqual(responseStr, "Invalid JSON Passed.");
        }