-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
small updates and added additional unit tests
- Loading branch information
1 parent
d4ee5d6
commit a9254a2
Showing
24 changed files
with
560 additions
and
30 deletions.
There are no files selected for viewing
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
113 changes: 113 additions & 0 deletions
113
src/Reveal.Sdk.Dom.Tests/Core/VisualizationCollectionFixture.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,113 @@ | ||
using Reveal.Sdk.Dom.Core; | ||
using Reveal.Sdk.Dom.Visualizations; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace Reveal.Sdk.Dom.Tests.Core | ||
{ | ||
public class VisualizationCollectionFixture | ||
{ | ||
[Fact] | ||
public void Add_AddsVisualizationToCollection() | ||
{ | ||
// Arrange | ||
var collection = new VisualizationCollection(); | ||
var visualization = new MockVisualization(); | ||
|
||
// Act | ||
collection.Add(visualization); | ||
|
||
// Assert | ||
Assert.Contains(visualization, collection); | ||
} | ||
|
||
[Fact] | ||
public void AddRange_AddsVisualizationsToCollection() | ||
{ | ||
// Arrange | ||
var collection = new VisualizationCollection(); | ||
var visualizations = new List<IVisualization> | ||
{ | ||
new MockVisualization(), | ||
new MockVisualization(), | ||
new MockVisualization() | ||
}; | ||
|
||
// Act | ||
collection.AddRange(visualizations); | ||
|
||
// Assert | ||
Assert.Equal(visualizations.Count, collection.Count); | ||
foreach (var visualization in visualizations) | ||
{ | ||
Assert.Contains(visualization, collection); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void RemoveById_RemovesVisualizationFromCollection() | ||
{ | ||
// Arrange | ||
var collection = new VisualizationCollection(); | ||
var visualization1 = new MockVisualization { Id = "1" }; | ||
var visualization2 = new MockVisualization { Id = "2" }; | ||
var visualization3 = new MockVisualization { Id = "3" }; | ||
collection.AddRange(new List<IVisualization> { visualization1, visualization2, visualization3 }); | ||
|
||
// Act | ||
var result = collection.RemoveById("2"); | ||
|
||
// Assert | ||
Assert.Equal(1, result); | ||
Assert.DoesNotContain(visualization2, collection); | ||
} | ||
|
||
[Fact] | ||
public void RemoveByTitle_RemovesVisualizationsFromCollection() | ||
{ | ||
// Arrange | ||
var collection = new VisualizationCollection(); | ||
var visualization1 = new MockVisualization { Title = "Title 1" }; | ||
var visualization2 = new MockVisualization { Title = "Title 2" }; | ||
var visualization3 = new MockVisualization { Title = "Title 3" }; | ||
collection.AddRange(new List<IVisualization> { visualization1, visualization2, visualization3 }); | ||
|
||
// Act | ||
var result = collection.RemoveByTitle("Title 2"); | ||
|
||
// Assert | ||
Assert.Equal(1, result); | ||
Assert.DoesNotContain(visualization2, collection); | ||
} | ||
|
||
[Fact] | ||
public void FindById_ReturnsVisualizationFromCollection() | ||
{ | ||
// Arrange | ||
var collection = new VisualizationCollection(); | ||
var visualization1 = new MockVisualization { Id = "1" }; | ||
var visualization2 = new MockVisualization { Id = "2" }; | ||
var visualization3 = new MockVisualization { Id = "3" }; | ||
collection.AddRange(new List<IVisualization> { visualization1, visualization2, visualization3 }); | ||
|
||
// Act | ||
var result = collection.FindById("2"); | ||
|
||
// Assert | ||
Assert.Equal(visualization2, result); | ||
} | ||
|
||
private class MockVisualization : IVisualization, IParentDocument | ||
{ | ||
public string Id { get; set; } | ||
public string Title { get; set; } | ||
public ChartType ChartType { get; } | ||
public bool IsTitleVisible { get; set; } | ||
public int ColumnSpan { get; set; } | ||
public int RowSpan { get; set; } | ||
public string Description { get; set; } | ||
public IDataDefinition DataDefinition { get; } | ||
RdashDocument IParentDocument.Document { get; set; } | ||
} | ||
} | ||
} |
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,115 @@ | ||
using Reveal.Sdk.Dom.Core.Constants; | ||
using Reveal.Sdk.Dom.Data; | ||
using Xunit; | ||
|
||
namespace Reveal.Sdk.Dom.Tests.Data | ||
{ | ||
public class DataSourceFixture | ||
{ | ||
[Fact] | ||
public void DataSource_DefaultConstructor_SetsSchemaTypeName() | ||
{ | ||
// Arrange | ||
var dataSource = new DataSource(); | ||
|
||
// Act | ||
|
||
// Assert | ||
Assert.Equal(SchemaTypeNames.DataSourceType, dataSource.SchemaTypeName); | ||
} | ||
|
||
[Fact] | ||
public void DataSource_DefaultConstructor_SetsProperties() | ||
{ | ||
// Arrange | ||
var dataSource = new DataSource(); | ||
|
||
// Act | ||
|
||
// Assert | ||
Assert.NotNull(dataSource.Properties); | ||
} | ||
|
||
[Fact] | ||
public void DataSource_DefaultConstructor_GeneratesUniqueId() | ||
{ | ||
// Arrange | ||
var dataSource1 = new DataSource(); | ||
var dataSource2 = new DataSource(); | ||
|
||
// Act | ||
|
||
// Assert | ||
Assert.NotEqual(dataSource1.Id, dataSource2.Id); | ||
} | ||
|
||
[Fact] | ||
public void DataSource_SetId_NullValue_GeneratesUniqueId() | ||
{ | ||
// Arrange | ||
var dataSource = new DataSource(); | ||
|
||
// Act | ||
dataSource.Id = null; | ||
|
||
// Assert | ||
Assert.NotNull(dataSource.Id); | ||
} | ||
|
||
[Fact] | ||
public void DataSource_DefaultRefreshRate_Should_SetAndGetValue() | ||
{ | ||
// Arrange | ||
var dataSource = new DataSource(); | ||
var expectedValue = "10 minutes"; | ||
|
||
// Act | ||
dataSource.DefaultRefreshRate = expectedValue; | ||
var actualValue = dataSource.DefaultRefreshRate; | ||
|
||
// Assert | ||
Assert.Equal(expectedValue, actualValue); | ||
} | ||
|
||
[Fact] | ||
public void DataSource_Equals_Null_ReturnsFalse() | ||
{ | ||
// Arrange | ||
var dataSource = new DataSource(); | ||
|
||
// Act | ||
var result = dataSource.Equals(null); | ||
|
||
// Assert | ||
Assert.False(result); | ||
} | ||
|
||
[Fact] | ||
public void DataSource_Equals_SameId_ReturnsTrue() | ||
{ | ||
// Arrange | ||
var dataSource1 = new DataSource { Id = "same-id" }; | ||
var dataSource2 = new DataSource { Id = "same-id" }; | ||
|
||
// Act | ||
var result = dataSource1.Equals(dataSource2); | ||
|
||
// Assert | ||
Assert.True(result); | ||
} | ||
|
||
[Fact] | ||
public void DataSource_GetHashCode_ReturnsConsistentValue() | ||
{ | ||
// Arrange | ||
var dataSource = new DataSource(); | ||
|
||
// Act | ||
var hashCode1 = dataSource.GetHashCode(); | ||
var hashCode2 = dataSource.GetHashCode(); | ||
|
||
// Assert | ||
Assert.Equal(hashCode1, hashCode2); | ||
} | ||
} | ||
} |
Oops, something went wrong.