From a1c1d07800e2fcc2a16b2e479399332695925262 Mon Sep 17 00:00:00 2001 From: Richard Randak Date: Thu, 1 Oct 2020 16:23:59 +0200 Subject: [PATCH] Add 'Description' search property for ProjectConnector --- .../ConnectorTests/ProjectTests.cs | 56 +++++++++++++++++++ .../Connectors/ProjectConnector.cs | 7 ++- .../Interfaces/IProjectConnector.cs | 1 + 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/FortnoxAPILibrary.Tests/ConnectorTests/ProjectTests.cs b/FortnoxAPILibrary.Tests/ConnectorTests/ProjectTests.cs index 6e7da4a3..e309e898 100644 --- a/FortnoxAPILibrary.Tests/ConnectorTests/ProjectTests.cs +++ b/FortnoxAPILibrary.Tests/ConnectorTests/ProjectTests.cs @@ -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 + } } } diff --git a/FortnoxAPILibrary/Connectors/ProjectConnector.cs b/FortnoxAPILibrary/Connectors/ProjectConnector.cs index 624beb2a..3dda17b4 100644 --- a/FortnoxAPILibrary/Connectors/ProjectConnector.cs +++ b/FortnoxAPILibrary/Connectors/ProjectConnector.cs @@ -15,8 +15,13 @@ public class ProjectConnector : EntityConnector + /// Use with Find() to limit the search result + /// + [SearchParameter("description")] + public string Description { get; set; } - /// + /// public ProjectConnector() { Resource = "projects"; diff --git a/FortnoxAPILibrary/Interfaces/IProjectConnector.cs b/FortnoxAPILibrary/Interfaces/IProjectConnector.cs index 40368b73..96a7ae42 100644 --- a/FortnoxAPILibrary/Interfaces/IProjectConnector.cs +++ b/FortnoxAPILibrary/Interfaces/IProjectConnector.cs @@ -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);