tests: WRITE TESTS FIRST...when will I learn
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
|
||||
namespace StevesBot.Webhook.Tests.Unit;
|
||||
|
||||
public sealed class PubSubClientTests : IDisposable
|
||||
{
|
||||
private readonly MockHttpMessageHandler _mockHttpMessageHandler = new();
|
||||
private readonly Mock<ILogger<PubSubClient>> _mockLogger = new();
|
||||
private readonly PubSubClient _sut;
|
||||
|
||||
public PubSubClientTests()
|
||||
{
|
||||
var mockHttpClient = _mockHttpMessageHandler.ToHttpClient();
|
||||
mockHttpClient.BaseAddress = new("https://test.com");
|
||||
|
||||
_sut = new(mockHttpClient, _mockLogger.Object);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(HttpStatusCode.InternalServerError, false)]
|
||||
[InlineData(HttpStatusCode.OK, true)]
|
||||
public async Task SubscribeAsync_WhenCalled_ItShouldReturnExpectedResult(HttpStatusCode givenStatusCode, bool expectedResult)
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.When("*/subscribe")
|
||||
.Respond(givenStatusCode);
|
||||
|
||||
var result = await _sut.SubscribeAsync("callbackUrl", "topicUrl");
|
||||
|
||||
result.Should().Be(expectedResult);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_mockHttpMessageHandler.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace StevesBot.Webhook.Tests.Unit;
|
||||
|
||||
public class YouTubePageInfoTests
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace StevesBot.Webhook.Tests.Unit;
|
||||
|
||||
public class YouTubeSnippetTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnAnInstance()
|
||||
{
|
||||
var result = new YouTubeSnippet();
|
||||
|
||||
result.LiveBroadcastContent.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithValues_ItShouldReturnAnInstance()
|
||||
{
|
||||
var content = "live";
|
||||
|
||||
var result = new YouTubeSnippet()
|
||||
{
|
||||
LiveBroadcastContent = content,
|
||||
};
|
||||
|
||||
result.LiveBroadcastContent.Should().Be(content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using StevesBot.Webhook.YouTube.Data;
|
||||
|
||||
namespace StevesBot.Webhook.Tests.Unit;
|
||||
|
||||
public class YouTubeVideoListResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnAnInstance()
|
||||
{
|
||||
var result = new YouTubeVideoListResponse();
|
||||
|
||||
result.Items.Should().BeEmpty();
|
||||
result.PageInfo.Should().BeEquivalentTo(new YouTubePageInfo());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithValues_ItShouldReturnAnInstance()
|
||||
{
|
||||
var videos = new YouTubeVideo[] { new() };
|
||||
var pageInfo = new YouTubePageInfo();
|
||||
|
||||
var result = new YouTubeVideoListResponse()
|
||||
{
|
||||
Items = videos,
|
||||
PageInfo = pageInfo,
|
||||
};
|
||||
|
||||
result.Items.Should().BeSameAs(videos);
|
||||
result.PageInfo.Should().BeSameAs(pageInfo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
namespace StevesBot.Webhook.Tests.Unit;
|
||||
|
||||
public class YouTubeVideoTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnAnInstance()
|
||||
{
|
||||
var result = new YouTubeVideo();
|
||||
|
||||
result.Id.Should().BeEmpty();
|
||||
result.LiveStreamingDetails.Should().BeNull();
|
||||
result.Snippet.Should().BeEquivalentTo(new YouTubeSnippet());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithValues_ItShouldReturnAnInstance()
|
||||
{
|
||||
var id = "id";
|
||||
var details = new YouTubeLiveStreamingDetails();
|
||||
var snippet = new YouTubeSnippet();
|
||||
|
||||
var result = new YouTubeVideo()
|
||||
{
|
||||
Id = id,
|
||||
LiveStreamingDetails = details,
|
||||
Snippet = snippet,
|
||||
};
|
||||
|
||||
result.Id.Should().Be(id);
|
||||
result.LiveStreamingDetails.Should().BeSameAs(details);
|
||||
result.Snippet.Should().BeSameAs(snippet);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsLiveStream_WhenLiveStreamingDetailsIsNull_ItShouldReturnFalse()
|
||||
{
|
||||
var video = new YouTubeVideo()
|
||||
{
|
||||
Snippet = new() { LiveBroadcastContent = "live" },
|
||||
};
|
||||
|
||||
video.IsLiveStream.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsLiveStream_WhenSnippetLiveBroadcastContentIsNotLive_ItShouldReturnFalse()
|
||||
{
|
||||
var video = new YouTubeVideo()
|
||||
{
|
||||
LiveStreamingDetails = new(),
|
||||
Snippet = new() { LiveBroadcastContent = "none" },
|
||||
};
|
||||
|
||||
video.IsLiveStream.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsLiveStream_WhenDetailsIsNotNullAndContentIsLive_ItShouldReturnTrue()
|
||||
{
|
||||
var video = new YouTubeVideo()
|
||||
{
|
||||
LiveStreamingDetails = new(),
|
||||
Snippet = new() { LiveBroadcastContent = "live" },
|
||||
};
|
||||
|
||||
video.IsLiveStream.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,11 @@
|
||||
global using System.Net;
|
||||
|
||||
global using Microsoft.Extensions.Logging;
|
||||
|
||||
global using Moq;
|
||||
|
||||
global using RichardSzalay.MockHttp;
|
||||
|
||||
global using StevesBot.Webhook.YouTube;
|
||||
global using StevesBot.Webhook.YouTube.Data;
|
||||
global using StevesBot.Webhook.YouTube.Tasks;
|
||||
Reference in New Issue
Block a user