Permalink
Browse files

added/updates Api test to include InMemory Api's

  • Loading branch information...
1 parent 66b8598 commit 0460b868d3397a40a77ed0f11e042e831e2d5974 Matheu committed Jan 17, 2012
View
11 DotNet/src/JustGiving.Api.Sdk.1.2.dotCover
@@ -0,0 +1,11 @@
+<Configuration>
+ <SnapshotDialog>
+ <InitialDirectory>D:\JustGiving\JustGiving.Api.Sdk\DotNet\src</InitialDirectory>
+ </SnapshotDialog>
+ <CoverageFilters>
+ <IncludeFilters>
+ <Filter ModuleMask="*" ClassMask="*" FunctionMask="*" />
+ </IncludeFilters>
+ <ExcludeFilters />
+ </CoverageFilters>
+</Configuration>
View
36 DotNet/src/JustGiving.Api.Sdk.Test.Integration/ApiClients/InMemoryApiTests.cs
@@ -0,0 +1,36 @@
+using JustGiving.Api.Sdk.ApiClients;
+using NUnit.Framework;
+
+namespace JustGiving.Api.Sdk.Test.Integration.ApiClients
+{
+ [TestFixture]
+ public class InMemoryApiTests
+ {
+ [TestCase(WireDataFormat.Json)]
+ [TestCase(WireDataFormat.Xml)]
+ public void GetRememberPerson_WhenProvidedWithValidPersonId_ReturnsRememberPersonDetails(WireDataFormat format)
+ {
+ var client = TestContext.CreateClientValidCredentials(format);
+ var inMemoryClient = new InMemoryApi(client.HttpChannel);
+ int rememberPersonId = 21;
+
+ var response = inMemoryClient.Retrieve(rememberPersonId);
+
+ Assert.AreEqual(response.RememberedPerson.Id, rememberPersonId);
+ Assert.That(response.CollectionUri, Is.StringContaining(string.Format("remember/{0}/", response.RememberedPerson.Id)));
+ }
+
+ [TestCase(WireDataFormat.Json)]
+ [TestCase(WireDataFormat.Xml)]
+ public void GetRememberPersonCollectionData_WhenProvidedWithValidPersonId_ReturnsRememberPersonCollectionData(WireDataFormat format)
+ {
+ var client = TestContext.CreateClientValidCredentials(format);
+ var inMemoryClient = new InMemoryApi(client.HttpChannel);
+ int rememberPersonId = 21;
+
+ var retrieveCollectionData = inMemoryClient.RetrieveCollectionData(rememberPersonId);
+
+ Assert.Greater(retrieveCollectionData.Pages.Length, 0);
+ }
+ }
+}
View
59 DotNet/src/JustGiving.Api.Sdk.Test.Integration/ApiClients/PageApiTests.cs
@@ -255,13 +255,6 @@ public void RetrievePage_WhenProvidedWithAKnownPage_ReturnsPublicPageView(WireDa
Assert.AreEqual(pageData.PageTitle, pageCreationRequest.PageTitle);
Assert.AreEqual(pageData.EventName, pageCreationRequest.EventName);
Assert.AreEqual(pageData.TargetAmount, pageCreationRequest.TargetAmount);
- Assert.That(pageData.CustomCodes, Is.Not.Null);
- Assert.That(pageData.CustomCodes.CustomCode1, Is.StringMatching("code1"));
- Assert.That(pageData.CustomCodes.CustomCode2, Is.StringMatching("code2"));
- Assert.That(pageData.CustomCodes.CustomCode3, Is.StringMatching("code3"));
- Assert.That(pageData.CustomCodes.CustomCode4, Is.StringMatching("code4"));
- Assert.That(pageData.CustomCodes.CustomCode5, Is.StringMatching("code5"));
- Assert.That(pageData.CustomCodes.CustomCode6, Is.StringMatching("code6"));
Assert.IsNotNullOrEmpty(pageData.SmsCode);
}
@@ -635,7 +628,7 @@ public void Register_SuppliedValidAuthenticationAndValidRegisterPageRequestWithR
var pageClient = new PageApi(client.HttpChannel);
var pageShortName = "api-test-" + guid;
- var firstName = "FirstName";
+ var firstName = "FirstName-api-test";
var lastName = string.Format("Last-{0}", guid);
string inMemNameAttribution = String.Format("{0} {1}{2}", firstName, lastName, guid).Trim();
@@ -666,7 +659,55 @@ public void Register_SuppliedValidAuthenticationAndValidRegisterPageRequestWithR
FundraisingPage page = pageClient.Retrieve(pageShortName);
Assert.NotNull(page.RememberedPersonSummary.Name);
- Assert.That(page.RememberedPersonSummary.Uri, Is.StringContaining(string.Format("/remember/{0}", rememberedPersonReference.RememberedPerson.Id)));
+ Assert.That(page.RememberedPersonSummary.Next.Uri, Is.StringContaining(String.Format("remember/{0}", page.RememberedPersonSummary.Id)));
+ }
+
+ [TestCase(WireDataFormat.Json)]
+ [TestCase(WireDataFormat.Xml)]
+ public void Register_SuppliedValidAuthenticationAndValidRegisterPageRequestWithNewRememberedPersonDetails_CanRetrievePageWithRememberedPersonData(WireDataFormat format)
+ {
+ var guid = Guid.NewGuid();
+ var client = TestContext.CreateClientValidCredentials(format);
+ var pageClient = new PageApi(client.HttpChannel);
+ var pageShortName = "api-test-" + guid;
+
+ var firstName = "FirstName-api-test";
+ var lastName = string.Format("Last-{0}", guid);
+
+ string inMemNameAttribution = String.Format("{0} {1}{2}", firstName, lastName, guid).Trim();
+
+ var rememberedPersonReference = new RememberedPersonReference
+ {
+ Relationship = "Other",
+ RememberedPerson = new RememberedPerson
+ {
+ FirstName = firstName,
+ LastName = lastName,
+ Gender = 1,
+ Town = String.Format("town-{0}", guid),
+ DateOfBirth = DateTime.Now.AddYears(-50),
+ DateOfDeath = DateTime.Now.AddDays(-1),
+ }
+ };
+
+ var pageCreationRequest = new RegisterPageRequest
+ {
+ ActivityType = ActivityType.InMemory,
+ Attribution = inMemNameAttribution,
+ PageShortName = pageShortName,
+ PageTitle = "api test InMem Name",
+ EventName = "The InMem ApiTest",
+ CharityId = 2050,
+ TargetAmount = 20M,
+ EventDate = DateTime.Now.AddDays(5),
+ RememberedPersonReference = rememberedPersonReference,
+ };
+
+ pageClient.Create(pageCreationRequest);
+ FundraisingPage page = pageClient.Retrieve(pageShortName);
+
+ Assert.NotNull(page.RememberedPersonSummary.Name);
+ Assert.That(page.RememberedPersonSummary.Next.Uri, Is.StringContaining(String.Format("remember/{0}", page.RememberedPersonSummary.Id)));
}
}
}
View
1 DotNet/src/JustGiving.Api.Sdk.Test.Integration/JustGiving.Api.Sdk.Test.Integration.csproj
@@ -47,6 +47,7 @@
<ItemGroup>
<Compile Include="ApiClients\AccountApiTests.cs" />
<Compile Include="ApiClients\CharityApiTests.cs" />
+ <Compile Include="ApiClients\InMemoryApiTests.cs" />
<Compile Include="ApiClients\TeamApiTests.cs" />
<Compile Include="ApiClients\EventApiTests.cs" />
<Compile Include="ApiClients\DonationApiTests.cs" />
View
10 DotNet/src/JustGiving.Api.Sdk/ApiClients/IInMemoryApi.cs
@@ -0,0 +1,10 @@
+using JustGiving.Api.Sdk.Model.Remember;
+
+namespace JustGiving.Api.Sdk.ApiClients
+{
+ public interface IInMemoryApi: IInMemoryApiAsync
+ {
+ RememberedPersonResponse Retrieve(int rememberedPersonId);
+ RememberedPersonCollection RetrieveCollectionData(int rememberedPersonId);
+ }
+}
View
11 DotNet/src/JustGiving.Api.Sdk/ApiClients/IInMemoryApiAsync.cs
@@ -0,0 +1,11 @@
+using System;
+using JustGiving.Api.Sdk.Model.Remember;
+
+namespace JustGiving.Api.Sdk.ApiClients
+{
+ public interface IInMemoryApiAsync
+ {
+ void RetrieveAsync(int rememberedPersonId, Action<RememberedPersonResponse> callback);
+ void RetrieveCollectionDataAsync(int rememberedPersonId, Action<RememberedPersonResponse> callback);
+ }
+}
View
49 DotNet/src/JustGiving.Api.Sdk/ApiClients/InMemoryApi.cs
@@ -0,0 +1,49 @@
+using System;
+using JustGiving.Api.Sdk.Http;
+using JustGiving.Api.Sdk.Model.Remember;
+
+namespace JustGiving.Api.Sdk.ApiClients
+{
+ public class InMemoryApi: ApiClientBase, IInMemoryApi
+ {
+ public override string ResourceBase
+ {
+ get { return "{apiKey}/v{apiVersion}/remember"; }
+ }
+
+ public InMemoryApi(HttpChannel channel)
+ : base(channel)
+ {
+ }
+
+ public string RetrieveLocationFormat(int rememberedPersonId)
+ {
+ return ResourceBase + "/" + rememberedPersonId;
+ }
+
+ public RememberedPersonResponse Retrieve(int rememberedPersonId)
+ {
+ var locationFormat = RetrieveLocationFormat(rememberedPersonId) ;
+ return HttpChannel.PerformRequest<RememberedPersonResponse>("GET", locationFormat);
+ }
+
+ public void RetrieveAsync(int rememberedPersonId, Action<RememberedPersonResponse> callback)
+ {
+ var locationFormat = RetrieveLocationFormat(rememberedPersonId);
+ HttpChannel.PerformRequestAsync("GET", locationFormat, callback);
+ }
+
+ public RememberedPersonCollection RetrieveCollectionData(int rememberedPersonId)
+ {
+ var locationFormat = RetrieveLocationFormat(rememberedPersonId)+ "/collection";
+ return HttpChannel.PerformRequest<RememberedPersonCollection>("GET", locationFormat);
+ }
+
+ public void RetrieveCollectionDataAsync(int rememberedPersonId, Action<RememberedPersonResponse> callback)
+ {
+ var locationFormat = RetrieveLocationFormat(rememberedPersonId) + "/collection";
+ HttpChannel.PerformRequestAsync("GET", locationFormat, callback);
+ }
+
+ }
+}
View
5 DotNet/src/JustGiving.Api.Sdk/JustGiving.Api.Sdk.csproj
@@ -47,6 +47,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ApiClients\CharityApi.cs" />
+ <Compile Include="ApiClients\IInMemoryApiAsync.cs" />
+ <Compile Include="ApiClients\IInMemoryApi.cs" />
+ <Compile Include="ApiClients\InMemoryApi.cs" />
<Compile Include="ApiClients\ITeamApi.cs" />
<Compile Include="ApiClients\ITeamApiAsync.cs" />
<Compile Include="ApiClients\TeamApi.cs" />
@@ -131,12 +134,14 @@
<Compile Include="Model\Page\StoryUpdateRequest.cs" />
<Compile Include="Model\Page\StoryUpdateResponse.cs" />
<Compile Include="Model\Pagination.cs" />
+ <Compile Include="Model\Remember\RememberedPersonReference.cs" />
<Compile Include="Model\RestResponseNavigationElement.cs" />
<Compile Include="Model\RestResponseNextElement.cs" />
<Compile Include="Model\RestResponsePrevElement.cs" />
<Compile Include="Model\Search\CharitySearchResult.cs" />
<Compile Include="Model\Search\CharitySearchResults.cs" />
<Compile Include="Model\Search\RestResponseSugguestedQueryElement.cs" />
+ <Compile Include="Model\Summaries\Summaries.cs" />
<Compile Include="Model\Team\Team.cs" />
<Compile Include="Model\Team\TeamTargetType.cs" />
<Compile Include="Model\Team\TeamType.cs" />
View
3 DotNet/src/JustGiving.Api.Sdk/Model/Page/FundraisingPage.cs
@@ -1,5 +1,6 @@
using System;
using System.Runtime.Serialization;
+using JustGiving.Api.Sdk.Model.Remember;
namespace JustGiving.Api.Sdk.Model.Page
{
@@ -71,6 +72,8 @@ public class FundraisingPage
public string Attribution { get; set; }
[DataMember(Name="customCodes", EmitDefaultValue = false)]
public PageCustomCodes CustomCodes { get; set; }
+ [DataMember(Name = "rememberedPersonSummary", EmitDefaultValue = false)]
+ public RememberedPersonSummary RememberedPersonSummary { get; set; }
public FundraisingPage()
{
View
15 DotNet/src/JustGiving.Api.Sdk/Model/Page/RegisterPageRequest.cs
@@ -1,5 +1,6 @@
using System;
using System.Runtime.Serialization;
+using JustGiving.Api.Sdk.Model.Remember;
namespace JustGiving.Api.Sdk.Model.Page
{
@@ -61,11 +62,21 @@ public class RegisterPageRequest
[DataMember(Name = "companyAppealId")]
public int? CompanyAppealId { get; set; }
- [DataMember(Name = "theme")]
- public PageTheme Theme { get; set; }
+ //expiryDate is in GG.Api.Services.Dto.Fundraising.PageRegistration but is not here
+
+ //pageStory is in GG.Api.Services.Dto.Fundraising.PageRegistration but is not here
[DataMember(Name = "customCodes")]
public PageCustomCodes CustomCodes { get; set; }
+ [DataMember(Name = "theme")]
+ public PageTheme Theme { get; set; }
+
+ //images is in GG.Api.Services.Dto.Fundraising.PageRegistration but is not here
+
+ //videos is in GG.Api.Services.Dto.Fundraising.PageRegistration but is not here
+
+ [DataMember(Name = "rememberedPersonReference")]
+ public RememberedPersonReference RememberedPersonReference { get; set; }
}
}
View
83 DotNet/src/JustGiving.Api.Sdk/Model/Remember/RememberedPersonReference.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Runtime.Serialization;
+using JustGiving.Api.Sdk.Model.Summaries;
+
+namespace JustGiving.Api.Sdk.Model.Remember
+{
+ [DataContract(Name = "rememberedPersonReference", Namespace = "")]
+ public class RememberedPersonReference
+ {
+ [DataMember(Name = "relationship")]
+ public string Relationship { get; set; }
+
+ [DataMember(Name = "rememberedPerson")]
+ public RememberedPerson RememberedPerson { get; set; }
+
+ }
+
+ [DataContract(Name = "rememberedPersonResponse", Namespace = "")]
+ public class RememberedPersonResponse
+ {
+ [DataMember(Name = "rememberedPerson")]
+ public RememberedPerson RememberedPerson { get; set; }
+
+ [DataMember(Name = "collectionUri")]
+ public string CollectionUri { get; set; }
+ }
+
+ [DataContract(Name = "rememberedPerson", Namespace = "")]
+ public class RememberedPerson
+ {
+ [DataMember(Name = "id")]
+ public int Id { get; set; }
+
+ [DataMember(Name = "firstName")]
+ public string FirstName { get; set; }
+
+ [DataMember(Name = "lastName")]
+ public string LastName { get; set; }
+
+ [DataMember(Name = "gender")]
+ public int? Gender { get; set; }
+
+ [DataMember(Name = "town")]
+ public string Town { get; set; }
+
+ [DataMember(Name = "dateOfBirth")]
+ public DateTime? DateOfBirth { get; set; }
+
+ [DataMember(Name = "dateOfDeath")]
+ public DateTime? DateOfDeath { get; set; }
+ }
+
+ [DataContract(Name = "rememberedPersonCollection", Namespace = "")]
+ public class RememberedPersonCollection
+ {
+ [DataMember(Name = "grandTotal")]
+ public decimal GrandTotal { get; set; }
+
+ [DataMember(Name = "pages")]
+ public PageSummary[] Pages { get; set; }
+
+ [DataMember(Name = "charities")]
+ public CharitySummary[] Charities { get; set; }
+
+ [DataMember(Name = "events")]
+ public EventSummary[] Events { get; set; }
+
+ }
+
+ [DataContract(Name = "rememberedPersonSummary", Namespace = "")]
+ public class RememberedPersonSummary
+ {
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+
+ [DataMember(Name = "id")]
+ public string Id { get; set; }
+
+ [DataMember(Name = "next")]
+ public RestResponseNextElement Next { get; set; }
+
+ }
+}
View
51 DotNet/src/JustGiving.Api.Sdk/Model/Summaries/Summaries.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+
+namespace JustGiving.Api.Sdk.Model.Summaries
+{
+ [DataContract(Name = "PageSummary", Namespace = "")]
+ public class PageSummary
+ {
+ [DataMember(Name = "id")]
+ public int Id { get; set; }
+ [DataMember(Name = "story")]
+ public string Story { get; set; }
+ [DataMember(Name = "amountRaised")]
+ public decimal AmountRaised { get; set; }
+ [DataMember(Name = "image")]
+ public string Image { get; set; }
+ [DataMember(Name = "charityId")]
+ public int CharityId { get; set; }
+ [DataMember(Name = "eventId")]
+ public int EventId { get; set; }
+ [DataMember(Name = "uri")]
+ public string Uri { get; set; }
+ }
+
+ [DataContract(Name = "CharitySummary", Namespace = "")]
+ public class CharitySummary
+ {
+ [DataMember(Name = "id")]
+ public int Id { get; set; }
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+ [DataMember(Name = "uri")]
+ public string Uri { get; set; }
+ }
+
+ [DataContract(Name = "EventSummary", Namespace = "")]
+ public class EventSummary
+ {
+ [DataMember(Name = "id")]
+ public int Id { get; set; }
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+ [DataMember(Name = "date")]
+ public DateTime? Date { get; set; }
+ [DataMember(Name = "uri")]
+ public string Uri { get; set; }
+ }
+}

0 comments on commit 0460b86

Please sign in to comment.