mirror of
https://github.com/abdelkader/vCardEditor
synced 2025-12-12 08:27:19 +07:00
added autofixture et other tests
This commit is contained in:
@@ -184,5 +184,20 @@
|
||||
|
||||
}
|
||||
|
||||
public static string[] vcfOneEntryWithTwoAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
string s = @"BEGIN:VCARD\n" +
|
||||
"VERSION:2.1\n" +
|
||||
"FN:Jean Dupont1\n" +
|
||||
"N:Dupont;Jean\n" +
|
||||
"ADR;WORK;PREF;QUOTED-PRINTABLE:;Bruxelles 1200=Belgique;6A Rue Th. Decuyper\n" +
|
||||
"ADR;Home;PREF;QUOTED-PRINTABLE:;Bruxelles 1200=Belgique;6A Rue Th. Decuyper\n" +
|
||||
"END:VCARD";
|
||||
return s.Split('\n');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ using vCardEditor.Repository;
|
||||
using NSubstitute;
|
||||
using vCardEditor.View;
|
||||
using System;
|
||||
using AutoFixture;
|
||||
using Thought.vCards;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace vCardEditor_Test
|
||||
{
|
||||
@@ -149,6 +152,72 @@ namespace vCardEditor_Test
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddressRemovedEvent_ShouldRemove()
|
||||
{
|
||||
|
||||
var fileHandler = Substitute.For<IFileHandler>();
|
||||
fileHandler.ReadAllLines(Arg.Any<string>()).Returns(Entries.vcfOneEntryWithTwoAddress);
|
||||
var repo = Substitute.For<ContactRepository>(fileHandler);
|
||||
var view = Substitute.For<IMainView>();
|
||||
view.SelectedContactIndex.Returns(0);
|
||||
_ = 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]
|
||||
public void AddressAddedEvent_ShouldAddAddress()
|
||||
{
|
||||
|
||||
var fileHandler = Substitute.For<IFileHandler>();
|
||||
fileHandler.ReadAllLines(Arg.Any<string>()).Returns(Entries.vcfOneEntryWithTwoAddress);
|
||||
var repo = Substitute.For<ContactRepository>(fileHandler);
|
||||
var view = Substitute.For<IMainView>();
|
||||
view.SelectedContactIndex.Returns(0);
|
||||
_ = new MainPresenter(view, repo);
|
||||
var contact = repo.LoadContacts("aaa.vcf");
|
||||
|
||||
var fixture = new Fixture { RepeatCount = 2 };
|
||||
var lstvCardDeliveryAddressTypes = fixture.Create <List<vCardDeliveryAddressTypes>>();
|
||||
|
||||
view.AddressAdded += Raise.EventWith(new EventArg<List<vCardDeliveryAddressTypes>>(lstvCardDeliveryAddressTypes));
|
||||
|
||||
Assert.AreEqual(2 + 1, contact[0].card.DeliveryAddresses.Count);
|
||||
Assert.AreEqual(2, contact[0].card.DeliveryAddresses[2].AddressType.Count);
|
||||
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddressModifiedEvent_ShouldModifyAddress()
|
||||
{
|
||||
|
||||
var fileHandler = Substitute.For<IFileHandler>();
|
||||
fileHandler.ReadAllLines(Arg.Any<string>()).Returns(Entries.vcfOneEntryWithTwoAddress);
|
||||
var repo = Substitute.For<ContactRepository>(fileHandler);
|
||||
var view = Substitute.For<IMainView>();
|
||||
view.SelectedContactIndex.Returns(0);
|
||||
_ = new MainPresenter(view, repo);
|
||||
var contact = repo.LoadContacts("aaa.vcf");
|
||||
|
||||
var fixture = new Fixture { RepeatCount = 2 };
|
||||
var lstvCardDeliveryAddressTypes = fixture.Create<List<vCardDeliveryAddressTypes>>();
|
||||
|
||||
view.AddressModified += Raise.EventWith(new EventArg<List<vCardDeliveryAddressTypes>>(lstvCardDeliveryAddressTypes));
|
||||
|
||||
Assert.AreEqual(1, contact[0].card.DeliveryAddresses.Count);
|
||||
Assert.AreEqual(2, contact[0].card.DeliveryAddresses[0].AddressType.Count);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
15
vCardEditor_Test/app.config
Normal file
15
vCardEditor_Test/app.config
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AutoFixture" version="4.18.0" targetFramework="net481" />
|
||||
<package id="Castle.Core" version="5.1.1" targetFramework="net481" />
|
||||
<package id="Fare" version="2.1.1" targetFramework="net481" />
|
||||
<package id="NSubstitute" version="5.0.0" targetFramework="net481" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net481" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net481" />
|
||||
|
||||
@@ -36,15 +36,22 @@
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="AutoFixture, Version=4.18.0.0, Culture=neutral, PublicKeyToken=b24654c590009d4f, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\AutoFixture.4.18.0\lib\net452\AutoFixture.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Castle.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Castle.Core.5.1.1\lib\net462\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Fare, Version=2.1.0.0, Culture=neutral, PublicKeyToken=ea68d375bf33a7c8, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Fare.2.1.1\lib\net35\Fare.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
<Reference Include="NSubstitute, Version=5.0.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NSubstitute.5.0.0\lib\net462\NSubstitute.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
@@ -82,6 +89,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
Reference in New Issue
Block a user