14d959834f
* xunit unit tests * most pass with formatting * convert objects to xunit * remove nunit * format * merge fixes * switch objects to fluent assertions * update to fluent assertions * more FA * convert all to FA * Format * Fix tests * formatting * hopefully made credential test better * Catch more specific exception * use another more specific exception * Fix tests * update to xunit * update packages
95 lines
2.2 KiB
C#
95 lines
2.2 KiB
C#
using FluentAssertions;
|
|
using Speckle.Sdk.Common;
|
|
using Xunit;
|
|
|
|
namespace Speckle.Sdk.Tests.Unit.Common;
|
|
|
|
public class NotNullTests
|
|
{
|
|
[Theory]
|
|
[InlineData(null, 0)]
|
|
[InlineData(new string[0], 0)]
|
|
[InlineData(new[] { "yay" }, 1)]
|
|
public void Empty(string[]? test, int length)
|
|
{
|
|
var list = test.Empty().ToList();
|
|
list.Count.Should().Be(length);
|
|
}
|
|
|
|
[Fact]
|
|
public void NotNullClass()
|
|
{
|
|
var t = "test".NotNull();
|
|
t.Should().Be("test");
|
|
}
|
|
|
|
[Fact]
|
|
public void NotNullStruct()
|
|
{
|
|
var t = NotNullExtensions.NotNull<int>(2);
|
|
t.Should().Be(2);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task NotNullClass_Task()
|
|
{
|
|
var t = await Task.FromResult<string?>("test").NotNull();
|
|
t.Should().Be("test");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task NotNullStruct_Task()
|
|
{
|
|
var t = await Task.FromResult<int?>(2).NotNull();
|
|
t.Should().Be(2);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task NotNullClass_ValueTask()
|
|
{
|
|
var t = await ValueTask.FromResult<string?>("test").NotNull();
|
|
t.Should().Be("test");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task NotNullStruct_ValueTask()
|
|
{
|
|
var t = await ValueTask.FromResult<int?>(2).NotNull();
|
|
t.Should().Be(2);
|
|
}
|
|
|
|
[Fact]
|
|
public void NotNullClass_Exception() => FluentActions.Invoking(() => ((string?)null).NotNull());
|
|
|
|
[Fact]
|
|
public void NotNullStruct_Exception() => FluentActions.Invoking(() => ((int?)null).NotNull());
|
|
|
|
[Fact]
|
|
public async Task NotNullClass_Task_Exception() =>
|
|
await FluentActions
|
|
.Invoking(async () => await Task.FromResult((string?)null).NotNull())
|
|
.Should()
|
|
.ThrowAsync<ArgumentNullException>();
|
|
|
|
[Fact]
|
|
public async Task NotNullStruct_Task_Exception() =>
|
|
await FluentActions
|
|
.Invoking(async () => await Task.FromResult((int?)null).NotNull())
|
|
.Should()
|
|
.ThrowAsync<ArgumentNullException>();
|
|
|
|
[Fact]
|
|
public async Task NotNullClass_ValueTask_Exception() =>
|
|
await FluentActions
|
|
.Invoking(async () => await ValueTask.FromResult((string?)null).NotNull())
|
|
.Should()
|
|
.ThrowAsync<ArgumentNullException>();
|
|
|
|
[Fact]
|
|
public async Task NotNullStruct_ValueTask_Exception() =>
|
|
await FluentActions
|
|
.Invoking(async () => await ValueTask.FromResult((int?)null).NotNull())
|
|
.Should()
|
|
.ThrowAsync<ArgumentNullException>();
|
|
}
|