Skip to content

Commit

Permalink
Subaccount e-mail can be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Jul 25, 2018
1 parent 3285e50 commit f34be9b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
28 changes: 28 additions & 0 deletions SeatsioDotNet.Test/Subaccounts/UpdateSubaccountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,40 @@ public class UpdateSubaccountTest : SeatsioClientTest
[Fact]
public void Test()
{
var email = RandomEmail();
var subaccount = Client.Subaccounts.Create("joske");

Client.Subaccounts.Update(subaccount.Id, "jefke", email);

var retrievedSubaccount = Client.Subaccounts.Retrieve(subaccount.Id);
Assert.Equal("jefke", retrievedSubaccount.Name);
Assert.Equal(email, retrievedSubaccount.Email);
}

[Fact]
public void EmailIsOptional()
{
var email = RandomEmail();
var subaccount = Client.Subaccounts.CreateWithEmail(email, "joske");

Client.Subaccounts.Update(subaccount.Id, "jefke");

var retrievedSubaccount = Client.Subaccounts.Retrieve(subaccount.Id);
Assert.Equal("jefke", retrievedSubaccount.Name);
Assert.Equal(email, retrievedSubaccount.Email);
}

[Fact]
public void NameIsOptional()
{
var email = RandomEmail();
var subaccount = Client.Subaccounts.Create("joske");

Client.Subaccounts.Update(subaccount.Id, email: email);

var retrievedSubaccount = Client.Subaccounts.Retrieve(subaccount.Id);
Assert.Equal("joske", retrievedSubaccount.Name);
Assert.Equal(email, retrievedSubaccount.Email);
}
}
}
2 changes: 1 addition & 1 deletion SeatsioDotNet/SeatsioDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
<Version>31</Version>
<Version>32</Version>
<Authors>mroloux;bverbeken</Authors>
<Title>Official Seats.io .NET API client</Title>
<Description>Official Seats.io .NET API client</Description>
Expand Down
16 changes: 12 additions & 4 deletions SeatsioDotNet/Subaccounts/Subaccounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ public Subaccount CreateWithEmail(string email, string name = null)
private Subaccount DoCreate(string email = null, string name = null)
{
var requestBody = new Dictionary<string, object>();

if (email != null)
{
requestBody.Add("email", email);
}

if (name != null)
{
requestBody.Add("name", name);
Expand All @@ -56,11 +54,21 @@ public Subaccount Retrieve(long id)
return AssertOk(_restClient.Execute<Subaccount>(restRequest));
}

public void Update(long id, string name)
public void Update(long id, string name = null, string email = null)
{
var requestBody = new Dictionary<string, object>();
if (email != null)
{
requestBody.Add("email", email);
}
if (name != null)
{
requestBody.Add("name", name);
}

var restRequest = new RestRequest("/subaccounts/{id}", Method.POST)
.AddUrlSegment("id", id)
.AddJsonBody(new {name});
.AddJsonBody(requestBody);
AssertOk(_restClient.Execute<object>(restRequest));
}

Expand Down

0 comments on commit f34be9b

Please sign in to comment.