mirror of
https://github.com/abdelkader/vCardEditor
synced 2025-12-12 08:27:19 +07:00
Corrected some tests
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
# vCard Editor
|
||||
A Simple vcf file Editor.
|
||||
A Simple vcf file Editor. You can export easily edit (modify, delete) entries of a vcf file with this simple tool.
|
||||
|
||||

|
||||
|
||||
- You can export easily edit (modify, delete) entries of a vcf file with this simple tool.
|
||||
|
||||
Thanks for Thought.vCards for his wonderful library of parsing and generating vcf format.
|
||||
https://github.com/drlongnecker/Thought.vCards
|
||||
@@ -12,6 +11,10 @@ Also, I used the MVP pattern from this example :
|
||||
https://github.com/lennykean/NoteCards
|
||||
|
||||
Relase note:
|
||||
*0.3*
|
||||
- refactoring and bugs fixed
|
||||
|
||||
|
||||
*0.2*
|
||||
- Updated the vCard library to https://github.com/acastroy/Thought.vCards
|
||||
- Replaced Moq with nsubstitute (Test mocking library).
|
||||
|
||||
@@ -31,12 +31,9 @@ namespace VCFEditor.Presenter
|
||||
_view.BeforeLeavingContact += BeforeLeavingContact;
|
||||
_view.CloseForm += CloseForm;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void CloseForm(object sender, EventArg<bool> e)
|
||||
{
|
||||
if (_repository.dirty && _view.AskMessage("Exit before saving?", "Exit"))
|
||||
@@ -87,22 +84,24 @@ namespace VCFEditor.Presenter
|
||||
|
||||
}
|
||||
|
||||
public void NewFileOpened(object sender, EventArgs e)
|
||||
public void NewFileOpened(object sender, EventArg<string> e)
|
||||
{
|
||||
|
||||
BeforeOpeningNewFile(sender, e);
|
||||
|
||||
string path = _view.DisplayOpenDialog();
|
||||
string ext = System.IO.Path.GetExtension(path);
|
||||
if (ext != ".vcf")
|
||||
{
|
||||
_view.DisplayMessage("Only vcf extension accepted!", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
string path = e.Data;
|
||||
if (string.IsNullOrEmpty(path))
|
||||
path = _view.DisplayOpenDialog();
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
string ext = System.IO.Path.GetExtension(path);
|
||||
if (ext != ".vcf")
|
||||
{
|
||||
_view.DisplayMessage("Only vcf extension accepted!", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
FixedList MRUList = ConfigRepository.Instance.Paths;
|
||||
if (!MRUList.Contains(path))
|
||||
{
|
||||
@@ -110,8 +109,6 @@ namespace VCFEditor.Presenter
|
||||
_view.UpdateMRUMenu(MRUList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
_repository.LoadContacts(path);
|
||||
_view.DisplayContacts(_repository.Contacts);
|
||||
}
|
||||
@@ -119,6 +116,7 @@ namespace VCFEditor.Presenter
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void ChangeContactSelected(object sender, EventArgs e)
|
||||
{
|
||||
if (_view.SelectedContactIndex > -1)
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace VCFEditor.View
|
||||
event EventHandler DeleteContact;
|
||||
event EventHandler BeforeOpeningNewFile;
|
||||
event EventHandler SaveContactsSelected;
|
||||
event EventHandler NewFileOpened;
|
||||
event EventHandler<EventArg<string>> NewFileOpened;
|
||||
event EventHandler ChangeContactsSelected;
|
||||
event EventHandler<EventArg<vCard>> BeforeLeavingContact;
|
||||
event EventHandler<EventArg<string>> FilterTextChanged;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace vCardEditor.View
|
||||
public event EventHandler SaveContactsSelected;
|
||||
public event EventHandler BeforeOpeningNewFile;
|
||||
public event EventHandler DeleteContact;
|
||||
public event EventHandler NewFileOpened;
|
||||
public event EventHandler<EventArg<string>> NewFileOpened;
|
||||
public event EventHandler ChangeContactsSelected;
|
||||
public event EventHandler<EventArg<vCard>> BeforeLeavingContact;
|
||||
public event EventHandler<EventArg<string>> FilterTextChanged;
|
||||
@@ -50,11 +50,8 @@ namespace vCardEditor.View
|
||||
|
||||
private void tbsOpen_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (NewFileOpened != null)
|
||||
NewFileOpened(sender, e);
|
||||
|
||||
|
||||
NewFileOpened(sender, new EventArg<string>(string.Empty));
|
||||
}
|
||||
|
||||
|
||||
@@ -255,8 +252,8 @@ namespace vCardEditor.View
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO: Correct this
|
||||
//OpenNewFile(sender, FileList[0]);
|
||||
|
||||
NewFileOpened(sender, new EventArg<string>(FileList[0]));
|
||||
|
||||
}
|
||||
#endregion
|
||||
@@ -265,9 +262,7 @@ namespace vCardEditor.View
|
||||
|
||||
private void BuildMRUMenu()
|
||||
{
|
||||
//TODO: Correct this
|
||||
//recentFilesMenuItem.DropDownItemClicked += (s, e) => OpenNewFile(s, e.ClickedItem.Text);
|
||||
|
||||
recentFilesMenuItem.DropDownItemClicked += (s, e) => NewFileOpened(s, new EventArg<string>(e.ClickedItem.Text));
|
||||
//Update the MRU Menu entries..
|
||||
UpdateMRUMenu(ConfigRepository.Instance.Paths);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace vCardEditor_Test
|
||||
public class MainPresenterTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void NewFileOpened_OpenNewFile_Test()
|
||||
public void NewFileOpened_OpenInvalidExtension_Test()
|
||||
{
|
||||
|
||||
var fileHandler = Substitute.For<IFileHandler>();
|
||||
@@ -30,6 +30,23 @@ namespace vCardEditor_Test
|
||||
var presenter = new MainPresenter(view, repo);
|
||||
view.NewFileOpened += Raise.EventWith(new EventArg<string>("aaa"));
|
||||
|
||||
view.Received().DisplayMessage(Arg.Any<string>(), Arg.Any<string>());
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void NewFileOpened_OpenNewFile_Test()
|
||||
{
|
||||
|
||||
var fileHandler = Substitute.For<IFileHandler>();
|
||||
fileHandler.ReadAllLines(Arg.Any<string>()).Returns(Entries.vcfOneEntry);
|
||||
var repo = Substitute.For<ContactRepository>(fileHandler);
|
||||
var view = Substitute.For<IMainView>();
|
||||
|
||||
|
||||
var presenter = new MainPresenter(view, repo);
|
||||
view.NewFileOpened += Raise.EventWith(new EventArg<string>("aaa.vcf"));
|
||||
|
||||
view.Received().DisplayContacts(Arg.Is<BindingList<Contact>>(x=>x.Count == 1));
|
||||
view.Received().DisplayContacts(Arg.Is<BindingList<Contact>>(x => x[0].card.FormattedName == "Jean Dupont1"));
|
||||
|
||||
@@ -44,13 +61,13 @@ namespace vCardEditor_Test
|
||||
fileHandler.ReadAllLines(Arg.Any<string>()).Returns(Entries.vcfThreeEntry);
|
||||
var repo = Substitute.For<ContactRepository>(fileHandler);
|
||||
var view = Substitute.For<IMainView>();
|
||||
|
||||
view.AskMessage(Arg.Any<string>(), Arg.Any<string>()).Returns(true);
|
||||
|
||||
var presenter = new MainPresenter(view, repo);
|
||||
view.NewFileOpened += Raise.EventWith(new EventArg<string>("aaa"));
|
||||
view.NewFileOpened += Raise.EventWith(new EventArg<string>("aaa.vcf"));
|
||||
repo.Contacts[1].isDirty = true;
|
||||
|
||||
view.NewFileOpened += Raise.EventWith(new EventArg<string>("aaa"));
|
||||
view.NewFileOpened += Raise.EventWith(new EventArg<string>("bbb.vcf"));
|
||||
|
||||
view.Received().AskMessage(Arg.Any<string>(), Arg.Any<string>());
|
||||
|
||||
@@ -67,7 +84,7 @@ namespace vCardEditor_Test
|
||||
|
||||
|
||||
var presenter = new MainPresenter(view, repo);
|
||||
view.NewFileOpened += Raise.EventWith(new EventArg<string>("aaa"));
|
||||
view.NewFileOpened += Raise.EventWith(new EventArg<string>("aaa.vcf"));
|
||||
|
||||
//Mouse click on second row.
|
||||
repo.Contacts[1].isSelected = true;
|
||||
@@ -82,5 +99,7 @@ namespace vCardEditor_Test
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user