Added test and refactor

This commit is contained in:
abdelkader
2023-05-10 13:20:17 -04:00
parent d9657f2318
commit 834c1a7243
9 changed files with 300 additions and 263 deletions

View File

@@ -146,22 +146,12 @@
{
get
{
string s = @"BEGIN:VCARD
VERSION:4.0
N:Gump;Forrest;;;
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;MEDIATYPE=image/jpg:https://upload.wikimedia.org/wikipedia/commons/thumb/9/95/TomHanksForrestGump94.jpg/224px-TomHanksForrestGump94.jpg
TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212
TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212
ADR;TYPE=work;LABEL=""100 Waters Edge\nBaytown, LA 30314\nUnited States of America""
:;;100 Waters Edge; Baytown;LA;30314;United States of America
ADR;TYPE=home;LABEL=""42 Plantation St.\nBaytown, LA 30314\nUnited States of America""
:;;42 Plantation St.; Baytown;LA;30314;United States of America
EMAIL:forrestgump @example.com
REV:20080424T195243Z
END:VCARD";
string s = @"BEGIN:VCARD\n" +
"VERSION:4.0\n" +
"N:Gump;Forrest;;;\n" +
"FN:Forrest Gump\n" +
"PHOTO;MEDIATYPE=image/jpg:https://upload.wikimedia.org/wikipedia/commons/thumb/9/95/TomHanksForrestGump94.jpg/224px-TomHanksForrestGump94.jpg\n" +
"END:VCARD";
return s.Split('\n');
}
}

View File

@@ -118,7 +118,6 @@ namespace vCardEditor_Test
var repo = Substitute.For<ContactRepository>(fileHandler);
repo.GetExtension(Arg.Any<string>()).Returns(".vcf");
var view = Substitute.For<IMainView>();
_ = new MainPresenter(view, repo);
view.NewFileOpened += Raise.EventWith(new EventArg<string>("aaa.vcf"));
@@ -164,13 +163,10 @@ namespace vCardEditor_Test
_ = new MainPresenter(view, repo);
var contact = repo.LoadContacts("aaa.vcf");
view.AddressRemoved += Raise.EventWith(new EventArg<int>(0));
Assert.AreEqual(1, contact[0].card.DeliveryAddresses.Count);
}
[TestMethod]
@@ -221,7 +217,23 @@ namespace vCardEditor_Test
[TestMethod]
public void ExportImage_ShouldExportArrayByte_Test()
{
var fileHandler = Substitute.For<IFileHandler>();
fileHandler.ReadAllLines(Arg.Any<string>()).Returns(Entries.vcfwithInternalPhoto);
var repo = Substitute.For<ContactRepository>(fileHandler);
var view = Substitute.For<IMainView>();
view.SelectedContactIndex.Returns(0);
_ = new MainPresenter(view, repo);
_ = repo.LoadContacts("aaa.vcf");
view.ExportImage += Raise.Event();
fileHandler.Received().WriteBytesToFile(Arg.Any<string>(), Arg.Any<Byte[]>());
}
[TestMethod]
public void ModifyImage_ShouldModify_Test()
{
var fileHandler = Substitute.For<IFileHandler>();
fileHandler.ReadAllLines(Arg.Any<string>()).Returns(Entries.vcfwithInternalPhoto);
var repo = Substitute.For<ContactRepository>(fileHandler);
@@ -230,14 +242,41 @@ namespace vCardEditor_Test
_ = new MainPresenter(view, repo);
var contact = repo.LoadContacts("aaa.vcf");
view.ExportImage += Raise.Event();
fileHandler.Received().WriteBytesToFile(Arg.Any<string>(), Arg.Any<Byte[]>());
view.ModifyImage += Raise.EventWith(new EventArg<string>(""));
Assert.AreEqual(0, contact[0].card.Photos.Count);
Assert.IsTrue(contact[0].isDirty);
}
[TestMethod]
public void Closeform_ShouldClose_Test()
{
var fileHandler = Substitute.For<IFileHandler>();
fileHandler.ReadAllLines(Arg.Any<string>()).Returns(Entries.vcfwithInternalPhoto);
var repo = Substitute.For<ContactRepository>(fileHandler);
var view = Substitute.For<IMainView>();
view.SelectedContactIndex.Returns(0);
view.AskMessage(Arg.Any<string>(), Arg.Any<string>()).Returns(true);
_ = new MainPresenter(view, repo);
_ = repo.LoadContacts("aaa.vcf");
view.CloseForm += Raise.EventWith(new EventArg<bool>(false));
ConfigRepository.Instance.Received();
}
/*
if (_repository.dirty && _view.AskMessage("Exit without saving?", "Exit"))
e.Data = true;
if (!e.Data)
{
var state = _view.GetFormState();
ConfigRepository.Instance.FormState = state;
ConfigRepository.Instance.SaveConfig();
}
*/
}
}