Beispiel #1
0
        public async void AddEntryTest_ReturnsBadRequest_WhenModelStateIsInvalid()
        {
            var mockEntry = new StandEntry {
                Url = "localhost"
            };

            controller.ModelState.AddModelError("Description", "This field is required");

            var result = await controller.AddEntry(mockEntry);

            var actionResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.Equal(new SerializableError(controller.ModelState), actionResult.Value);
        }
Beispiel #2
0
        public async Task <IActionResult> AddEntry([FromBody] StandEntry entry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (entry == null)
            {
                return(BadRequest());
            }

            try
            {
                _standRepository.AddEntry(entry);
                await _standRepository.SaveChanges();

                return(CreatedAtRoute("GetStandLastEntry", new { url = entry.Url }, entry));
            }
            catch (InvalidOperationException)
            {
                return(NotFound());
            }
        }