-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reapply "Libs(CSharp): add kitchen sink test"
This reverts commit ec5acbd.
- Loading branch information
1 parent
38130cc
commit 9773375
Showing
2 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace Svix.Tests; | ||
|
||
public sealed class IgnoreIfClientVarsUnset : FactAttribute | ||
{ | ||
public IgnoreIfClientVarsUnset() | ||
{ | ||
if ( | ||
Environment.GetEnvironmentVariable("SVIX_TOKEN") == null && | ||
Environment.GetEnvironmentVariable("SVIX_SERVER_URL") == null) | ||
{ | ||
Skip = "Test client cannot be constructed when environment variable SVIX_TOKEN or SVIX_SERVER_URL is unset."; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,74 @@ | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Svix.Client; | ||
using Svix.Model; | ||
using Svix.Models; | ||
using Xunit; | ||
|
||
namespace Svix.Tests | ||
namespace Svix.Tests; | ||
|
||
public class SvixClientTests | ||
{ | ||
public class SvixClientTests | ||
[Fact] | ||
public void Constructor_WhenCalled_DoesNotNeedLogger() | ||
{ | ||
[Fact] | ||
public void Constructor_WhenCalled_DoesNotNeedLogger() | ||
{ | ||
var sut = new SvixClient("", new SvixOptions("http://some.url")); | ||
var sut = new SvixClient("", new SvixOptions("http://some.url")); | ||
|
||
Assert.NotNull(sut); | ||
} | ||
Assert.NotNull(sut); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_WhenCalled_AcceptsLogger() | ||
{ | ||
var sut = new SvixClient("", new SvixOptions("http://some.url"), new NullLogger<SvixClient>()); | ||
|
||
Assert.NotNull(sut); | ||
} | ||
|
||
[IgnoreIfClientVarsUnset] | ||
public void KitchenSink_SeemsToWorkOkay() | ||
{ | ||
var token = Environment.GetEnvironmentVariable("SVIX_TOKEN"); | ||
var url = Environment.GetEnvironmentVariable("SVIX_SERVER_URL"); | ||
var client = new SvixClient(token, new SvixOptions(url)); | ||
|
||
[Fact] | ||
public void Constructor_WhenCalled_AcceptsLogger() | ||
var app = client.Application.Create(new ApplicationIn(name: "App")); | ||
try | ||
{ | ||
var sut = new SvixClient("", new SvixOptions("http://some.url"), new NullLogger<SvixClient>()); | ||
client.EventType.Create(new EventTypeIn(name: "event.started", description: "Something started")); | ||
} | ||
catch (ApiException e) | ||
{ | ||
// We expect conflicts, but any other status is an error | ||
Assert.Equal(409, e.ErrorCode); | ||
} | ||
|
||
Assert.NotNull(sut); | ||
try | ||
{ | ||
client.EventType.Create(new EventTypeIn(name: "event.ended", description: "Something ended")); | ||
} | ||
catch (ApiException e) | ||
{ | ||
// We expect conflicts, but any other status is an error | ||
Assert.Equal(409, e.ErrorCode); | ||
} | ||
|
||
var ep = client.Endpoint.Create(app.Id, | ||
new EndpointIn(url: "https://example.svix.com/", channels: new List<string> { "ch0", "ch1" })); | ||
|
||
ep.Channels.Sort(); | ||
Assert.Equal(new List<string> { "ch0", "ch1" }, ep.Channels); | ||
Assert.Null(ep.FilterTypes); | ||
|
||
var epPatched = client.Endpoint.Patch(app.Id, ep.Id, | ||
new EndpointPatch(filterTypes: new List<string> { "event.started", "event.ended" })); | ||
epPatched.Channels.Sort(); | ||
epPatched.FilterTypes.Sort(); | ||
Assert.Equal(new List<string> { "ch0", "ch1" }, epPatched.Channels); | ||
Assert.Equal(new List<string> { "event.ended", "event.started" }, epPatched.FilterTypes); | ||
|
||
// Should not throw an exception if the serialization code handles empty bodies properly | ||
client.Endpoint.Delete(app.Id, ep.Id); | ||
} | ||
} |