Skip to content

Commit

Permalink
Add base search parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
richardrandak committed Oct 21, 2020
1 parent a8e8121 commit 60efe53
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
17 changes: 17 additions & 0 deletions FortnoxAPILibrary.Tests/ConnectorTests/InvoiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,22 @@ public void Test_Email()
new ArticleConnector().Delete(tmpArticle.ArticleNumber);
#endregion Delete arranged resources
}

[TestMethod]
public void Test_Search()
{
var connector = new InvoiceConnector();
connector.FromDate = new DateTime(2020,10, 10);
connector.ToDate = new DateTime(2020, 10, 15);

var result = connector.Find();

Assert.IsTrue(result.Entities.Count > 0);
foreach (var invoice in result.Entities)
{
Assert.IsTrue(invoice.InvoiceDate >= connector.FromDate);
Assert.IsTrue(invoice.InvoiceDate <= connector.ToDate);
}
}
}
}
2 changes: 1 addition & 1 deletion FortnoxAPILibrary.Tests/ReportedIssuesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void Test_issue51_fixed() //Origins from https://github.com/FortnoxAB/csh

//Act & Assert
var connector = new VoucherConnector();
connector.FinancialYearID = "1";
connector.FinancialYearID = 1;

connector.Limit = 2;
var voucherResult = connector.Find();
Expand Down
14 changes: 0 additions & 14 deletions FortnoxAPILibrary/Connectors/VoucherConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@ public class VoucherConnector : EntityConnector<Voucher, EntityCollection<Vouche
[SearchParameter("filter")]
public Filter.Voucher? FilterBy { get; set; }

/// <summary>
/// <para>Use FinancialYearDate to select the financial year to use.</para>
/// <para>If omitted the default financial year will be selected</para>
/// </summary>
[SearchParameter("financialyeardate")]
public string FinancialYearDate { get; set; }

/// <summary>
/// <para>Use FinancialYearID to select the financial year to use.</para>
/// <para>If omitted the default financial year will be selected</para>
/// </summary>
[SearchParameter("financialyear")]
public string FinancialYearID { get; set; }

/// <summary>
/// Use with Find() to limit the search result
/// </summary>
Expand Down
33 changes: 32 additions & 1 deletion FortnoxAPILibrary/EntityConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ public abstract class EntityConnector<TEntity, TEntityCollection, TSort> : BaseC
/// </summary>
[SearchParameter]
public DateTime? LastModified { get; set; }
/// <summary>
/// Use with Find() to limit the search result.
/// Selects which financial year should be used.
/// </summary>
[SearchParameter("financialyear")]
public long? FinancialYearID { get; set; }
/// <summary>
/// Use with Find() to limit the search result.
/// Selects which financial year should be used by date
/// </summary>
[SearchParameter]
public DateTime? FinancialYearDate { get; set; }
/// <summary>
/// Use with Find() to limit the search result.
/// Defines a selection based on a start date.
/// Only available for invoices, orders, offers and vouchers
/// </summary>
[SearchParameter]
public DateTime? FromDate { get; set; }
/// <summary>
/// Use with Find() to limit the search result.
/// Defines a selection based on an end date.
/// Only available for invoices, orders, offers and vouchers
/// </summary>
[SearchParameter]
public DateTime? ToDate { get; set; }

/// <summary>
/// Use with Find() to limit the search result
Expand Down Expand Up @@ -166,7 +192,12 @@ private static string GetStringValue(object value, Type type)
if (type.IsEnum)
return ((Enum)value).GetStringValue();
if (type == typeof(DateTime))
return ((DateTime)value).ToString(APIConstants.DateAndTimeFormat);
{
if (((DateTime)value).Date == (DateTime)value) //Date without hours/minutes/seconds..
return ((DateTime)value).ToString(APIConstants.DateFormat);

return ((DateTime) value).ToString(APIConstants.DateAndTimeFormat);
}

return value.ToString().ToLower();
}
Expand Down
7 changes: 6 additions & 1 deletion FortnoxAPILibrary/Interfaces/IConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ public interface IConnector : IBaseConnector //TODO: Rename to IResourceConnecto
public interface IEntityConnector : IConnector
{
//Base search params
int? Limit { get; set; }
DateTime? LastModified { get; set; }
public long? FinancialYearID { get; set; }
public DateTime? FinancialYearDate { get; set; }
public DateTime? FromDate { get; set; }
public DateTime? ToDate { get; set; }

int? Page { get; set; }
int? Offset { get; set; }
int? Limit { get; set; }
}
}

0 comments on commit 60efe53

Please sign in to comment.