Dreamine.FullKit.Tests
1.0.0.0
Dreamine.FullKit.Tests 기능을 검증하는 자동화 테스트 프로젝트입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
FastechProtocolTests.cs
이 파일의 문서화 페이지로 가기
1
using
Dreamine.IO.Abstractions.Models;
2
using
Dreamine.IO.Abstractions.Results;
3
using
Dreamine.IO.Fastech.Ethernet.Controllers;
4
using
Dreamine.IO.Fastech.Ethernet.Options;
5
using
Dreamine.IO.Fastech.Ethernet.Protocol;
6
using
Dreamine.IO.Fastech.Ethernet.Transport;
7
8
namespace
Dreamine.FullKit.Tests.IO
;
9
18
public
sealed
class
FastechProtocolTests
19
{
28
[Fact]
29
public
void
BuildReadDigitalInputs_CreatesExpectedFrameShape
()
30
{
31
var frame =
new
FastechPlusE16PointProtocol()
32
.BuildReadDigitalInputs(
new
[] {
new
IoPoint(0, 0) });
33
34
Assert.Equal(0xAA, frame[0]);
35
Assert.Equal(3, frame[1]);
36
Assert.Equal(0x00, frame[3]);
37
Assert.Equal(0xC0, frame[4]);
38
}
39
48
[Fact]
49
public
void
ParseDigitalInputs_ReadsBitsFromInputPayload
()
50
{
51
var protocol =
new
FastechPlusE16PointProtocol();
52
var response =
new
byte
[]
53
{
54
0xAA, 12, 1, 0x00, 0xC0, 0x00,
55
0b0000_0101, 0b0000_0010, 0, 0, 0, 0, 0, 0
56
};
57
58
var result = protocol.ParseDigitalInputs(response, 10);
59
60
Assert.True(result.IsSuccess);
61
Assert.Equal(
new
[] {
true
,
false
,
true
,
false
,
false
,
false
,
false
,
false
,
false
,
true
}, result.Value);
62
}
63
72
[Fact]
73
public
void
BuildWriteDigitalOutputs_RejectsOutOfRangeChannel
()
74
{
75
var protocol =
new
FastechPlusE16PointProtocol();
76
var values =
new
Dictionary<IoPoint, bool>
77
{
78
[
new
IoPoint(0, 16)] =
true
79
};
80
81
Assert.Throws<ArgumentOutOfRangeException>(() => protocol.BuildWriteDigitalOutputs(values));
82
}
83
92
[Fact]
93
public
void
PlusE16PointProtocol_ReportsAnalogUnsupportedConsistently
()
94
{
95
var protocol =
new
FastechPlusE16PointProtocol();
96
var point =
new
AnalogIoPoint(0, 0);
97
98
var inputException = Assert.Throws<NotSupportedException>(() => protocol.BuildReadAnalogInputs([point]));
99
var inputParse = protocol.ParseAnalogInputs([], 1);
100
var outputException = Assert.Throws<NotSupportedException>(() => protocol.BuildReadAnalogOutputs([point]));
101
var outputParse = protocol.ParseAnalogOutputs([], 1);
102
103
Assert.Equal(inputException.Message, inputParse.Message);
104
Assert.Equal(outputException.Message, outputParse.Message);
105
Assert.False(inputParse.IsSuccess);
106
Assert.False(outputParse.IsSuccess);
107
}
108
117
[Fact]
118
public
void
UnsupportedProtocol_ReturnsFailuresForParseMethods
()
119
{
120
var protocol =
new
UnsupportedFastechEthernetIoProtocol();
121
122
Assert.False(protocol.ParseDigitalInputs(Array.Empty<
byte
>(), 1).IsSuccess);
123
Assert.False(protocol.ParseDigitalOutputs(Array.Empty<
byte
>(), 1).IsSuccess);
124
Assert.False(protocol.ParseAnalogInputs(Array.Empty<
byte
>(), 1).IsSuccess);
125
Assert.Throws<NotSupportedException>(() => protocol.BuildReadDigitalInputs(Array.Empty<IoPoint>()));
126
}
127
144
[Fact]
145
public
async Task
Controller_ReturnsFailureWhenParserThrows
()
146
{
147
var transport =
new
FakeFastechTransport
();
148
await
using
var controller =
new
FastechEthernetIoController(
149
new
FastechEthernetIoOptions(),
150
transport,
151
new
ThrowingParseProtocol
());
152
153
await controller.ConnectAsync();
154
155
var result = await controller.DigitalInputs.ReadAsync([
new
IoPoint(0, 0)]);
156
157
Assert.False(result.IsSuccess);
158
Assert.Contains(
"parse failed"
, result.Message);
159
}
160
169
[Fact]
170
public
void
FastechOptions_ExposeDefaults
()
171
{
172
var options =
new
FastechEthernetIoOptions();
173
174
Assert.Equal(
"127.0.0.1"
, options.Host);
175
Assert.Equal(FastechEthernetIoTransportType.Udp, options.TransportType);
176
}
177
186
private
sealed
class
FakeFastechTransport
: IFastechEthernetIoTransport
187
{
196
public
bool
IsConnected
{
get
;
private
set
; }
197
222
public
Task<IoResult>
ConnectAsync
(CancellationToken cancellationToken =
default
)
223
{
224
IsConnected
=
true
;
225
return
Task.FromResult(IoResult.Success());
226
}
227
252
public
Task<IoResult>
DisconnectAsync
(CancellationToken cancellationToken =
default
)
253
{
254
IsConnected
=
false
;
255
return
Task.FromResult(IoResult.Success());
256
}
257
306
public
Task<IoResult<byte[]>>
SendAndReceiveAsync
(
307
IReadOnlyList<byte> requestFrame,
308
int
receiveTimeoutMs,
309
int
expectedResponseLength,
310
CancellationToken cancellationToken =
default
)
311
{
312
return
Task.FromResult(IoResult<
byte
[]>.Success([0xAA, 3, 1, 0, 0xC0, 0]));
313
}
314
331
public
ValueTask
DisposeAsync
()
332
{
333
IsConnected
=
false
;
334
return
ValueTask.CompletedTask;
335
}
336
}
337
346
private
sealed
class
ThrowingParseProtocol
: IFastechEthernetIoProtocol
347
{
372
public
byte
[]
BuildReadDigitalInputs
(IReadOnlyList<IoPoint> points)
373
{
374
return
[1];
375
}
376
417
public
IoResult<bool[]>
ParseDigitalInputs
(IReadOnlyList<byte> responseFrame,
int
count)
418
{
419
throw
new
InvalidOperationException(
"parse failed"
);
420
}
421
446
public
byte
[]
BuildReadDigitalOutputs
(IReadOnlyList<IoPoint> points)
447
{
448
return
[1];
449
}
450
483
public
IoResult<bool[]>
ParseDigitalOutputs
(IReadOnlyList<byte> responseFrame,
int
count)
484
{
485
return
IoResult<bool[]>.Success([]);
486
}
487
512
public
byte
[]
BuildWriteDigitalOutputs
(IReadOnlyDictionary<IoPoint, bool> values)
513
{
514
return
[1];
515
}
516
541
public
byte
[]
BuildReadAnalogInputs
(IReadOnlyList<AnalogIoPoint> points)
542
{
543
return
[1];
544
}
545
578
public
IoResult<double[]>
ParseAnalogInputs
(IReadOnlyList<byte> responseFrame,
int
count)
579
{
580
return
IoResult<double[]>.Success([]);
581
}
582
607
public
byte
[]
BuildReadAnalogOutputs
(IReadOnlyList<AnalogIoPoint> points)
608
{
609
return
[1];
610
}
611
644
public
IoResult<double[]>
ParseAnalogOutputs
(IReadOnlyList<byte> responseFrame,
int
count)
645
{
646
return
IoResult<double[]>.Success([]);
647
}
648
673
public
byte
[]
BuildWriteAnalogOutputs
(IReadOnlyDictionary<AnalogIoPoint, double> values)
674
{
675
return
[1];
676
}
677
702
public
IoResult
ParseWriteResponse
(IReadOnlyList<byte> responseFrame)
703
{
704
return
IoResult.Success();
705
}
706
}
707
}
Dreamine.FullKit.Tests.IO
Definition
FastechProtocolTests.cs:8
Dreamine.FullKit.Tests.IO.FastechProtocolTests
Definition
FastechProtocolTests.cs:19
Dreamine.FullKit.Tests.IO.FastechProtocolTests.PlusE16PointProtocol_ReportsAnalogUnsupportedConsistently
void PlusE16PointProtocol_ReportsAnalogUnsupportedConsistently()
Definition
FastechProtocolTests.cs:93
Dreamine.FullKit.Tests.IO.FastechProtocolTests.UnsupportedProtocol_ReturnsFailuresForParseMethods
void UnsupportedProtocol_ReturnsFailuresForParseMethods()
Definition
FastechProtocolTests.cs:118
Dreamine.FullKit.Tests.IO.FastechProtocolTests.BuildReadDigitalInputs_CreatesExpectedFrameShape
void BuildReadDigitalInputs_CreatesExpectedFrameShape()
Definition
FastechProtocolTests.cs:29
Dreamine.FullKit.Tests.IO.FastechProtocolTests.Controller_ReturnsFailureWhenParserThrows
async Task Controller_ReturnsFailureWhenParserThrows()
Definition
FastechProtocolTests.cs:145
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ParseDigitalInputs_ReadsBitsFromInputPayload
void ParseDigitalInputs_ReadsBitsFromInputPayload()
Definition
FastechProtocolTests.cs:49
Dreamine.FullKit.Tests.IO.FastechProtocolTests.FastechOptions_ExposeDefaults
void FastechOptions_ExposeDefaults()
Definition
FastechProtocolTests.cs:170
Dreamine.FullKit.Tests.IO.FastechProtocolTests.BuildWriteDigitalOutputs_RejectsOutOfRangeChannel
void BuildWriteDigitalOutputs_RejectsOutOfRangeChannel()
Definition
FastechProtocolTests.cs:73
Dreamine.FullKit.Tests.IO.FastechProtocolTests.FakeFastechTransport
Definition
FastechProtocolTests.cs:187
Dreamine.FullKit.Tests.IO.FastechProtocolTests.FakeFastechTransport.ConnectAsync
Task< IoResult > ConnectAsync(CancellationToken cancellationToken=default)
Definition
FastechProtocolTests.cs:222
Dreamine.FullKit.Tests.IO.FastechProtocolTests.FakeFastechTransport.DisconnectAsync
Task< IoResult > DisconnectAsync(CancellationToken cancellationToken=default)
Definition
FastechProtocolTests.cs:252
Dreamine.FullKit.Tests.IO.FastechProtocolTests.FakeFastechTransport.IsConnected
bool IsConnected
Definition
FastechProtocolTests.cs:196
Dreamine.FullKit.Tests.IO.FastechProtocolTests.FakeFastechTransport.SendAndReceiveAsync
Task< IoResult< byte[]> > SendAndReceiveAsync(IReadOnlyList< byte > requestFrame, int receiveTimeoutMs, int expectedResponseLength, CancellationToken cancellationToken=default)
Definition
FastechProtocolTests.cs:306
Dreamine.FullKit.Tests.IO.FastechProtocolTests.FakeFastechTransport.DisposeAsync
ValueTask DisposeAsync()
Definition
FastechProtocolTests.cs:331
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol
Definition
FastechProtocolTests.cs:347
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol.BuildReadAnalogOutputs
byte[] BuildReadAnalogOutputs(IReadOnlyList< AnalogIoPoint > points)
Definition
FastechProtocolTests.cs:607
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol.BuildReadAnalogInputs
byte[] BuildReadAnalogInputs(IReadOnlyList< AnalogIoPoint > points)
Definition
FastechProtocolTests.cs:541
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol.ParseWriteResponse
IoResult ParseWriteResponse(IReadOnlyList< byte > responseFrame)
Definition
FastechProtocolTests.cs:702
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol.ParseAnalogInputs
IoResult< double[]> ParseAnalogInputs(IReadOnlyList< byte > responseFrame, int count)
Definition
FastechProtocolTests.cs:578
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol.BuildReadDigitalOutputs
byte[] BuildReadDigitalOutputs(IReadOnlyList< IoPoint > points)
Definition
FastechProtocolTests.cs:446
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol.BuildWriteDigitalOutputs
byte[] BuildWriteDigitalOutputs(IReadOnlyDictionary< IoPoint, bool > values)
Definition
FastechProtocolTests.cs:512
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol.ParseAnalogOutputs
IoResult< double[]> ParseAnalogOutputs(IReadOnlyList< byte > responseFrame, int count)
Definition
FastechProtocolTests.cs:644
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol.ParseDigitalInputs
IoResult< bool[]> ParseDigitalInputs(IReadOnlyList< byte > responseFrame, int count)
Definition
FastechProtocolTests.cs:417
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol.ParseDigitalOutputs
IoResult< bool[]> ParseDigitalOutputs(IReadOnlyList< byte > responseFrame, int count)
Definition
FastechProtocolTests.cs:483
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol.BuildReadDigitalInputs
byte[] BuildReadDigitalInputs(IReadOnlyList< IoPoint > points)
Definition
FastechProtocolTests.cs:372
Dreamine.FullKit.Tests.IO.FastechProtocolTests.ThrowingParseProtocol.BuildWriteAnalogOutputs
byte[] BuildWriteAnalogOutputs(IReadOnlyDictionary< AnalogIoPoint, double > values)
Definition
FastechProtocolTests.cs:673
IO
FastechProtocolTests.cs
다음에 의해 생성됨 :
1.17.0