-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
228 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using TwinCAT.Ads; | ||
using TwinCAT.TypeSystem; | ||
|
||
namespace TwinCAT.JsonExtension.Tests | ||
{ | ||
internal class DebugSymbol : ITcAdsSymbol, ITcAdsSymbol5 | ||
{ | ||
public long IndexGroup { get; set; } | ||
public long IndexOffset { get; set; } | ||
public int Size { get; set; } | ||
public AdsDatatypeId Datatype { get; set; } | ||
public string Name { get; set; } | ||
public string Type { get; set; } | ||
public string Comment { get; set; } | ||
public bool IsPersistent { get; set;} | ||
public bool IsBitType { get; set;} | ||
public bool IsReference { get; set;} | ||
public bool IsPointer { get; set;} | ||
public bool IsTypeGuid { get; set;} | ||
public bool IsReadOnly { get; set;} | ||
public bool IsTcComInterfacePointer { get; set;} | ||
public int ContextMask { get; set;} | ||
public bool IsArray { get; set;} | ||
public int ArrayDimensions { get; set;} | ||
public AdsDatatypeArrayInfo[] ArrayInfos { get; set;} | ||
public ReadOnlyTypeAttributeCollection Attributes { get; set;} | ||
public bool IsEnum { get; set;} | ||
public bool IsStruct { get; set;} | ||
public bool HasRpcMethods { get; set;} | ||
public ReadOnlyRpcMethodCollection RpcMethods { get; set;} | ||
public DataTypeCategory Category { get; set;} | ||
public int BitSize { get; set;} | ||
public int ByteSize { get; set;} | ||
public bool IsRecursive(IEnumerable<ITcAdsSymbol5> parents) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public ITcAdsDataType DataType { get; set;} | ||
public AdsDatatypeId DataTypeId { get; set;} | ||
public string TypeName { get; set;} | ||
public bool IsStatic { 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,55 @@ | ||
using System; | ||
using System.Linq; | ||
using TwinCAT.Ads; | ||
using TwinCAT.Ads.Internal; | ||
using TwinCAT.TypeSystem; | ||
|
||
namespace TwinCAT.JsonExtension.Tests | ||
{ | ||
internal class DebugType : ITcAdsDataType | ||
{ | ||
public int Size { get; set;} | ||
public bool IsBitType { get; set;} | ||
public int BitSize { get; set;} | ||
public int ByteSize { get; set;} | ||
public bool IsByteAligned { get; set;} | ||
public int Id { get; set;} | ||
public DataTypeCategory Category { get; set;} | ||
public string Name { get; set;} | ||
public string Namespace { get; set;} | ||
public string FullName { get; set;} | ||
public bool IsPrimitive { get; set;} | ||
public bool IsContainer { get; set;} | ||
public bool IsPointer { get; set;} | ||
public bool IsReference { get; set;} | ||
public ReadOnlyTypeAttributeCollection Attributes { get; set;} | ||
public string Comment { get; set;} | ||
public IDataType ResolveType(DataTypeResolveStrategy type) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public AdsDatatypeId DataTypeId { get; set;} | ||
public bool HasArrayInfo { get; set;} | ||
public ReadOnlyDimensionCollection Dimensions { get; set;} | ||
public bool HasRpcMethods { get; set;} | ||
public ReadOnlyRpcMethodCollection RpcMethods { get; set;} | ||
public ITcAdsDataType BaseType { get; set;} | ||
public string BaseTypeName { get; set;} | ||
public bool HasEnumInfo { get; set;} | ||
public ReadOnlyEnumValueCollection EnumInfos { get; set;} | ||
public ReadOnlyEnumValueCollection EnumValues { get; set;} | ||
public ReadOnlySubItemCollection SubItems { get; set;} | ||
public bool HasSubItemInfo { get; set;} | ||
public bool IsEnum { get; set;} | ||
public bool IsArray { get; set;} | ||
public bool IsStruct { get; set;} | ||
public bool IsSubItem { get; set;} | ||
public bool IsAlias { get; set;} | ||
public bool IsString { get; set;} | ||
public Type ManagedType { get; set;} | ||
public bool IsOversamplingArray { get; set;} | ||
public AdsDataTypeFlags Flags { get; set;} | ||
public bool IsJaggedArray { 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,98 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Moq; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
using TwinCAT.Ads; | ||
|
||
namespace TwinCAT.JsonExtension.Tests | ||
{ | ||
public class TestReadWriteOperations | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
} | ||
|
||
[Test] | ||
public async Task ReadSymbolWithDifferentType() | ||
{ | ||
var clientMock = new Mock<IAdsSymbolicAccess>(); | ||
|
||
var value = 10; | ||
clientMock.Setup(client => client.ReadSymbol(It.IsAny<ITcAdsSymbol>())) | ||
.Returns(value); | ||
var symbol = new DebugSymbol(); | ||
clientMock.Setup(client => client.ReadSymbolInfo(It.IsAny<string>())) | ||
.Returns(symbol); | ||
|
||
var variableName = "test.object"; | ||
var readVariable = await clientMock.Object.ReadAsync<string>(variableName); | ||
|
||
clientMock.Verify(client => client.ReadSymbolInfo(variableName), Times.Once); | ||
clientMock.Verify(client => client.ReadSymbol(symbol), Times.Once); | ||
|
||
readVariable.ShouldBe(value.ToString()); | ||
} | ||
|
||
[Test] | ||
public async Task ReadSymbol() | ||
{ | ||
var clientMock = new Mock<IAdsSymbolicAccess>(); | ||
|
||
int value = 10; | ||
clientMock.Setup(client => client.ReadSymbol(It.IsAny<ITcAdsSymbol>())) | ||
.Returns(value); | ||
var symbol = new DebugSymbol(); | ||
clientMock.Setup(client => client.ReadSymbolInfo(It.IsAny<string>())) | ||
.Returns(symbol); | ||
|
||
var variableName = "test.object"; | ||
var readVariable = await clientMock.Object.ReadAsync<int>(variableName); | ||
|
||
clientMock.Verify(client => client.ReadSymbolInfo(variableName), Times.Once); | ||
clientMock.Verify(client => client.ReadSymbol(symbol), Times.Once); | ||
|
||
readVariable.ShouldBe(value); | ||
} | ||
|
||
[Test] | ||
public async Task WriteSymbol() | ||
{ | ||
var clientMock = new Mock<IAdsSymbolicAccess>(); | ||
|
||
var symbol = new DebugSymbol(); | ||
var targetType = typeof(int); | ||
symbol.DataType = new DebugType(){ManagedType = targetType}; | ||
|
||
clientMock.Setup(client => client.ReadSymbolInfo(It.IsAny<string>())) | ||
.Returns(symbol); | ||
var variableName = "test.object"; | ||
int value = 10; | ||
await clientMock.Object.WriteAsync(variableName, value); | ||
|
||
clientMock.Verify(client => client.ReadSymbolInfo(variableName), Times.Once); | ||
clientMock.Verify(client => client.WriteSymbol(symbol, value), Times.Once); | ||
} | ||
|
||
[Test] | ||
public async Task WriteSymbolWithDifferentType() | ||
{ | ||
var clientMock = new Mock<IAdsSymbolicAccess>(); | ||
|
||
var symbol = new DebugSymbol(); | ||
var targetType = typeof(string); | ||
symbol.DataType = new DebugType() { ManagedType = targetType }; | ||
|
||
clientMock.Setup(client => client.ReadSymbolInfo(It.IsAny<string>())) | ||
.Returns(symbol); | ||
var variableName = "test.object"; | ||
int value = 10; | ||
await clientMock.Object.WriteAsync(variableName, value); | ||
|
||
clientMock.Verify(client => client.ReadSymbolInfo(variableName), Times.Once); | ||
clientMock.Verify(client => client.WriteSymbol(symbol, value.ToString()), Times.Once); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
TwinCAT.JsonExtension.Tests/TwinCAT.JsonExtension.Tests.csproj
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,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net45</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Beckhoff.TwinCAT.Ads" Version="4.3.7" /> | ||
<PackageReference Include="Moq" Version="4.13.0" /> | ||
<PackageReference Include="nunit" Version="3.12.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" /> | ||
<PackageReference Include="Shouldly" Version="3.0.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TwinCAT.JsonExtension\TwinCAT.JsonExtension.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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