@@ -202,85 +202,292 @@ public void TestFilterVersionBValidAliasAndName()
202
202
Assert . IsTrue ( node . KnownMetrics . Count ( ) == 1 ) ;
203
203
204
204
// Test filter function.
205
- var filteredMetrics = node . KnownMetricsStorage . FilterMetrics ( filterMetrics , SparkplugMessageType . NodeData ) ;
205
+ var filteredMetrics = node . KnownMetricsStorage . FilterMetrics ( filterMetrics , SparkplugMessageType . NodeBirth ) ;
206
206
Assert . IsTrue ( filteredMetrics . Count ( ) == 1 ) ;
207
207
}
208
208
209
+ /// <summary>
210
+ /// Tests the version B metric storage with an invalid metric (Alias and name not set).
211
+ /// </summary>
212
+ [ TestMethod ]
213
+ public void TestFilterVersionBInvalidAliasAndNameNotSet ( )
214
+ {
215
+ var metric = new VersionBData . Metric ( "TestMetric1" , VersionBData . DataType . Double , 123.45 )
216
+ {
217
+ Alias = 1
218
+ } ;
219
+ IEnumerable < VersionBData . Metric > metrics =
220
+ [
221
+ metric
222
+ ] ;
223
+
224
+ IEnumerable < VersionBData . Metric > filterMetrics =
225
+ [
226
+ new ( string . Empty , VersionBData . DataType . Double , 128.56 )
227
+ ] ;
228
+
229
+ var node = new VersionBMain . SparkplugNode ( metrics , SparkplugSpecificationVersion . Version30 ) ;
230
+ Assert . IsNotNull ( node ) ;
231
+ Assert . IsTrue ( node . KnownMetrics . Count ( ) == 1 ) ;
232
+
233
+ // Test filter function.
234
+ var filteredMetrics = node . KnownMetricsStorage . FilterMetrics ( filterMetrics , SparkplugMessageType . NodeData ) ;
235
+ Assert . IsTrue ( ! filteredMetrics . Any ( ) ) ;
236
+ }
237
+
238
+ /// <summary>
239
+ /// Tests the version B metric storage with an invalid metric, alias not set (Name is unknown).
240
+ /// </summary>
241
+ [ TestMethod ]
242
+ public void TestFilterVersionBInvalidAliasNotSetAndUnknownName ( )
243
+ {
244
+ var metric = new VersionBData . Metric ( "TestMetric1" , VersionBData . DataType . Double , 123.45 )
245
+ {
246
+ Alias = 1
247
+ } ;
248
+ IEnumerable < VersionBData . Metric > metrics =
249
+ [
250
+ metric
251
+ ] ;
252
+
253
+ IEnumerable < VersionBData . Metric > filterMetrics =
254
+ [
255
+ new ( "TestMetric2" , VersionBData . DataType . Double , 128.56 )
256
+ ] ;
257
+
258
+ var node = new VersionBMain . SparkplugNode ( metrics , SparkplugSpecificationVersion . Version30 ) ;
259
+ Assert . IsNotNull ( node ) ;
260
+ Assert . IsTrue ( node . KnownMetrics . Count ( ) == 1 ) ;
261
+
262
+ // Test filter function.
263
+ var filteredMetrics = node . KnownMetricsStorage . FilterMetrics ( filterMetrics , SparkplugMessageType . NodeData ) ;
264
+ Assert . IsTrue ( ! filteredMetrics . Any ( ) ) ;
265
+ }
266
+
267
+ /// <summary>
268
+ /// Tests the version B metric storage with an invalid metric, alias not set (Data type is unknown).
269
+ /// </summary>
270
+ [ TestMethod ]
271
+ public void TestFilterVersionBInvalidAliasNotSetAndUnknownDataType ( )
272
+ {
273
+ var metric = new VersionBData . Metric ( "TestMetric1" , VersionBData . DataType . Double , 123.45 )
274
+ {
275
+ Alias = 1
276
+ } ;
277
+ IEnumerable < VersionBData . Metric > metrics =
278
+ [
279
+ metric
280
+ ] ;
281
+
282
+ IEnumerable < VersionBData . Metric > filterMetrics =
283
+ [
284
+ new ( "TestMetric1" , VersionBData . DataType . Float , 128.56f )
285
+ ] ;
286
+
287
+ var node = new VersionBMain . SparkplugNode ( metrics , SparkplugSpecificationVersion . Version30 ) ;
288
+ Assert . IsNotNull ( node ) ;
289
+ Assert . IsTrue ( node . KnownMetrics . Count ( ) == 1 ) ;
290
+
291
+ // Test filter function.
292
+ var filteredMetrics = node . KnownMetricsStorage . FilterMetrics ( filterMetrics , SparkplugMessageType . NodeData ) ;
293
+ Assert . IsTrue ( ! filteredMetrics . Any ( ) ) ;
294
+ }
295
+
296
+ /// <summary>
297
+ /// Tests the version B metric storage with an invalid metric, name not set (NBIRTH with an alias only).
298
+ /// </summary>
299
+ [ TestMethod ]
300
+ public void TestFilterVersionBInvalidNameNotSetNbirthWithAliasOnly ( )
301
+ {
302
+ var metric = new VersionBData . Metric ( "TestMetric1" , VersionBData . DataType . Double , 123.45 )
303
+ {
304
+ Alias = 1
305
+ } ;
306
+ IEnumerable < VersionBData . Metric > metrics =
307
+ [
308
+ metric
309
+ ] ;
310
+
311
+ var filterMetric = new VersionBData . Metric ( string . Empty , VersionBData . DataType . Double , 128.56 )
312
+ {
313
+ Alias = 1
314
+ } ;
315
+ IEnumerable < VersionBData . Metric > filterMetrics =
316
+ [
317
+ filterMetric
318
+ ] ;
319
+
320
+ var node = new VersionBMain . SparkplugNode ( metrics , SparkplugSpecificationVersion . Version30 ) ;
321
+ Assert . IsNotNull ( node ) ;
322
+ Assert . IsTrue ( node . KnownMetrics . Count ( ) == 1 ) ;
323
+
324
+ // Test filter function.
325
+ var filteredMetrics = node . KnownMetricsStorage . FilterMetrics ( filterMetrics , SparkplugMessageType . NodeBirth ) ;
326
+ Assert . IsTrue ( ! filteredMetrics . Any ( ) ) ;
327
+ }
328
+
329
+ /// <summary>
330
+ /// Tests the version B metric storage with an invalid metric, name not set (The alias is unknown).
331
+ /// </summary>
332
+ [ TestMethod ]
333
+ public void TestFilterVersionBInvalidNameNotSetUnknownAlias ( )
334
+ {
335
+ var metric = new VersionBData . Metric ( "TestMetric1" , VersionBData . DataType . Double , 123.45 )
336
+ {
337
+ Alias = 1
338
+ } ;
339
+ IEnumerable < VersionBData . Metric > metrics =
340
+ [
341
+ metric
342
+ ] ;
343
+
344
+ var filterMetric = new VersionBData . Metric ( string . Empty , VersionBData . DataType . Double , 128.56 )
345
+ {
346
+ Alias = 2
347
+ } ;
348
+ IEnumerable < VersionBData . Metric > filterMetrics =
349
+ [
350
+ filterMetric
351
+ ] ;
352
+
353
+ var node = new VersionBMain . SparkplugNode ( metrics , SparkplugSpecificationVersion . Version30 ) ;
354
+ Assert . IsNotNull ( node ) ;
355
+ Assert . IsTrue ( node . KnownMetrics . Count ( ) == 1 ) ;
356
+
357
+ // Test filter function.
358
+ var filteredMetrics = node . KnownMetricsStorage . FilterMetrics ( filterMetrics , SparkplugMessageType . NodeData ) ;
359
+ Assert . IsTrue ( ! filteredMetrics . Any ( ) ) ;
360
+ }
361
+
362
+ /// <summary>
363
+ /// Tests the version B metric storage with an invalid metric, name not set (Data type is unknown).
364
+ /// </summary>
365
+ [ TestMethod ]
366
+ public void TestFilterVersionBInvalidNameNotSetUnknownDataType ( )
367
+ {
368
+ var metric = new VersionBData . Metric ( "TestMetric1" , VersionBData . DataType . Double , 123.45 )
369
+ {
370
+ Alias = 1
371
+ } ;
372
+ IEnumerable < VersionBData . Metric > metrics =
373
+ [
374
+ metric
375
+ ] ;
376
+
377
+ var filterMetric = new VersionBData . Metric ( string . Empty , VersionBData . DataType . Float , 128.56f )
378
+ {
379
+ Alias = 1
380
+ } ;
381
+ IEnumerable < VersionBData . Metric > filterMetrics =
382
+ [
383
+ filterMetric
384
+ ] ;
385
+
386
+ var node = new VersionBMain . SparkplugNode ( metrics , SparkplugSpecificationVersion . Version30 ) ;
387
+ Assert . IsNotNull ( node ) ;
388
+ Assert . IsTrue ( node . KnownMetrics . Count ( ) == 1 ) ;
389
+
390
+ // Test filter function.
391
+ var filteredMetrics = node . KnownMetricsStorage . FilterMetrics ( filterMetrics , SparkplugMessageType . NodeData ) ;
392
+ Assert . IsTrue ( ! filteredMetrics . Any ( ) ) ;
393
+ }
394
+
395
+ /// <summary>
396
+ /// Tests the version B metric storage with an invalid metric, name and alias set (NDATA message with alias and name).
397
+ /// </summary>
398
+ [ TestMethod ]
399
+ public void TestFilterVersionBInvalidNameAndAliasSetNDataWithAliasAndName ( )
400
+ {
401
+ var metric = new VersionBData . Metric ( "TestMetric1" , VersionBData . DataType . Double , 123.45 )
402
+ {
403
+ Alias = 1
404
+ } ;
405
+ IEnumerable < VersionBData . Metric > metrics =
406
+ [
407
+ metric
408
+ ] ;
409
+
410
+ var filterMetric = new VersionBData . Metric ( "TestMetric1" , VersionBData . DataType . Double , 128.56 )
411
+ {
412
+ Alias = 1
413
+ } ;
414
+ IEnumerable < VersionBData . Metric > filterMetrics =
415
+ [
416
+ filterMetric
417
+ ] ;
418
+
419
+ var node = new VersionBMain . SparkplugNode ( metrics , SparkplugSpecificationVersion . Version30 ) ;
420
+ Assert . IsNotNull ( node ) ;
421
+ Assert . IsTrue ( node . KnownMetrics . Count ( ) == 1 ) ;
422
+
423
+ // Test filter function.
424
+ var filteredMetrics = node . KnownMetricsStorage . FilterMetrics ( filterMetrics , SparkplugMessageType . NodeData ) ;
425
+ Assert . IsTrue ( ! filteredMetrics . Any ( ) ) ;
426
+ }
427
+
428
+ /// <summary>
429
+ /// Tests the version B metric storage with an invalid metric, name and alias set (Name is unknown).
430
+ /// </summary>
431
+ [ TestMethod ]
432
+ public void TestFilterVersionBInvalidNameAndAliasSetUnknownName ( )
433
+ {
434
+ var metric = new VersionBData . Metric ( "TestMetric1" , VersionBData . DataType . Double , 123.45 )
435
+ {
436
+ Alias = 1
437
+ } ;
438
+ IEnumerable < VersionBData . Metric > metrics =
439
+ [
440
+ metric
441
+ ] ;
209
442
443
+ var filterMetric = new VersionBData . Metric ( "TestMetric2" , VersionBData . DataType . Double , 128.56 )
444
+ {
445
+ Alias = 1
446
+ } ;
447
+ IEnumerable < VersionBData . Metric > filterMetrics =
448
+ [
449
+ filterMetric
450
+ ] ;
210
451
452
+ var node = new VersionBMain . SparkplugNode ( metrics , SparkplugSpecificationVersion . Version30 ) ;
453
+ Assert . IsNotNull ( node ) ;
454
+ Assert . IsTrue ( node . KnownMetrics . Count ( ) == 1 ) ;
211
455
456
+ // Test filter function.
457
+ var filteredMetrics = node . KnownMetricsStorage . FilterMetrics ( filterMetrics , SparkplugMessageType . NodeBirth ) ;
458
+ Assert . IsTrue ( ! filteredMetrics . Any ( ) ) ;
459
+ }
212
460
461
+ /// <summary>
462
+ /// Tests the version B metric storage with an invalid metric, name and alias set (Data type is unknown).
463
+ /// </summary>
464
+ [ TestMethod ]
465
+ public void TestFilterVersionBInvalidNameAndAliasSetUnknownDataType ( )
466
+ {
467
+ var metric = new VersionBData . Metric ( "TestMetric1" , VersionBData . DataType . Double , 123.45 )
468
+ {
469
+ Alias = 1
470
+ } ;
471
+ IEnumerable < VersionBData . Metric > metrics =
472
+ [
473
+ metric
474
+ ] ;
213
475
214
- ///// <summary>
215
- ///// Tests the version B metric storage with a valid metric (Name only).
216
- ///// </summary>
217
- //[TestMethod]
218
- //public void TestFilterVersionBValidMetricNameOnly()
219
- //{
220
- // IEnumerable<VersionBData.Metric> metrics =
221
- // [
222
- // new("TestMetric1", VersionBData.DataType.Double, 123.45)
223
- // ];
224
-
225
- // var node = new VersionBMain.SparkplugNode(metrics, SparkplugSpecificationVersion.Version30);
226
- // Assert.IsNotNull(node);
227
- // Assert.IsTrue(node.KnownMetrics.Count() == 1);
228
- //}
229
-
230
- ///// <summary>
231
- ///// Tests the version B metric storage with a valid metric (Alias only).
232
- ///// </summary>
233
- //[TestMethod]
234
- //public void TestFilterVersionBValidMetricAliasOnly()
235
- //{
236
- // var metric = new VersionBData.Metric(string.Empty, VersionBData.DataType.Double, 123.45)
237
- // {
238
- // Alias = 1
239
- // };
240
-
241
- // IEnumerable<VersionBData.Metric> metrics =
242
- // [
243
- // metric
244
- // ];
245
-
246
- // var node = new VersionBMain.SparkplugNode(metrics, SparkplugSpecificationVersion.Version30);
247
- // Assert.IsNotNull(node);
248
- // Assert.IsTrue(node.KnownMetrics.Count() == 1);
249
- //}
250
-
251
- ///// <summary>
252
- ///// Tests the version B metric storage with a valid metric (Name and alias).
253
- ///// </summary>
254
- //[TestMethod]
255
- //public void TestFilterVersionBValidMetricNameAndAlias()
256
- //{
257
- // var metric = new VersionBData.Metric("TestMetric1", VersionBData.DataType.Double, 123.45)
258
- // {
259
- // Alias = 1
260
- // };
261
-
262
- // IEnumerable<VersionBData.Metric> metrics =
263
- // [
264
- // metric
265
- // ];
266
-
267
- // var node = new VersionBMain.SparkplugNode(metrics, SparkplugSpecificationVersion.Version30);
268
- // Assert.IsNotNull(node);
269
- // Assert.IsTrue(node.KnownMetrics.Count() == 1);
270
- //}
271
-
272
- ///// <summary>
273
- ///// Tests the version B metric storage with an invalid metric.
274
- ///// </summary>
275
- //[TestMethod]
276
- //[ExpectedException(typeof(InvalidMetricException))]
277
- //public void TestFilterVersionBInvalidMetric()
278
- //{
279
- // IEnumerable<VersionBData.Metric> metrics =
280
- // [
281
- // new(string.Empty, VersionBData.DataType.Double, 123.45)
282
- // ];
283
-
284
- // _ = new VersionBMain.SparkplugNode(metrics, SparkplugSpecificationVersion.Version30);
285
- //}
476
+ var filterMetric = new VersionBData . Metric ( "TestMetric1" , VersionBData . DataType . Float , 128.56f )
477
+ {
478
+ Alias = 1
479
+ } ;
480
+ IEnumerable < VersionBData . Metric > filterMetrics =
481
+ [
482
+ filterMetric
483
+ ] ;
484
+
485
+ var node = new VersionBMain . SparkplugNode ( metrics , SparkplugSpecificationVersion . Version30 ) ;
486
+ Assert . IsNotNull ( node ) ;
487
+ Assert . IsTrue ( node . KnownMetrics . Count ( ) == 1 ) ;
488
+
489
+ // Test filter function.
490
+ var filteredMetrics = node . KnownMetricsStorage . FilterMetrics ( filterMetrics , SparkplugMessageType . NodeBirth ) ;
491
+ Assert . IsTrue ( ! filteredMetrics . Any ( ) ) ;
492
+ }
286
493
}
0 commit comments