-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better support for DomBehaviorDefinition
- Loading branch information
1 parent
7aba921
commit e3b359d
Showing
6 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
Utils.DOM.Tests/Builders/DomBehaviorDefinitionBuilderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
namespace Utils.DOM.Tests | ||
{ | ||
using System; | ||
|
||
using FluentAssertions; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
using Skyline.DataMiner.Net.Apps.DataMinerObjectModel; | ||
using Skyline.DataMiner.Net.Apps.DataMinerObjectModel.Status; | ||
using Skyline.DataMiner.Utils.DOM.Builders; | ||
|
||
[TestClass] | ||
public class DomBehaviorDefinitionBuilderTests | ||
{ | ||
[TestMethod] | ||
public void DomBehaviorDefinitionBuilder_WithID() | ||
{ | ||
var id = new DomBehaviorDefinitionId(Guid.NewGuid()); | ||
|
||
var definition = new DomBehaviorDefinitionBuilder() | ||
.WithID(id) | ||
.Build(); | ||
|
||
definition.ID.Should().Be(id); | ||
} | ||
|
||
[TestMethod] | ||
public void DomBehaviorDefinitionBuilder_WithName() | ||
{ | ||
var name = "My name"; | ||
|
||
var definition = new DomBehaviorDefinitionBuilder() | ||
.WithName(name) | ||
.Build(); | ||
|
||
definition.Name.Should().Be(name); | ||
} | ||
|
||
[TestMethod] | ||
public void DomBehaviorDefinitionBuilder_WithInitialStatusId() | ||
{ | ||
var initialStatus = "draft"; | ||
|
||
var definition = new DomBehaviorDefinitionBuilder() | ||
.WithInitialStatusId(initialStatus) | ||
.Build(); | ||
|
||
definition.InitialStatusId.Should().Be(initialStatus); | ||
} | ||
|
||
[TestMethod] | ||
public void DomBehaviorDefinitionBuilder_WithStatuses() | ||
{ | ||
var statuses = new[] | ||
{ | ||
new DomStatus("draft", "Draft"), | ||
new DomStatus("confirmed", "Confirmed"), | ||
}; | ||
|
||
var definition = new DomBehaviorDefinitionBuilder() | ||
.WithStatuses(statuses) | ||
.Build(); | ||
|
||
definition.Statuses.Should().BeEquivalentTo(statuses); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
namespace Skyline.DataMiner.Utils.DOM.Builders | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using Skyline.DataMiner.Net.Apps.DataMinerObjectModel; | ||
using Skyline.DataMiner.Net.Apps.DataMinerObjectModel.Status; | ||
using Skyline.DataMiner.Net.Apps.Sections.SectionDefinitions; | ||
using Skyline.DataMiner.Net.Sections; | ||
|
||
/// <summary> | ||
/// Represents a builder for creating instances of <see cref="DomBehaviorDefinition"/>. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the derived builder class.</typeparam> | ||
public class DomBehaviorDefinitionBuilder<T> where T : DomBehaviorDefinitionBuilder<T> | ||
{ | ||
/// <summary> | ||
/// The <see cref="DomBehaviorDefinition"/> instance being built by the builder. | ||
/// </summary> | ||
protected readonly DomBehaviorDefinition _definition; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DomBehaviorDefinitionBuilder{T}"/> class. | ||
/// </summary> | ||
public DomBehaviorDefinitionBuilder() | ||
{ | ||
_definition = new DomBehaviorDefinition(); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DomBehaviorDefinitionBuilder{T}"/> class with a specified <see cref="DomBehaviorDefinition"/>. | ||
/// </summary> | ||
/// <param name="definition">The existing DOM behavior definition to be used in the builder.</param> | ||
public DomBehaviorDefinitionBuilder(DomBehaviorDefinition definition) | ||
{ | ||
_definition = definition ?? throw new ArgumentNullException(nameof(definition)); | ||
} | ||
|
||
/// <summary> | ||
/// Builds the <see cref="DomBehaviorDefinition"/>. | ||
/// </summary> | ||
/// <returns>The built <see cref="DomBehaviorDefinition"/>.</returns> | ||
public DomBehaviorDefinition Build() | ||
{ | ||
return _definition; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the ID of the <see cref="DomBehaviorDefinition"/>. | ||
/// </summary> | ||
/// <param name="id">The ID to set.</param> | ||
/// <returns>The builder instance.</returns> | ||
public T WithID(DomBehaviorDefinitionId id) | ||
{ | ||
_definition.ID = id ?? throw new ArgumentNullException(nameof(id)); | ||
|
||
return (T)this; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the ID of the <see cref="DomBehaviorDefinition"/> using a GUID. | ||
/// </summary> | ||
/// <param name="id">The GUID to set as the ID.</param> | ||
/// <returns>The builder instance.</returns> | ||
public T WithID(Guid id) | ||
{ | ||
return WithID(new DomBehaviorDefinitionId(id)); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the name of the <see cref="DomBehaviorDefinition"/>. | ||
/// </summary> | ||
/// <param name="name">The name to set.</param> | ||
/// <returns>The builder instance.</returns> | ||
public T WithName(string name) | ||
{ | ||
if (String.IsNullOrWhiteSpace(name)) | ||
{ | ||
throw new ArgumentException($"'{nameof(name)}' cannot be null or whitespace.", nameof(name)); | ||
} | ||
|
||
_definition.Name = name; | ||
|
||
return (T)this; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the initial status ID. | ||
/// </summary> | ||
/// <param name="initialStatusId">The initial status to set.</param> | ||
/// <returns>The builder instance.</returns> | ||
public T WithInitialStatusId(string initialStatusId) | ||
{ | ||
_definition.InitialStatusId = initialStatusId; | ||
|
||
return (T)this; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the statuses. | ||
/// </summary> | ||
/// <param name="statuses">The statuses to set.</param> | ||
/// <returns>The builder instance.</returns> | ||
public T WithStatuses(IEnumerable<DomStatus> statuses) | ||
{ | ||
if (statuses == null) | ||
{ | ||
throw new ArgumentNullException(nameof(statuses)); | ||
} | ||
|
||
_definition.Statuses = statuses.ToList(); | ||
|
||
return (T)this; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Represents a builder for creating instances of <see cref="DomBehaviorDefinition"/>. | ||
/// </summary> | ||
public class DomBehaviorDefinitionBuilder : DomBehaviorDefinitionBuilder<DomBehaviorDefinitionBuilder> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DomBehaviorDefinitionBuilder"/> class. | ||
/// </summary> | ||
public DomBehaviorDefinitionBuilder() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DomBehaviorDefinitionBuilder"/> class with a specified <see cref="DomBehaviorDefinition"/>. | ||
/// </summary> | ||
/// <param name="definition">The existing DOM behavior definition to be used in the builder.</param> | ||
public DomBehaviorDefinitionBuilder(DomBehaviorDefinition definition) : base(definition) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters