Files

97 lines
3.3 KiB
C#

using FluentAssertions;
using NUnit.Framework;
using Strata.ContinuousImprovement.Biz.UserSetting;
using Strata.ContinuousImprovement.JazzEntityFrameworkStub;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Strata.ContinuousImprovement.Biz.Test.Unit.Generics
{
[TestFixture, Category("Unit")]
public class UserSettingServieTest
{
[SetUp]
public void TestSetUp()
{
// Method intentionally left empty.
}
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
public async Task TestGetUserSetting(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, CancellationToken cancellationToken)
{
// arrange
var userSettingService = new UserSettingService(jazzEntityFrameworkFactory, null, null, null);
var userGuid = jazzEntityFrameworkFactory.UserSettings?.First().UserGuid ?? Guid.Empty;
try
{
// act
var taskResult = await userSettingService.GetById(userGuid, cancellationToken);
// assert
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
{
taskResult.Should().BeNull();
}
else
{
taskResult.Should().NotBeNull()
.And.BeOfType<UserSetting.CciUserSetting>();
}
}
catch (AssertionException ae)
{
ae.Should().BeOfType<AssertionException>();
}
catch (NullReferenceException nre)
{
nre.Should().BeOfType<NullReferenceException>();
}
catch (Exception e)
{
e.Should().BeOfType<OperationCanceledException>();
}
}
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
public async Task TestSetUserSetting(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, CancellationToken cancellationToken)
{
// arrange
var userSettingService = new UserSettingService(jazzEntityFrameworkFactory, null, null, null);
var userSetting = jazzEntityFrameworkFactory.UserSettings?.First();
try
{
// act
var taskResult = await userSettingService.SetUserSetting(userSetting, cancellationToken);
// assert
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
{
taskResult.Should().BeNull();
}
else
{
taskResult.Should().NotBeNull()
.And.BeOfType<UserSetting.CciUserSetting>();
}
}
catch (NullReferenceException nre)
{
nre.Should().BeOfType<NullReferenceException>();
}
catch (TaskCanceledException tce)
{
tce.Should().BeOfType<TaskCanceledException>();
}
catch (Exception e)
{
e.Should().BeOfType<OperationCanceledException>();
}
}
}
}