Ready to test

This commit is contained in:
2022-07-24 12:35:00 -07:00
parent 4a3e24236f
commit 36592ea319
58 changed files with 1743 additions and 995 deletions

View File

@ -7,7 +7,7 @@ internal abstract class Person
// ...
private static List<string> ValidatePerson(Models.Properties.IStorage storage, Models.PersonId id, Models.PersonBirthday birthday, Models.PersonName name)
private static List<string> ValidatePerson(Properties.IStorage storage, Models.PersonId id, Models.PersonBirthday birthday, Models.PersonName name)
{
List<string> results = new();
if (birthday is null)
@ -21,16 +21,16 @@ internal abstract class Person
if (name.First is null || string.IsNullOrEmpty(name.First.Value))
results.Add("Fist Name must be supplied!");
if (PersonBirthday.DoesBirthDateExits(storage, birthday))
results.Add("Birthdate already exits!");
results.Add("BirthDate already exits!");
return results;
}
internal static Models.Person CreatePerson(Models.Properties.IStorage storage, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses)
internal static Models.Person CreatePerson(Properties.IStorage storage, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses)
{
Models.Person result;
Models.PersonId id = new(birthday.Value.Ticks);
if (birthday.Value == DateTime.MinValue)
birthday = PersonBirthday.GetNextBirthdate(storage);
birthday = PersonBirthday.GetNextBirthDate(storage);
List<string> results = ValidatePerson(storage, id, birthday, name);
if (results.Any())
throw new Exception(string.Join(Environment.NewLine, results));
@ -126,14 +126,14 @@ internal abstract class Person
return results;
}
internal static void SavePerson(Models.Properties.IStorage storage, Models.Person person)
internal static void SavePerson(Properties.IStorage storage, Models.Person person)
{
string fileName = IPerson.GetFileFullName(storage, person);
string json = JsonSerializer.Serialize(person, new JsonSerializerOptions { WriteIndented = true });
_ = IStorage.WriteAllText(fileName, json, compareBeforeWrite: true);
}
private static List<Models.Person> GetPeopleFromText(Models.Properties.IStorage storage, string localKnownPeopleFile)
private static List<Models.Person> GetPeopleFromText(Properties.IStorage storage, string localKnownPeopleFile)
{
List<Models.Person> results = new();
string comment;
@ -175,7 +175,7 @@ internal abstract class Person
return results;
}
internal static Models.Person[] GetPeople(Models.Properties.IStorage storage)
internal static Models.Person[] GetPeople(Properties.IStorage storage)
{
List<Models.Person> results = new();
string json;
@ -187,11 +187,14 @@ internal abstract class Person
string directory = Path.Combine(storage.PeopleRootDirectory, "{}");
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
if (!Directory.Exists(storage.RootDirectory))
string? rootDirectoryParent = Path.GetDirectoryName(storage.RootDirectory);
if (string.IsNullOrEmpty(rootDirectoryParent))
throw new Exception($"{nameof(rootDirectoryParent)} is null!");
if (!Directory.Exists(rootDirectoryParent))
localKnownPeopleFile = string.Empty;
else
{
files = Directory.GetFiles(storage.RootDirectory, "*People*.txt", SearchOption.TopDirectoryOnly);
files = Directory.GetFiles(rootDirectoryParent, "*People*.txt", SearchOption.TopDirectoryOnly);
if (files.Any())
localKnownPeopleFile = files[0];
else