ファイル
YMM4-GitHubUpdateNotifier/GitHubUpdateNotifier.Tests/ModelTests.cs
T

72 行
2.2 KiB
C#

using GitHubUpdateNotifier;
using Xunit;
using static NotifierTests.TestSupport;
namespace NotifierTests;
public class ModelTests
{
[Fact]
public void UpdateCheckResult_UpdateAvailableStatusWithoutUpdate_HasUpdateFalse()
{
var result = new UpdateCheckResult { Status = UpdateStatus.UpdateAvailable };
Assert.False(result.HasUpdate);
}
[Fact]
public void UpdateInfo_FullName_CombinesOwnerAndName()
=> Assert.Equal("acme/widget", SampleInfo().FullName);
[Fact]
public void UpdateNotification_CarriesUpdateAndMessage()
{
var info = SampleInfo();
var notification = new UpdateNotification(info, "hello");
Assert.Same(info, notification.Update);
Assert.Equal("hello", notification.Message);
}
[Fact]
public void UpdateCheckException_NoFailures_HasNoInner()
{
var exception = new UpdateCheckException(Repo("a", "b"), []);
Assert.Null(exception.InnerException);
Assert.Equal("a", exception.Owner);
Assert.Equal("b", exception.Repository);
Assert.Empty(exception.Failures);
}
[Fact]
public void UpdateCheckException_SingleFailure_InnerIsThatException()
{
var inner = new InvalidOperationException("x");
var exception = new UpdateCheckException(Repo(), [inner]);
Assert.Same(inner, exception.InnerException);
}
[Fact]
public void UpdateCheckException_MultipleFailures_InnerIsAggregate()
{
var first = new InvalidOperationException("1");
var second = new InvalidOperationException("2");
var exception = new UpdateCheckException(Repo(), [first, second]);
var aggregate = Assert.IsType<AggregateException>(exception.InnerException);
Assert.Equal(2, aggregate.InnerExceptions.Count);
}
private static UpdateInfo SampleInfo()
=> new()
{
Owner = "acme",
Name = "widget",
Version = Ver("1.0.0"),
TagName = "v1.0.0",
ReleaseName = "r",
Body = "",
IsPrerelease = false,
PublishedAt = default,
ReleaseUrl = new Uri("https://example.com/"),
Source = UpdateSource.GitHub,
};
}