예제 #1
0
        public void CreateSportTest()
        {
            //Arrange.
            SportModelIn input = new SportModelIn()
            {
                Name       = "Tennis",
                IsTwoTeams = true
            };

            //Act.
            IActionResult        result        = controllerToTest.Post(input);
            CreatedAtRouteResult createdResult = result as CreatedAtRouteResult;
            SportModelOut        output        = createdResult.Value as SportModelOut;

            //Assert.
            sportsService.Verify(r => r.AddSport(It.IsAny <SportDto>()), Times.Once);
            Assert.IsNotNull(result);
            Assert.IsNotNull(createdResult);
            Assert.AreEqual(createdResult.StatusCode, 201);
            Assert.AreEqual(createdResult.RouteName, "GetSportById");
            Assert.IsNotNull(output);
            Assert.AreEqual(output.Name, input.Name);
        }
예제 #2
0
        public void CreateFailedUserTest()

        {
            var modelIn = new SportModelIn();

            var userService = new Mock <ISportService>();

            var controller = new SportsController(userService.Object);

            controller.ModelState.AddModelError("", "Error");

            var result = controller.Post(modelIn);

            var createdResult = result as BadRequestObjectResult;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual(400, createdResult.StatusCode);
        }