Exemplo n.º 1
0
        public void AddResultWithValidDbReturnsOk()
        {
            //Setup
            var mockEventsRepo       = new Mock <IEventRepo>();
            var mockEventResultsRepo = new Mock <IEventResultsRepo>();
            var mockUserRepo         = new Mock <IUserRepo>();
            var result = new AddResultModel()
            {
                EventId   = 1,
                Hundreths = 100,
                Minutes   = 20,
                Seconds   = 30,
                UserId    = "a1"
            };

            mockEventResultsRepo.Setup(mERR => mERR.AddEventResult(result)).Returns(true);
            var sut = new EventsController(mockEventsRepo.Object, mockEventResultsRepo.Object, mockUserRepo.Object);


            //Action
            var res = sut.AddResult(result);

            //Assert
            res.Should().BeOfType <OkResult>();
        }
Exemplo n.º 2
0
        //POST api/Events/AddResult
        public IHttpActionResult AddResult(AddResultModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var res = _eventResultsRepo.AddEventResult(model);

            return(res ? (IHttpActionResult)Ok() : BadRequest("Unable To add to database"));
        }
Exemplo n.º 3
0
        public void AddResultWithInvalidModelReturnsBadRequest()
        {
            //Setup
            var mockEventsRepo       = new Mock <IEventRepo>();
            var mockEventResultsRepo = new Mock <IEventResultsRepo>();
            var mockUserRepo         = new Mock <IUserRepo>();
            var result = new AddResultModel();

            var sut = new EventsController(mockEventsRepo.Object, mockEventResultsRepo.Object, mockUserRepo.Object);

            sut.ModelState.AddModelError("EventId", "EventId is required");

            //Action
            var res = sut.AddResult(result);

            //Assert
            res.Should().BeOfType <InvalidModelStateResult>();
            res.As <InvalidModelStateResult>().ModelState.IsValid.Should().BeFalse();
        }