Skip to content

Commit

Permalink
Add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander van Delft committed Jan 7, 2025
1 parent 74dd724 commit b32b538
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 38 deletions.
92 changes: 65 additions & 27 deletions COMET.Web.Common.Tests/Components/OpenModelTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,13 @@ public class OpenModelTestFixture
private Mock<ISessionService> sessionService;
private Mock<IConfigurationService> configurationService;
private Mock<ICacheService> cacheService;
private List<EngineeringModelSetup> engineeringModels;

[SetUp]
public void Setup()
{
this.context = new TestContext();
this.sessionService = new Mock<ISessionService>();
this.configurationService = new Mock<IConfigurationService>();
this.cacheService = new Mock<ICacheService>();
this.viewModel = new OpenModelViewModel(this.sessionService.Object, this.configurationService.Object, this.cacheService.Object);
this.context.ConfigureDevExpressBlazor();
this.context.Services.AddSingleton<IOpenModelViewModel>(this.viewModel);

var stringTableService = new Mock<IStringTableService>();
this.context.Services.AddSingleton(stringTableService.Object);
}

[TearDown]
public void Teardown()
{
this.context.CleanContext();
}

[Test]
public async Task VerifyOpenModel()
{
var engineeringModels = new List<EngineeringModelSetup>
{
this.engineeringModels =
[
new()
{
Iid = Guid.NewGuid(),
Expand All @@ -99,6 +79,7 @@ public async Task VerifyOpenModel()
}
}
},

new()
{
Iid = Guid.NewGuid(),
Expand All @@ -109,7 +90,7 @@ public async Task VerifyOpenModel()
{
Iid = Guid.NewGuid(),
IterationNumber = 1,
FrozenOn = DateTime.Now - TimeSpan.FromDays(1)
FrozenOn = DateTimeOffset.Now.AddDays(-1).DateTime
},
new IterationSetup
{
Expand All @@ -118,10 +99,31 @@ public async Task VerifyOpenModel()
}
}
}
};
];

this.context = new TestContext();
this.sessionService = new Mock<ISessionService>();
this.configurationService = new Mock<IConfigurationService>();
this.cacheService = new Mock<ICacheService>();
this.viewModel = new OpenModelViewModel(this.sessionService.Object, this.configurationService.Object, this.cacheService.Object);
this.context.ConfigureDevExpressBlazor();
this.context.Services.AddSingleton<IOpenModelViewModel>(this.viewModel);

var stringTableService = new Mock<IStringTableService>();
this.context.Services.AddSingleton(stringTableService.Object);
}

[TearDown]
public void Teardown()
{
this.context.CleanContext();
}

[Test]
public async Task VerifyOpenModel()
{
this.sessionService.Setup(x => x.OpenIterations).Returns(new SourceList<Iteration>());
this.sessionService.Setup(x => x.GetParticipantModels()).Returns(engineeringModels);
this.sessionService.Setup(x => x.GetParticipantModels()).Returns(this.engineeringModels);
var renderer = this.context.RenderComponent<OpenModel>();
var layoutItems = renderer.FindComponents<DxFormLayoutItem>();

Expand Down Expand Up @@ -158,13 +160,49 @@ public async Task VerifyOpenModel()

this.viewModel.SelectedEngineeringModel = null;

var result = await this.viewModel.OpenSession();

Assert.Multiple(() =>
{
Assert.That(this.viewModel.SelectedDomainOfExpertise, Is.Null);
Assert.That(this.viewModel.SelectedIterationSetup, Is.Null);
Assert.That(this.viewModel.AvailableIterationSetups, Is.Empty);
Assert.That(this.viewModel.AvailablesDomainOfExpertises, Is.Empty);
Assert.That(async () => await this.viewModel.OpenSession(), Throws.Nothing);
Assert.That(result.IsFailed, Is.True);
Assert.That(result.Errors[0].Message, Is.EqualTo("The selected iteration and the domain of expertise should not be null"));
});
}

