public void Create_BadRequest() { var input = PersonFixtures.Input(); var failedState = new ModelStateDictionary(); failedState.AddModelError("name", "invalid"); validator.Setup(x => x.Validate(input)).Returns(failedState); var response = controller.Create(input); Assert.IsInstanceOf(typeof(BadRequestResult), response); }
public void Update_NotFound() { var input = PersonFixtures.Input(); service .Setup(x => x.Update(It.IsAny <int>(), It.IsAny <PersonInputForm>())) .Returns(false); var response = controller.Update(1, input); Assert.IsInstanceOf(typeof(NotFoundResult), response); }
public void Update_Created() { var input = PersonFixtures.Input(); var fixture = PersonFixtures.Entity(input); service.Setup(x => x.Update(fixture.Id, input)).Returns(true); var response = controller.Update(fixture.Id, input); var responseResult = (StatusCodeResult)response; Assert.AreEqual(HttpStatusCode.Accepted, responseResult.StatusCode); }
public void Create_Created() { var input = PersonFixtures.Input(); var fixture = PersonFixtures.Entity(input); service.Setup(x => x.Create(input)).Returns(fixture); validator.Setup(x => x.Validate(input)).Returns(new ModelStateDictionary()); var response = controller.Create(input); var responseResult = (CreatedNegotiatedContentResult <PersonEntity>)response; Assert.AreEqual(new Uri(string.Format("people/{0}", fixture.Id), UriKind.Relative), responseResult.Location); Assert.AreEqual(fixture.Id, responseResult.Content.Id); Assert.AreEqual(fixture.Name, responseResult.Content.Name); Assert.AreEqual(fixture.DOB, responseResult.Content.DOB); }