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(); } } catch (AssertionException ae) { ae.Should().BeOfType(); } catch (NullReferenceException nre) { nre.Should().BeOfType(); } catch (Exception e) { e.Should().BeOfType(); } } [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(); } } catch (NullReferenceException nre) { nre.Should().BeOfType(); } catch (TaskCanceledException tce) { tce.Should().BeOfType(); } catch (Exception e) { e.Should().BeOfType(); } } } }