[Test]
public async Task VerifyOpenModelFails()
{
this.sessionService.Setup(x => x.OpenIterations).Returns(new SourceList<Iteration>());
this.sessionService.Setup(x => x.GetParticipantModels()).Returns(this.engineeringModels);
this.context.RenderComponent<OpenModel>();

this.sessionService.Setup(x => x.GetModelDomains(It.IsAny<EngineeringModelSetup>()))
.Returns(new List<DomainOfExpertise> { new() { Name = "Thermodynamic" } });

this.viewModel.SelectedEngineeringModel = this.viewModel.AvailableEngineeringModelSetups.First();
this.viewModel.SelectedDomainOfExpertise = this.viewModel.AvailablesDomainOfExpertises.First();
this.viewModel.SelectedIterationSetup = this.viewModel.AvailableIterationSetups.First();

var iteration = new Iteration(Guid.NewGuid(), null, null)
{
IterationSetup = this.engineeringModels.SelectMany(x => x.IterationSetup).Single(x => x.Iid == this.viewModel.SelectedIterationSetup.IterationSetupId)
};

var openIterations = new SourceList<Iteration>();
openIterations.Add(iteration);

this.sessionService.Setup(x => x.OpenIterations).Returns(openIterations);

var result = await this.viewModel.OpenSession();

Assert.Multiple(() =>
{
Assert.That(result.IsFailed, Is.True);
Assert.That(result.Errors[0].Message, Is.EqualTo("The selected iteration is already openened"));
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions COMET.Web.Common/Components/CardView/CardView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public partial class CardView<T> : DisposableComponent
/// Gets or sets the item template for the list.
/// </summary>
[Parameter]
public RenderFragment<T>? ItemTemplate { get; set; }
public RenderFragment<T> ItemTemplate { get; set; }

/// <summary>
/// Gets or sets the list of items of type T to use
Expand Down Expand Up @@ -90,12 +90,12 @@ public partial class CardView<T> : DisposableComponent
/// <summary>
/// A reference to the <see cref="Virtualize{T}"/> component for loading items
/// </summary>
private Virtualize<T>? virtualize; // Reference to the Virtualize component
private Virtualize<T> virtualize; // Reference to the Virtualize component

/// <summary>
/// The FastMember <see cref="FastMember.TypeAccessor"/> to use to perform actions on instances of type T
/// </summary>
private TypeAccessor typeAccessor = TypeAccessor.Create(typeof(T));
private readonly TypeAccessor typeAccessor = TypeAccessor.Create(typeof(T));

/// <summary>
/// The selected Card in the CardView
Expand Down
4 changes: 2 additions & 2 deletions COMET.Web.Common/Utilities/CopyElementDefinitionCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public class CopyElementDefinitionCreator
/// <summary>
/// The original-clone <see cref="ParameterGroup"/> map
/// </summary>
private readonly Dictionary<ParameterGroup, ParameterGroup> groupMap = new Dictionary<ParameterGroup, ParameterGroup>();
private readonly Dictionary<ParameterGroup, ParameterGroup> groupMap = [];

/// <summary>
/// The original-clone <see cref="ParameterValueSetBase"/> map
/// </summary>
private readonly Dictionary<ParameterValueSetBase, ParameterValueSetBase> valueSetMap = new Dictionary<ParameterValueSetBase, ParameterValueSetBase>();
private readonly Dictionary<ParameterValueSetBase, ParameterValueSetBase> valueSetMap = [];

/// <summary>
/// Initializes a new instance of the <see cref="CopyElementDefinitionCreator"/> class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public abstract class HaveObjectChangedTracking : DisposableObject, IHaveObjectC
/// <summary>
/// A collection of added <see cref="Thing" />s
/// </summary>
protected readonly List<Thing> AddedThings = new();
protected readonly List<Thing> AddedThings = [];

/// <summary>
/// A collection of deleted <see cref="Thing" />s
/// </summary>
protected readonly List<Thing> DeletedThings = new();
protected readonly List<Thing> DeletedThings = [];

/// <summary>
/// A collection of updated <see cref="Thing" />s
/// </summary>
protected readonly List<Thing> UpdatedThings = new();
protected readonly List<Thing> UpdatedThings = [];

/// <summary>
/// Initializes a new instance of <see cref="HaveObjectChangedTracking" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private void ComputeAvailableCollections()
return;
}

var currentModelIteration = this.SelectedEngineeringModel.IterationSetup.FirstOrDefault(x => x == this.sessionService.OpenIterations.Items.FirstOrDefault(i => i.Iid == x.IterationIid)?.IterationSetup);
var currentModelIteration = this.SelectedEngineeringModel.IterationSetup.Find(x => x == this.sessionService.OpenIterations.Items.FirstOrDefault(i => i.Iid == x.IterationIid)?.IterationSetup);
this.SelectedIterationSetup = new IterationData(currentModelIteration);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public IterationData SelectedIterationData
/// <summary>
/// Gets or a collection of selectable <see cref="Iteration"/>s
/// </summary>
public ObservableCollection<IterationData> Iterations { get; } = new();
public ObservableCollection<IterationData> Iterations { get; } = [];

/// <summary>
/// All <see cref="ElementBase" /> of the iteration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ElementDefinitionTreeTreeRowViewModel : ElementBaseTreeRowViewModel
/// <summary>
/// Gets or the collection of <see cref="ElementUsageTreeTreeRowViewModel"/>
/// </summary>
public ObservableCollection<ElementUsageTreeTreeRowViewModel> Rows { get; } = new();
public ObservableCollection<ElementUsageTreeTreeRowViewModel> Rows { get; } = [];

/// <summary>
/// Initializes a new instance of the <see cref="ElementDefinitionRowViewModel" /> class.
Expand Down

0 comments on commit b32b538

Please sign in to comment.