-
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.
Merge pull request #271 from RevealBi/unit-test/primitive-test-field
Unit test/primitive test field
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/Reveal.Sdk.Dom.Tests/Visualizations/Primitives/TextFieldFixture.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 @@ | ||
using Newtonsoft.Json.Linq; | ||
using Reveal.Sdk.Dom.Visualizations; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Reveal.Sdk.Dom.Tests.Visualizations.Primitives | ||
{ | ||
public class TextFieldFixture | ||
{ | ||
[Fact] | ||
public void Constructor_SetDefaultValues_WhenConstructed() | ||
{ | ||
// Act | ||
var field = new TextField(); | ||
|
||
// Assert | ||
Assert.Equal(DataType.String, ((IFieldDataType)field).DataType); | ||
Assert.Equal(string.Empty, field.FieldName); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_SetFieldName_WhenConstructed() | ||
{ | ||
// Arrange | ||
var fieldName = "FieldName"; | ||
|
||
// Act | ||
var field = new TextField(fieldName); | ||
|
||
// Assert | ||
Assert.Equal(DataType.String, ((IFieldDataType)field).DataType); | ||
Assert.Equal(fieldName, field.FieldName); | ||
} | ||
|
||
[Fact] | ||
public void ToJsonString_CreateCorrectJsonString_WithoutCondition() | ||
{ | ||
// Arrange | ||
var expectedJson = """ | ||
{ | ||
"FieldName": "FieldName", | ||
"FieldLabel": "FieldName", | ||
"UserCaption": "FieldName", | ||
"IsCalculated": false, | ||
"Properties": {}, | ||
"Sorting": "None", | ||
"FieldType": "String" | ||
} | ||
"""; | ||
var fieldName = "FieldName"; | ||
|
||
// Act | ||
var field = new TextField(fieldName); | ||
|
||
// Act | ||
var actualJson = field.ToJsonString(); | ||
var expectedJObject = JObject.Parse(expectedJson); | ||
var actualJObject = JObject.Parse(actualJson); | ||
|
||
// Assert | ||
Assert.Equal(expectedJObject, actualJObject); | ||
} | ||
} | ||
} |