Skip to content

Commit

Permalink
Refactor the contact group related methods of ContactService into a n…
Browse files Browse the repository at this point in the history
…ew ContactGroupService.
  • Loading branch information
Ethan Young committed Jan 11, 2014
1 parent 6fd7c5a commit 510d9d3
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 89 deletions.
43 changes: 43 additions & 0 deletions Source/Core/ContactGroups/ContactGroupService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;

namespace EthanYoung.ContactRepository.ContactGroups
{
public class ContactGroupService : IContactGroupService
{
private readonly IContactGroupRepository _contactGroupRepository;

public ContactGroupService(IContactGroupRepository contactGroupRepository)
{
_contactGroupRepository = contactGroupRepository;
}

public void Save(IContactGroup contactGroup)
{
_contactGroupRepository.Save(contactGroup);
}

public List<IContactGroup> FindAll()
{
return _contactGroupRepository.FindAll();
}

public IContactGroup FindByIdentifier(Guid identifier)
{
return _contactGroupRepository.FindByIdentifier(identifier);
}

public void DeleteByIdentifier(Guid identifier)
{
_contactGroupRepository.DeleteByIdentifier(identifier);
}
}

public interface IContactGroupService : IService
{
void Save(IContactGroup contactGroup);
List<IContactGroup> FindAll();
IContactGroup FindByIdentifier(Guid identifier);
void DeleteByIdentifier(Guid identifier);
}
}
20 changes: 0 additions & 20 deletions Source/Core/Contacts/ContactService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,17 @@ namespace EthanYoung.ContactRepository.Contacts
public class ContactService : IContactService
{
private readonly IContactRepository _contactRepository;
private readonly IContactGroupRepository _contactGroupRepository;

public ContactService(IContactRepository contactRepository, IContactGroupRepository contactGroupRepository)
{
_contactRepository = contactRepository;
_contactGroupRepository = contactGroupRepository;
}

public void Save(IContact contact)
{
_contactRepository.Save(contact);
}

public void Save(IContactGroup contactGroup)
{
_contactGroupRepository.Save(contactGroup);
}

public List<IContact> FindAll()
{
return _contactRepository.FindAll();
Expand All @@ -35,30 +28,17 @@ public IContact FindByIdentifier(Guid identifier)
return _contactRepository.FindByIdentifier(identifier);
}

public IContactGroup FindContactGroupByIdentifier(Guid identifier)
{
return _contactGroupRepository.FindByIdentifier(identifier);
}

public void DeleteByIdentifier(Guid identifier)
{
_contactRepository.DeleteByIdentifier(identifier);
}

public void DeleteContactGroupByIdentifier(Guid identifier)
{
_contactGroupRepository.DeleteByIdentifier(identifier);
}
}

public interface IContactService : IService
{
void Save(IContact contact);
void Save(IContactGroup contactGroup);
IContact FindByIdentifier(Guid identifier);
IContactGroup FindContactGroupByIdentifier(Guid identifier);
List<IContact> FindAll();
void DeleteByIdentifier(Guid identifier);
void DeleteContactGroupByIdentifier(Guid identifier);
}
}
1 change: 1 addition & 0 deletions Source/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<Compile Include="Bootstrapping\Migrations\Migration201312071339_CreateContactsTable.cs" />
<Compile Include="Bootstrapping\Migrations\Migrator.cs" />
<Compile Include="ContactGroups\ContactGroup.cs" />
<Compile Include="ContactGroups\ContactGroupService.cs" />
<Compile Include="ContactGroups\IContactGroupRepository.cs" />
<Compile Include="Contacts\Contact.cs" />
<Compile Include="Contacts\ContactEmailAddress.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: Contact Service Can Perform CRUD Operations For Contact Groups
Feature: Contact Group Service Can Perform CRUD Operations
In order to organize my contacts
As a user
I want to be able to save and retrieve groups of contacts
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using EthanYoung.ContactRepository.ContactGroups;
using NUnit.Framework;
using TechTalk.SpecFlow;

