public void ShouldWritePerson()
        {
            _personService = new PersonService(_factory);
            _person = new Person { FirstName = "First", LastName = "Last", BirthDate = DateTime.Now};
            var newId = _personService.WritePerson(_person);

            // Yucky Sql Stuff to verify
            string sSQL = "SELECT FirstName, LastName, BirthDate " +
              "FROM Person " +
              "WHERE PersonId = @PersonId";
            Person result;
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sSQL, connection);
                command.Parameters.Add("@PersonId", SqlDbType.UniqueIdentifier).Value = newId;
                var reader = command.ExecuteReader();
                var table = new DataTable();
                table.Load(reader);
                var firstName = table.Rows[0][0].ToString();
                var lastName = table.Rows[0][1].ToString();
                var birthdate = DateTime.Parse(table.Rows[0][2].ToString());
                result = new Person (newId, firstName, lastName, birthdate);
            }

            _person.FirstName.ShouldEqual(result.FirstName);
            _person.LastName.ShouldEqual(result.LastName);
            newId.ShouldEqual(result.PersonId);
        }
 public void ShouldReadPerson()
 {
     _personService = new PersonService(_factory);
     _person = new Person { FirstName = "First", LastName = "Last", BirthDate = DateTime.Now};
     var newId = _personService.WritePerson(_person);
     var readPerson = _personService.GetPerson(newId);
     readPerson.FirstName.ShouldEqual(_person.FirstName);
     readPerson.LastName.ShouldEqual(_person.LastName);
     readPerson.PersonId.ShouldEqual(newId);
 }
예제 #3
0
        static void RunService()
        {
            var personService = new PersonService(new SqlHelperFactory());
            var person = new Person
            {
                FirstName = "Joe",
                LastName = "Reynolds",
                BirthDate = DateTime.Parse("1/1/1900")
            };
            var newId = personService.WritePerson(person);
            WriteLine(newId);

            var readPerson = personService.GetPerson(newId);
            WriteLine($"New Person ID: {readPerson.PersonId}");
            WriteLine($"New Name: {readPerson.FirstName} {readPerson.LastName}");
            WriteLine($"Birthday: {readPerson.BirthDate.ToShortDateString()}");
            WriteLine("Did it work?");
            ReadKey();
            personService.CleanUp();
        }