Skip to content

Commit

Permalink
Merge pull request #170 from RevealBi/unit-test/icategory-extension
Browse files Browse the repository at this point in the history
Create unit tests for ICategoryExtensions class
  • Loading branch information
hainv-ohio authored Dec 24, 2024
2 parents 62c2e5c + d0ab5f0 commit a3177f6
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Moq;
using Reveal.Sdk.Dom.Visualizations;
using Xunit;

namespace Reveal.Sdk.Dom.Tests.Visualizations.Extensions
{
public class ICategoryExtensionsFixture
{
[Fact]
public void SetCategory_UpdateCategory_WithFieldName()
{
// Arrange
var visualization = new MockICategory();
var fieldName = "TestField";
var expectedCategory = new DimensionColumn()
{
DataField = new TextDataField(fieldName)
};

// Act
visualization.SetCategory(fieldName);

// Assert
Assert.Equivalent(expectedCategory, visualization.Category);
}

[Fact]
public void SetCategory_UpdateCategory_WithDimensionDataField()
{
// Arrange
var visualization = new MockICategory();
var fieldName = "TestField";
var mockDimensionDataField = new Mock<DimensionDataField>(fieldName);
var field = mockDimensionDataField.Object;
var expectedCategory = new DimensionColumn()
{
DataField = field
};

// Act
visualization.SetCategory(field);

// Assert
Assert.Equivalent(expectedCategory, visualization.Category);
}

private class MockICategory : ICategory
{
public DimensionColumn Category { get; set; }
}
}
}

0 comments on commit a3177f6

Please sign in to comment.