namespace EthanYoung.ContactRepository.Tests.AcceptanceTests.ContactGroupService
{
[Binding]
public class ContactGroupServiceSteps
{
private readonly IContactGroupService _service = DependencyRegistry.Resolve<IContactGroupService>();

private IContactGroup _contactGroup;
private IContactGroup _retrievedContactGroup;

[BeforeScenario]
public void BeforeScenario()
{
_contactGroup = null;
_retrievedContactGroup = null;
}

[Given(@"I create a contact group")]
public void GivenICreateAContactGroup()
{
_contactGroup = new ContactGroup
{
Identifier = Guid.NewGuid(),
Name = "My Contacts"
};
}

[Given(@"I change the name of the contact group")]
public void GivenIChangeTheNameOfTheContactGroup()
{
_contactGroup.Name += " Updated";
}

[Given(@"I save the contact group")]
public void GivenISaveTheContactGroup()
{
_service.Save(_contactGroup);
}

[Given(@"I delete the contact group")]
public void GivenIDeleteTheContactGroup()
{
_service.DeleteByIdentifier(_contactGroup.Identifier);
}

[When(@"I retrieve the contact group")]
public void WhenIRetrieveTheContactGroup()
{
_retrievedContactGroup = _service.FindByIdentifier(_contactGroup.Identifier);
}

[Then(@"the retrieved contact group is null")]
public void ThenTheRetrievedContactGroupIsNull()
{
Assert.IsNull(_retrievedContactGroup);
}

[Then(@"the name of the retrieved contact group is equal to the name of the contact group")]
public void ThenTheNameOfTheRetrievedContactGroupIsEqualToTheNameOfTheContactGroup()
{
Assert.AreEqual(_contactGroup.Name, _retrievedContactGroup.Name);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: Contact Service Can Perform CRUD Operations For Contacts
Feature: Contact Service Can Perform CRUD Operations
In order to remember my contacts
As a user
I want to be able to save and retrieve a contact
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 0 additions & 50 deletions Source/Tests/AcceptanceTests/ContactService/ContactServiceSteps.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Linq;
using EthanYoung.ContactRepository.ContactGroups;
using EthanYoung.ContactRepository.Contacts;
using NUnit.Framework;
using TechTalk.SpecFlow;
Expand All @@ -15,9 +14,6 @@ public class ContactServiceSteps
private IContact _contact;
private IContact _retrievedContact;

private IContactGroup _contactGroup;
private IContactGroup _retrievedContactGroup;

[BeforeScenario]
public void BeforeScenario()
{
Expand All @@ -35,16 +31,6 @@ public void GivenICreateAContact()
};
}

[Given(@"I create a contact group")]
public void GivenICreateAContactGroup()
{
_contactGroup = new ContactGroup
{
Identifier = Guid.NewGuid(),
Name = "My Contacts"
};
}

[Given(@"I change the name of the contact")]
public void GivenIChangeTheNameOfTheContact()
{
Expand Down Expand Up @@ -99,72 +85,36 @@ public void GivenIClearThePhoneNumbersOfTheContact()
_contact.ClearPhoneNumbers();
}

[Given(@"I change the name of the contact group")]
public void GivenIChangeTheNameOfTheContactGroup()
{
_contactGroup.Name += " Updated";
}

[Given(@"I save the contact")]
public void GivenISaveTheContact()
{
_service.Save(_contact);
}

[Given(@"I save the contact group")]
public void GivenISaveTheContactGroup()
{
_service.Save(_contactGroup);
}

[Given(@"I delete the contact")]
public void GivenIDeleteTheContact()
{
_service.DeleteByIdentifier(_contact.Identifier);
}

[Given(@"I delete the contact group")]
public void GivenIDeleteTheContactGroup()
{
_service.DeleteContactGroupByIdentifier(_contactGroup.Identifier);
}

[When(@"I retrieve the contact")]
public void WhenIRetrieveTheContact()
{
_retrievedContact = _service.FindByIdentifier(_contact.Identifier);
}

[When(@"I retrieve the contact group")]
public void WhenIRetrieveTheContactGroup()
{
_retrievedContactGroup = _service.FindContactGroupByIdentifier(_contactGroup.Identifier);
}

[Then(@"the retrieved contact is null")]
public void ThenTheRetrievedContactIsNull()
{
Assert.IsNull(_retrievedContact);
}

[Then(@"the retrieved contact group is null")]
public void ThenTheRetrievedContactGroupIsNull()
{
Assert.IsNull(_retrievedContactGroup);
}

[Then(@"the name of the retrieved contact is equal to the name of the contact")]
public void ThenTheNameOfTheRetrievedContactIsEqualToTheNameOfTheContact()
{
Assert.AreEqual(_contact.Name, _retrievedContact.Name);
}

[Then(@"the name of the retrieved contact group is equal to the name of the contact group")]
public void ThenTheNameOfTheRetrievedContactGroupIsEqualToTheNameOfTheContactGroup()
{
Assert.AreEqual(_contactGroup.Name, _retrievedContactGroup.Name);
}

[Then(@"the contact has (.*) email address")]
[Then(@"the contact has (.*) email addresses")]
public void ThenTheContactHasCountEmailAddress(int count)
Expand Down
Loading

0 comments on commit 510d9d3

Please sign in to comment.