Skip to content

Commit

Permalink
Add 'Description' search property for ProjectConnector
Browse files Browse the repository at this point in the history
  • Loading branch information
richardrandak committed Oct 1, 2020
1 parent 350030f commit a1c1d07
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
56 changes: 56 additions & 0 deletions FortnoxAPILibrary.Tests/ConnectorTests/ProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,61 @@ public void Test_Find()
//Add code to delete temporary resources
#endregion Delete arranged resources
}

[TestMethod]
public void Test_Find_By_Description()
{
#region Arrange
//Add code to create required resources
#endregion Arrange

IProjectConnector connector = new ProjectConnector();
var existingEntries = connector.Find().Entities.Count;
var description = TestUtils.RandomString();

var newProject = new Project()
{
Description = description,
Status = Status.Ongoing,
StartDate = new DateTime(2019, 10, 10),
EndDate = new DateTime(2021, 10, 10),
ProjectLeader = "TestProjectLeader",
ContactPerson = "TestContactPerson",
Comments = "TestComments"
};

//Add entries
for (var i = 0; i < 5; i++)
connector.Create(newProject);
var otherDescription = TestUtils.RandomString();
newProject.Description = otherDescription;
for (var i = 0; i < 5; i++)
connector.Create(newProject);

var fullCollection = connector.Find();
MyAssert.HasNoError(connector);

Assert.AreEqual(existingEntries + 5 + 5, fullCollection.Entities.Count);
Assert.AreEqual(5, fullCollection.Entities.Count(e => e.Description == description));
Assert.AreEqual(5, fullCollection.Entities.Count(e => e.Description == otherDescription));

//Apply filter
connector.Description = otherDescription;
var filteredCollection = connector.Find();
MyAssert.HasNoError(connector);

Assert.AreEqual(5, filteredCollection.TotalResources);
Assert.AreEqual(5, filteredCollection.Entities.Count);

//Delete entries
foreach (var entry in fullCollection.Entities)
{
connector.Delete(entry.ProjectNumber);
}

#region Delete arranged resources
//Add code to delete temporary resources
#endregion Delete arranged resources
}
}
}
7 changes: 6 additions & 1 deletion FortnoxAPILibrary/Connectors/ProjectConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ public class ProjectConnector : EntityConnector<Project, EntityCollection<Projec
[SearchParameter("filter")]
public Filter.Project? FilterBy { get; set; }

/// <summary>
/// Use with Find() to limit the search result
/// </summary>
[SearchParameter("description")]
public string Description { get; set; }

/// <remarks/>
/// <remarks/>
public ProjectConnector()
{
Resource = "projects";
Expand Down
1 change: 1 addition & 0 deletions FortnoxAPILibrary/Interfaces/IProjectConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IProjectConnector : IEntityConnector
Sort.By.Project? SortBy { get; set; }
Filter.Project? FilterBy { get; set; }

string Description { get; set; }

Project Update(Project project);
Project Create(Project project);
Expand Down

0 comments on commit a1c1d07

Please sign in to comment.