Ejemplo n.º 1
0
        public HttpResponseMessage Post([FromBody]PersonModel personModel)
        {
            try
            {
                if (!ModelState.IsValid || personModel == null) return new HttpResponseMessage(HttpStatusCode.BadRequest);

                var person = new Person
                {
                    DateOfBirth = personModel.DateOfBirth,
                    DateOfDeath = personModel.DateOfDeath,
                    FamilyName = personModel.FamilyName,
                    GivenName = personModel.GivenName,
                    Height = personModel.Height,
                    Id = personModel.Id,
                    MiddleNames = personModel.MiddleNames,
                    PlaceOfBirth = personModel.PlaceOfBirth,
                    TwitterId = personModel.TwitterId
                };

                _personManager.AddPerson(person);

                return new HttpResponseMessage(HttpStatusCode.Created);
            }
            catch (Exception)
            {
                 throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
        }
Ejemplo n.º 2
0
        public void GetPersonById_Assert_Person_Returned_With_Correct_Age()
        {
            // Arrange
            var expected = new Person{DateOfBirth = DateTime.Now.AddYears(-30)};
            _dataManager.Stub(x => x.GetPersonFromRepositoryById(Arg<int>.Is.Anything)).Return(expected);
            var personManager = new PersonManager(_dataManager);

            // Act
            var actual = personManager.GetPersonById(1);

            // Assert
            Assert.AreEqual(30, actual.Age);
        }
Ejemplo n.º 3
0
        public void GetPersonById_Assert_Person_Returned()
        {
            // Arrange
            var expected = new Person();
            _dataManager.Stub(x => x.GetPersonFromRepositoryById(Arg<int>.Is.Anything)).Return(expected);
            var personManager = new PersonManager(_dataManager);

            // Act
            var actual = personManager.GetPersonById(1);

            // Assert
            Assert.AreEqual(expected,actual);
        }
Ejemplo n.º 4
0
        private static Person MapKeyValuesToPerson(Dictionary<string, string> kvp)
        {
            var person = new Person();

            foreach (var kv in kvp)
            {
                switch (kv.Key)
                {
                    case "Id":
                        person.Id = int.Parse(kv.Value);
                        break;

                    case "familyName":
                        person.FamilyName = kv.Value;
                        break;

                    case "givenName":
                        person.GivenName = kv.Value;
                        break;

                    case "middleNames":
                        person.MiddleNames = kv.Value.Split(' ');
                        break;

                    case "dateOfBirth":
                        person.DateOfBirth = DateTime.Parse(kv.Value);
                        break;

                    case "dateOfDeath":
                        if (!string.IsNullOrEmpty(kv.Value)) person.DateOfDeath = DateTime.Parse(kv.Value);
                        break;

                    case "placeOfBirth":
                        person.PlaceOfBirth = kv.Value;
                        break;

                    case "height":
                        if (!string.IsNullOrEmpty(kv.Value)) person.Height = double.Parse(kv.Value);
                        break;

                    case "twitterId":
                        person.TwitterId = kv.Value;
                        break;
                }

            }

            return person;
        }
Ejemplo n.º 5
0
 public void AddPerson(Person person)
 {
     _dataManager.AddPersonToRepository(person);
 }
Ejemplo n.º 6
0
 public void AddPersonToRepository(Person person)
 {
     _personMockDataStore.Add(person);
 }