Exemplo n.º 1
0
        public IActionResult CreateTape([FromBody] TapeInputModel Tape)
        {
            // Check if input model is valid, output all errors if not
            if (!ModelState.IsValid)
            {
                IEnumerable <string> errorList = ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage);
                throw new InputFormatException("Video tape input model improperly formatted.", errorList);
            }
            // Create new tape if input model was valid
            int id = _tapeService.CreateTape(Tape);

            return(CreatedAtRoute("GetTapeById", new { id }, null));
        }
Exemplo n.º 2
0
        public IActionResult CreateTape([FromBody] TapeInputModel tape)
        {
            if (!ModelState.IsValid)
            {
                throw new ModelFormatException("Tape was not properly formatted");
            }
            var newId = _tapeService.CreateTape(tape);

            return(CreatedAtRoute("GetTapeById", new { tapeId = newId }, null));
        }
Exemplo n.º 3
0
        public void CreateTape_ReturnsId()
        {
            // act
            int result = service.CreateTape(tape);

            // assert
            Assert.IsInstanceOfType(result, typeof(int));
            Assert.AreEqual(1, result);

            _tapeRepository.Verify((m => m.CreateTape(It.IsAny <Tape>())), Times.Once());
        }
Exemplo n.º 4
0
 public void CreateTape_ShouldCallCreateTapeFromTapeRepository()
 {
     _tapeService.CreateTape(It.IsAny <TapeInputModel>());
     _mockTapeRepository.Verify(mock => mock.CreateTape(It.IsAny <TapeInputModel>()), Times.Once());
 }