Ejemplo n.º 1
0
        public async void postWithBadTrackReturnsBadRequest()
        {
            var track = new TrackCreateDTO()
            {
            };
            var mockRepository = new Mock <ITrackRepository>();
            var controller     = new TracksController(mockRepository.Object);

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

            var response = await controller.Post(track);

            Assert.IsType <BadRequestObjectResult>(response);
        }
Ejemplo n.º 2
0
        public async void postWithGoodTrackReturnsOK()
        {
            var track = new TrackCreateDTO()
            {
                Name = "eat", LengthInMeters = 100, MaxCars = 50
            };
            var mockRepository = new Mock <ITrackRepository>();

            mockRepository.Setup(a => a.Create(track)).ReturnsAsync(1231);
            var controller = new TracksController(mockRepository.Object);
            var response   = await controller.Post(track) as CreatedAtActionResult;

            Assert.Equal("Get", response.ActionName);
            Assert.Equal(1231, response.RouteValues["id"]);
        }
Ejemplo n.º 3
0
        public async Task Create_given_track_creates_track()
        {
            var expected = new TrackCreateDTO {
                Name = "Awesome Track"
            };

            var mock = new Mock <ITrackRepository>();

            mock.Setup(m => m.Create(expected)).ReturnsAsync(5);

            var controller = new TracksController(mock.Object);

            var actual = await controller.Post(expected) as CreatedAtActionResult;

            Assert.Equal("Get", actual.ActionName);
            Assert.Equal(5, actual.RouteValues["id"]);
        }