#!/usr/bin/perl
use strict;
use warnings;
use Test::More qw(no_plan);

# Same as "use RegistrarData;", but traps errors
BEGIN { 
  use_ok('RegistrarData'); 
}

`./init_db`;  # make sure database is in initial state.

my $data;
ok($data = RegistrarData->new,       "create registrarData object");
my $person;
ok($person = $data->getNextPerson,   "get first person");
ok(ref($person) eq 'Person',         ".. which is a Person");
ok($person->name  eq 'E. Einstein',  ".. whose name is Einstein");
ok($person->phone eq '222-9999',     ".. whose phone is 222-9999");

$data->reset;  # start over
my $count=0;   # count how many people we can get.
$count++ while $data->getNextPerson;
ok($count == 8,                      "8 people in the test database");

$data->addPerson(name => 'S. Claus', phone => '000-0000');

$data->reset;  # start over
$count=0;
$count++ while $data->getNextPerson;
ok($count == 9,                      "9 people after adding one.");

# This was a bug : stale statement handle after end of loop through getNextPerson
$count=0;
$count++ while $data->getNextPerson;
ok($count == 9,                      "count again without reset.");

