Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }