Ejemplo n.º 1
0
        public async Task CreateExamAsync_InvalidRequest_ReturnsBadRequestResult()
        {
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "1"),
            }));
            var examForCreation = new ExamForCreationDto()
            {
                Password = "******"
            };

            var mapperMock     = new Mock <IMapper>();
            var repositoryMock = new Mock <IRepositoryWrapper>();


            repositoryMock.Setup(r => r.SaveAllAsync()).ReturnsAsync(false);
            repositoryMock.Setup(r => r.ExamRepository.Add(It.IsAny <Exam>()));
            mapperMock.Setup(m => m.Map <Exam>(It.IsAny <ExamForCreationDto>())).Returns(new Exam());



            var controllerMock = new ExamsController(repositoryMock.Object, mapperMock.Object);

            controllerMock.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };
            var result = await controllerMock.CreateExamAsync(examForCreation);

            Assert.IsType <BadRequestObjectResult>(result);
        }