tests: begin adding tests to webhook project
This commit is contained in:
@@ -6,11 +6,13 @@ internal class LastPostedStreamStore : ILastPostedStreamStore
|
||||
|
||||
public void SetValue(string value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public bool HasValue(string value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
return _value.Equals(value, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace StevesBot.Webhook.Tests.Unit;
|
||||
|
||||
public class DiscordNotificationOptionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnInstance()
|
||||
{
|
||||
var options = new DiscordNotificationOptions();
|
||||
|
||||
options.ChannelId.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithProperties_ItShouldReturnInstance()
|
||||
{
|
||||
var channelId = "1234567890";
|
||||
var messageFormat = "New video uploaded: {VideoTitle}";
|
||||
|
||||
var options = new DiscordNotificationOptions
|
||||
{
|
||||
ChannelId = channelId,
|
||||
MessageFormat = messageFormat
|
||||
};
|
||||
|
||||
options.ChannelId.Should().Be(channelId);
|
||||
options.MessageFormat.Should().Be(messageFormat);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace StevesBot.Webhook.Tests.Unit;
|
||||
|
||||
public class LastPostedStreamStoreTests
|
||||
{
|
||||
[Fact]
|
||||
public void SetValue_WhenCalledWithNull_ItShouldThrowArgumentNullException()
|
||||
{
|
||||
var store = new LastPostedStreamStore();
|
||||
|
||||
var act = () => store.SetValue(null!);
|
||||
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasValue_WhenCalledWithNull_ItShouldThrowArgumentNullException()
|
||||
{
|
||||
var store = new LastPostedStreamStore();
|
||||
|
||||
var act = () => store.HasValue(null!);
|
||||
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void SetValueHasValue_WhenCalled_ItShouldStoreValue()
|
||||
{
|
||||
var store = new LastPostedStreamStore();
|
||||
var streamId = "test-stream-id";
|
||||
|
||||
store.SetValue(streamId);
|
||||
|
||||
store.HasValue(streamId).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace StevesBot.Webhook.Tests.Unit;
|
||||
|
||||
public class PubSubClientOptionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnInstance()
|
||||
{
|
||||
var options = new PubSubClientOptions();
|
||||
|
||||
options.BaseUrl.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithProperties_ItShouldReturnInstance()
|
||||
{
|
||||
var baseUrl = "https://example.com";
|
||||
|
||||
var options = new PubSubClientOptions()
|
||||
{
|
||||
BaseUrl = baseUrl
|
||||
};
|
||||
|
||||
options.BaseUrl.Should().Be(baseUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace StevesBot.Webhook.Tests.Unit;
|
||||
|
||||
public class SubscribeTaskTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnInstance()
|
||||
{
|
||||
var task = new SubscribeTask();
|
||||
|
||||
task.CallbackUrl.Should().BeEmpty();
|
||||
task.TopicUrl.Should().BeEmpty();
|
||||
task.ExpiresAt.Should().Be(DateTime.MinValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithProperties_ItShouldReturnInstance()
|
||||
{
|
||||
var callbackUrl = "https://example.com/callback";
|
||||
var topicUrl = "https://example.com/topic";
|
||||
var expiresAt = DateTime.UtcNow.AddDays(1);
|
||||
|
||||
var task = new SubscribeTask
|
||||
{
|
||||
CallbackUrl = callbackUrl,
|
||||
TopicUrl = topicUrl,
|
||||
ExpiresAt = expiresAt
|
||||
};
|
||||
|
||||
task.CallbackUrl.Should().Be(callbackUrl);
|
||||
task.TopicUrl.Should().Be(topicUrl);
|
||||
task.ExpiresAt.Should().Be(expiresAt);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace StevesBot.Webhook.Tests.Unit;
|
||||
|
||||
public class SubscriptionOptionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnInstance()
|
||||
{
|
||||
var options = new SubscriptionOptions();
|
||||
|
||||
options.CallbackUrl.Should().BeEmpty();
|
||||
options.TopicUrl.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithProperties_ItShouldReturnInstance()
|
||||
{
|
||||
var callbackUrl = "https://example.com/callback";
|
||||
var topicUrl = "https://example.com/topic";
|
||||
|
||||
var options = new SubscriptionOptions
|
||||
{
|
||||
CallbackUrl = callbackUrl,
|
||||
TopicUrl = topicUrl
|
||||
};
|
||||
|
||||
options.CallbackUrl.Should().Be(callbackUrl);
|
||||
options.TopicUrl.Should().Be(topicUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace StevesBot.Webhook.Tests.Unit;
|
||||
|
||||
public class YouTubeClientOptionsTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnInstance()
|
||||
{
|
||||
var options = new YouTubeClientOptions();
|
||||
|
||||
options.BaseUrl.Should().BeEmpty();
|
||||
options.ApiKey.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithProperties_ItShouldReturnInstance()
|
||||
{
|
||||
var baseUrl = "https://example.com";
|
||||
var apiKey = "test-api-key";
|
||||
|
||||
var options = new YouTubeClientOptions
|
||||
{
|
||||
BaseUrl = baseUrl,
|
||||
ApiKey = apiKey
|
||||
};
|
||||
|
||||
options.BaseUrl.Should().Be(baseUrl);
|
||||
options.ApiKey.Should().Be(apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
global using StevesBot.Webhook.YouTube;
|
||||
global using StevesBot.Webhook.YouTube.Tasks;
|
||||
Reference in New Issue
Block a user