Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit af435d5

Browse files
committed
Finalising history and notes
1 parent 72b99fd commit af435d5

5 files changed

Lines changed: 30 additions & 48 deletions

File tree

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using NUnit.Framework;
1+
using NUnit.Framework;
32

43
namespace CoreTests.Integration.HistoryAndNotes
54
{
@@ -8,28 +7,15 @@ public class CreateNotes : HistoryAndNotesTest
87
[Test]
98
public void Can_create_notes()
109
{
11-
var date = DateTime.UtcNow;
1210
const string details = "Details";
1311

1412
Given_a_contact();
1513

16-
Given_a_note_with_this_date_and_details(date, details);
14+
Given_a_note_with_these_details(details);
1715

1816
When_I_retrieve_history_and_notes_for_the_contact();
1917

20-
Then_there_is_a_note_with_the_correct_details(date, details);
21-
}
22-
23-
[Test]
24-
public void Validation_errors_are_as_expected()
25-
{
26-
Given_a_contact();
27-
28-
Given_a_note_with_this_date_and_details(new DateTime(1000, 1, 1), "Details");
29-
30-
When_I_retrieve_history_and_notes_for_the_contact();
31-
32-
Then_there_is_this_validation_error("sad");
18+
Then_there_is_a_note_with_the_correct_details(details);
3319
}
3420
}
3521
}

CoreTests/Integration/HistoryAndNotes/HistoryAndNotesTest.cs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,26 @@
44
using NUnit.Framework;
55
using Xero.Api.Core.Model;
66
using Xero.Api.Core.Model.Types;
7-
using Xero.Api.Infrastructure.Exceptions;
87

98
namespace CoreTests.Integration.HistoryAndNotes
109
{
1110
public class HistoryAndNotesTest : ApiWrapperTest
1211
{
1312
private Contact _contact;
1413
private IEnumerable<HistoryRecord> _historyRecords;
15-
private ValidationException _exception;
16-
14+
1715
protected void Given_a_contact()
1816
{
1917
_contact = Api.Contacts.Create(new Contact { Name = Guid.NewGuid().ToString() });
2018
}
2119

22-
protected void Given_a_note_with_this_date_and_details(DateTime date, string details)
20+
protected void Given_a_note_with_these_details(string details)
2321
{
24-
try
25-
{
26-
Api.HistoryAndNotes.CreateNote(HistoryAndNotesEndpointCreateType.Contacts, _contact.Id,
27-
new HistoryRecord
28-
{
29-
DateUtc = date,
30-
Details = details
31-
});
32-
}
33-
catch (ValidationException e)
34-
{
35-
_exception = e;
36-
}
22+
Api.HistoryAndNotes.CreateNote(HistoryAndNotesEndpointCreateType.Contacts, _contact.Id,
23+
new HistoryRecord
24+
{
25+
Details = details
26+
});
3727
}
3828

3929
protected void When_I_retrieve_history_and_notes_for_the_contact()
@@ -46,14 +36,9 @@ protected void Then_there_are_some_history_records()
4636
Assert.True(_historyRecords.Any(), "Expected some history records to be returned, but there were none");
4737
}
4838

49-
protected void Then_there_is_a_note_with_the_correct_details(DateTime date, string details)
50-
{
51-
Assert.True(_historyRecords.Any(it => it.DateUtc.Date.Equals(date.Date) && it.Details == details), "Expected a note with the expected details to be retunred but it was not");
52-
}
53-
54-
protected void Then_there_is_this_validation_error(string expectedError)
39+
protected void Then_there_is_a_note_with_the_correct_details(string details)
5540
{
56-
Assert.Contains(expectedError, _exception.ValidationErrors.Select(it => it.Message).ToList());
41+
Assert.True(_historyRecords.Any(it => it.Details == details), "Expected a note with the expected details to be returned but it was not");
5742
}
5843
}
5944
}

Xero.Api/Core/Endpoints/HistoryAndNotesEndpoint.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Net;
45
using Xero.Api.Core.Model;
56
using Xero.Api.Core.Model.Types;
7+
using Xero.Api.Core.Request;
68
using Xero.Api.Core.Response;
79
using Xero.Api.Infrastructure.Http;
810

@@ -11,7 +13,7 @@ namespace Xero.Api.Core.Endpoints
1113
public interface IHistoryAndNotesEndpoint
1214
{
1315
IEnumerable<HistoryRecord> Find(HistoryAndNotesEndpointRetrieveType type, Guid parent);
14-
void CreateNote(HistoryAndNotesEndpointCreateType type, Guid parent, HistoryRecord note);
16+
HistoryRecord CreateNote(HistoryAndNotesEndpointCreateType type, Guid parent, HistoryRecord note);
1517
}
1618

1719
public class HistoryAndNotesEndpoint : IHistoryAndNotesEndpoint
@@ -28,14 +30,11 @@ public IEnumerable<HistoryRecord> Find(HistoryAndNotesEndpointRetrieveType type,
2830
return Client.Get<HistoryRecord, HistoryRecordsResponse>(string.Format("api.xro/2.0/{0}/{1:D}/history", type, parent));
2931
}
3032

31-
public void CreateNote(HistoryAndNotesEndpointCreateType type, Guid parent, HistoryRecord note)
33+
public HistoryRecord CreateNote(HistoryAndNotesEndpointCreateType type, Guid parent, HistoryRecord note)
3234
{
33-
var response = Client.Client.Put(string.Format("api.xro/2.0/{0}/{1:D}/history", type, parent), Client.XmlMapper.To(new List<HistoryRecord>{note}));
35+
var request = new HistoryRecordsRequest {note};
3436

35-
if (response.StatusCode != HttpStatusCode.OK)
36-
{
37-
Client.HandleErrors(response);
38-
}
37+
return Client.Put<HistoryRecord, HistoryRecordsResponse>(string.Format("api.xro/2.0/{0}/{1:D}/history", type, parent), request).FirstOrDefault();
3938
}
4039
}
4140
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Runtime.Serialization;
2+
using Xero.Api.Common;
3+
using Xero.Api.Core.Model;
4+
5+
namespace Xero.Api.Core.Request
6+
{
7+
[CollectionDataContract(Namespace = "", Name = "HistoryRecords")]
8+
public class HistoryRecordsRequest : XeroRequest<HistoryRecord>
9+
{
10+
}
11+
}

Xero.Api/Xero.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<Compile Include="Core\Model\Types\ObjectType.cs" />
8181
<Compile Include="Core\Model\Types\SourceType.cs" />
8282
<Compile Include="Core\Request\CurrenciesRequest.cs" />
83+
<Compile Include="Core\Request\HistoryRecordsRequest.cs" />
8384
<Compile Include="Core\Request\LinkedTransactionsRequest.cs" />
8485
<Compile Include="Core\Request\OnlineInvoicesRequest.cs" />
8586
<Compile Include="Core\Request\PurchaseOrdersRequest.cs" />

0 commit comments

Comments
 (0)