-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support GetValueOrDefault<> of custom type, view model property of cu…
…stom type.
- Loading branch information
Showing
6 changed files
with
288 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using FluentAssertions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Workstation.ServiceModel.Ua; | ||
using Xunit; | ||
|
||
namespace Workstation.UaClient.UnitTests | ||
{ | ||
public class DataValueExtensionTests | ||
{ | ||
[Fact] | ||
public void GetValueAsString() | ||
{ | ||
var val = new DataValue("Hi"); | ||
|
||
val.GetValueOrDefault<string>() | ||
.Should().Be("Hi"); | ||
val.GetValueOrDefault(-1) | ||
.Should().Be(-1); | ||
} | ||
|
||
[Fact] | ||
public void GetValueAsCustomVector() | ||
{ | ||
var obj = new CustomTypeLibrary.CustomVector { X = 1.0, Y = 2.0, Z = 3.0 }; | ||
var val = new DataValue(obj); | ||
|
||
val.GetValueOrDefault<CustomTypeLibrary.CustomVector>() | ||
.Should().BeEquivalentTo(obj); | ||
val.GetValueOrDefault<object>() | ||
.Should().BeEquivalentTo(obj); | ||
val.GetValueOrDefault(-1) | ||
.Should().Be(-1); | ||
} | ||
|
||
[Fact] | ||
public void GetValueAsArrayInt32() | ||
{ | ||
var array = new int[] { 1, 2, 3, 4, 5 }; | ||
var val = new DataValue(array); | ||
|
||
val.GetValueOrDefault<int[]>() | ||
.Should().BeEquivalentTo(array); | ||
val.GetValueOrDefault(-1) | ||
.Should().Be(-1); | ||
} | ||
|
||
[Fact] | ||
public void GetValueAsArrayCustomVector() | ||
{ | ||
var array = new CustomTypeLibrary.CustomVector[] | ||
{ | ||
new CustomTypeLibrary.CustomVector { X = 1.0, Y = 2.0, Z = 3.0 } | ||
}; | ||
var val = new DataValue(array); | ||
|
||
val.GetValueOrDefault<CustomTypeLibrary.CustomVector[]>() | ||
.Should().BeEquivalentTo(array); | ||
val.GetValueOrDefault<object[]>() | ||
.Should().BeEquivalentTo(array); | ||
val.GetValueOrDefault(-1) | ||
.Should().Be(-1); | ||
} | ||
} | ||
} |
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