-
Notifications
You must be signed in to change notification settings - Fork 553
/
DataDictionaryTests.cs
735 lines (601 loc) · 33.2 KB
/
DataDictionaryTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using NUnit.Framework;
using QuickFix;
using UnitTests.TestHelpers;
namespace UnitTests
{
[TestFixture]
public class DataDictionaryTests
{
private QuickFix.IMessageFactory _defaultMsgFactory = new QuickFix.DefaultMessageFactory();
private const char NUL = Message.SOH;
[Test]
public void VersionTest()
{
QuickFix.DataDictionary.DataDictionary dd44 = new QuickFix.DataDictionary.DataDictionary();
dd44.LoadFIXSpec("FIX44");
Assert.That(dd44.MajorVersion, Is.EqualTo("4"));
Assert.That(dd44.MinorVersion, Is.EqualTo("4"));
Assert.That(dd44.Version, Is.EqualTo("FIX.4.4"));
}
[Test]
public void LoadFieldsTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.That(dd.FieldsByTag[1].Name, Is.EqualTo("Account"));
Assert.That(dd.FieldsByName["Account"].Tag, Is.EqualTo(1));
Assert.That(dd.FieldsByTag[1].EnumDict.Count, Is.EqualTo(0));
Assert.That(dd.FieldsByTag[QuickFix.Fields.Tags.StatusValue].EnumDict.Count, Is.EqualTo(4));
}
[Test]
public void LoadFieldsFromStreamTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
Stream stream = new FileStream(Path.Combine(TestContext.CurrentContext.TestDirectory, "spec", "fix", "FIX44.xml"), FileMode.Open, FileAccess.Read);
dd.Load(stream);
Assert.That(dd.FieldsByTag[1].Name, Is.EqualTo("Account"));
Assert.That(dd.FieldsByName["Account"].Tag, Is.EqualTo(1));
Assert.That(dd.FieldsByTag[1].EnumDict.Count, Is.EqualTo(0));
Assert.That(dd.FieldsByTag[QuickFix.Fields.Tags.StatusValue].EnumDict.Count, Is.EqualTo(4));
}
[Test]
public void FieldHasValueTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.That(dd.FieldHasValue(QuickFix.Fields.Tags.StatusValue, "1"), Is.EqualTo(true));
Assert.That(dd.FieldHasValue(QuickFix.Fields.Tags.StatusValue, "CONNECTED"), Is.EqualTo(false));
Assert.False(dd.FieldsByTag[1].HasEnums());
Assert.True(dd.FieldsByTag[945].HasEnums());
}
[Test]
public void FieldHasDescriptionTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.AreEqual(typeof (Dictionary<string, string>), dd.FieldsByTag[945].EnumDict.GetType());
Assert.That("COMPLETED", Is.EqualTo(dd.FieldsByTag[945].EnumDict["2"]));
Assert.AreNotEqual("HEARTBEAT", dd.FieldsByTag[35].EnumDict["A"]);
}
[Test]
public void BasicMessageTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.That(dd.Messages["3"].Fields.Count, Is.EqualTo(7));
}
[Test]
public void ComponentSmokeTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.DataDictionary.DDMap tcr = dd.Messages["AE"];
Assert.True(tcr.Fields.ContainsKey(55));
Assert.False(tcr.Fields.ContainsKey(5995));
}
[Test]
public void GroupTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.DataDictionary.DDMap tcrr = dd.Messages["AD"];
Assert.True(tcrr.IsGroup(711));
Assert.True(tcrr.IsField(711)); // No Field also a field
Assert.True(tcrr.GetGroup(711).IsField(311));
Assert.That(tcrr.Groups[711].Fields[311].Name, Is.EqualTo("UnderlyingSymbol"));
Assert.That(tcrr.Groups[711].Delim, Is.EqualTo(311));
QuickFix.DataDictionary.DDMap tcr = dd.Messages["AE"];
Assert.That(tcr.Groups[711].Groups[457].Fields[458].Name, Is.EqualTo("UnderlyingSecurityAltID"));
}
[Test]
public void NestedGroupTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.DataDictionary.DDMap msgJ = dd.Messages["J"];
Assert.True(msgJ.IsGroup(73));
Assert.False(msgJ.IsGroup(756));
Assert.True(msgJ.GetGroup(73).IsGroup(756));
}
[Test]
public void GroupBeginsGroupTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadTestFIXSpec("group_begins_group");
QuickFix.DataDictionary.DDMap msg = dd.Messages["magic"];
Assert.True(msg.IsGroup(6660)); // NoMagics group
Assert.True(msg.GetGroup(6660).IsGroup(7770)); // NoMagics/NoRabbits
Assert.True(msg.GetGroup(6660).IsField(6661)); // NoMagics/MagicWord
Assert.True(msg.GetGroup(6660).GetGroup(7770).IsField(7711)); // NoMagics/NoRabbits/RabbitName
Assert.AreEqual(7770, msg.GetGroup(6660).Delim); // NoMagics delim is NoRabbits counter
Assert.AreEqual(7711, msg.GetGroup(6660).GetGroup(7770).Delim); // NoRabbits delim is RabbitName
}
[Test]
public void HeaderGroupTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.DataDictionary.DDMap headerMap = dd.Header;
Assert.True(headerMap.IsGroup(627));
QuickFix.DataDictionary.DDGrp grpMap = headerMap.GetGroup(627);
Assert.True(dd.Header.GetGroup(627).IsField(628));
Assert.True(grpMap.IsField(628));
}
[Test]
public void ReqFldTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.True(dd.Messages["AE"].ReqFields.Contains(571));
Assert.False(dd.Messages["AE"].ReqFields.Contains(828));
}
[Test]
public void HeaderTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.True(dd.Header.ReqFields.Contains(9));
Assert.That(dd.Header.Fields.Count, Is.EqualTo(27));
}
[Test]
public void TrailerTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.True(dd.Trailer.ReqFields.Contains(10));
Assert.That(dd.Trailer.Fields.Count, Is.EqualTo(3));
}
[Test]
public void CheckValidFormat()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
dd.CheckFieldsHaveValues = true;
var goodFields = new QuickFix.Fields.StringField[] {
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.Symbol, "foo"), // string
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.Side, "2"), // char
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.LastQty, "123"), // int
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.AvgPx, "1.23"), // decimal
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.ReportToExch, "Y"), // bool
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.ContraTradeTime, "20011217-09:30:47.123"), // datetime
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.MDEntryDate, "20030910"), // dateonly
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.MDEntryTime, "13:20:00.123"), // timeonly
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.Symbol, "") // string
};
foreach (var datum in goodFields)
{
Assert.DoesNotThrow(delegate { dd.CheckValidFormat(datum); });
}
var badFields = new QuickFix.Fields.StringField[]
{
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.Side, "toolong"), // char
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.LastQty, "notint"), // int
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.AvgPx, "notdec"), // decimal
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.ReportToExch, "notbool"), // bool
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.ContraTradeTime, "notdatetime"), // datetime
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.MDEntryDate, "notdate"), // dateonly
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.MDEntryTime, "nottime") // timeonly
};
foreach (var datum in badFields)
{
Assert.Throws(typeof(IncorrectDataFormat), delegate { dd.CheckValidFormat(datum); });
}
var emptyFields = new QuickFix.Fields.StringField[]
{
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.Side, ""), // char
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.LastQty, ""), // int
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.AvgPx, ""), // decimal
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.ReportToExch, ""), // bool
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.ContraTradeTime, ""), // datetime
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.MDEntryDate, ""), // dateonly
new QuickFix.Fields.StringField(QuickFix.Fields.Tags.MDEntryTime, "") // timeonly
};
foreach (var datum in emptyFields)
{
Assert.Throws(typeof(IncorrectDataFormat), delegate { dd.CheckValidFormat(datum); });
}
// Setting change!
dd.CheckFieldsHaveValues = false;
foreach (var datum in emptyFields)
{
Assert.DoesNotThrow(delegate { dd.CheckValidFormat(datum); });
}
}
[Test]
public void CheckValidTagNumberTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.DoesNotThrow(delegate { dd.CheckValidTagNumber(35); });
Assert.Throws(typeof(InvalidTagNumber),
delegate { dd.CheckValidTagNumber(999); });
dd.AllowUnknownMessageFields = true;
Assert.DoesNotThrow(delegate { dd.CheckValidTagNumber(999); });
}
[Test]
public void CheckValue()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
// unknown field
Assert.DoesNotThrow(delegate { dd.CheckValue(new QuickFix.Fields.CharField(20, '0')); });
// not an enum
Assert.DoesNotThrow(delegate { dd.CheckValue(new QuickFix.Fields.ListSeqNo(5)); });
// regular enum, ok
Assert.DoesNotThrow(delegate { dd.CheckValue(new QuickFix.Fields.TickDirection('2')); });
// multiple-value field, ok
Assert.DoesNotThrow(delegate { dd.CheckValue(new QuickFix.Fields.QuoteCondition("A C D")); });
// regular enum, invalid value
Assert.Throws(typeof(IncorrectTagValue),
delegate { dd.CheckValue(new QuickFix.Fields.TickDirection('9')); });
// multiple-value field, one value is invalid
Assert.Throws(typeof(IncorrectTagValue),
delegate { dd.CheckValue(new QuickFix.Fields.QuoteCondition("A @ D")); });
}
[Test]
public void CheckIsInMessageTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.DoesNotThrow(delegate { dd.CheckIsInMessage(new QuickFix.Fields.MDReqID("foo"), "W"); });
Assert.Throws(typeof(TagNotDefinedForMessage),
delegate { dd.CheckIsInMessage(new QuickFix.Fields.EmailThreadID("foo"), "W"); });
dd.AllowUnknownMessageFields = true;
Assert.DoesNotThrow(delegate { dd.CheckIsInMessage(new QuickFix.Fields.EmailThreadID("foo"), "W"); });
}
[Test]
public void CheckIsInGroupTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.DataDictionary.DDGrp g = dd.Messages["B"].GetGroup(33);
QuickFix.Fields.Text textField = new QuickFix.Fields.Text("woot");
QuickFix.Fields.ClOrdID clOrdIdField = new QuickFix.Fields.ClOrdID("not woot");
Assert.DoesNotThrow(delegate() { dd.CheckIsInGroup(textField, g, "B"); });
Assert.Throws(typeof(TagNotDefinedForMessage), delegate { dd.CheckIsInGroup(clOrdIdField, g, "B"); });
}
[Test]
public void CheckGroupCountTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX42");
QuickFix.FIX42.NewOrderSingle n = new QuickFix.FIX42.NewOrderSingle();
string s = "8=FIX.4.2" + NUL + "9=148" + NUL + "35=D" + NUL + "34=2" + NUL + "49=TW" + NUL + "52=20111011-15:06:23.103" + NUL + "56=ISLD" + NUL
+ "11=ID" + NUL + "21=1" + NUL + "40=1" + NUL + "54=1" + NUL + "38=200.00" + NUL + "55=INTC" + NUL
+ "386=3" + NUL + "336=PRE-OPEN" + NUL + "336=AFTER-HOURS" + NUL
+ "60=20111011-15:06:23.103" + NUL
+ "10=35" + NUL;
n.FromString(s, true, dd, dd, _defaultMsgFactory);
//verify that FromString didn't correct the counter
//HEY YOU, READ THIS NOW: if these fail, first check if MessageTests::FromString_DoNotCorrectCounter() passes
Assert.AreEqual("386=3", n.NoTradingSessions.toStringField());
StringAssert.Contains("386=3", n.ToString());
Assert.Throws<QuickFix.RepeatingGroupCountMismatch>(delegate { dd.CheckGroupCount(n.NoTradingSessions, n, "D"); });
}
[Test]
public void ValidateWrongType()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.FIX44.MessageFactory f = new QuickFix.FIX44.MessageFactory();
string[] msgFields = {"8=FIX.4.4", "9=120", "35=D", "34=3", "49=sender", "52=20110909-09:09:09.999", "56=target",
"11=clordid", "55=sym", "54=1", "60=20110909-09:09:09.999", "40=1",
"38=failboat", // should be a decimal
"10=64"};
string msgStr = string.Join(Message.SOH, msgFields) + Message.SOH;
string msgType = "D";
string beginString = "FIX.4.4";
Message message = f.Create(beginString, msgType);
message.FromString(msgStr, true, dd, dd, f);
Assert.That(() => dd.Validate(message, beginString, msgType), Throws.TypeOf<QuickFix.IncorrectDataFormat>());
}
[Test]
public void ValidateWithRepeatingGroupTest()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX42");
QuickFix.FIX42.MessageFactory f = new QuickFix.FIX42.MessageFactory();
string msgStr = "8=FIX.4.2" + NUL + "9=87" + NUL + "35=B" + NUL + "34=3" + NUL + "49=CLIENT1" + NUL
+ "52=20111012-22:15:55.474" + NUL + "56=EXECUTOR" + NUL + "148=AAAAAAA" + NUL
+ "33=2" + NUL + "58=L1" + NUL + "58=L2" + NUL + "10=016" + NUL;
QuickFix.Fields.MsgType msgType = Message.IdentifyType(msgStr);
string beginString = Message.ExtractBeginString(msgStr);
Message message = f.Create(beginString, msgType.Obj);
message.FromString(msgStr, true, dd, dd, f);
dd.Validate(message, beginString, msgType.Obj);
}
[Test]
public void ValidateGroupBeginsGroup()
{
// TODO: In a future version, change this so that
// 1) generator will generate source for our test DD
// 2) this test will use proper type-safe methods and not generics
// Probably some or all of this would then move to MessageTests.cs
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadTestFIXSpec("group_begins_group");
string pipedStr = "8=FIX.9.9|9=167|35=magic|34=3|49=CLIENT1|52=20111012-22:15:55.474|56=EXECUTOR|"
+ "1111=mundane|5555=magicfield|6660=1|7770=2|7711=Hoppy|7712=brown|"
+ "7711=Floppy|7712=white|6661=abracadabra|10=48|";
// note: length and checksum might be garbage
string msgStr = pipedStr.Replace('|', Message.SOH);
string beginString = Message.ExtractBeginString(msgStr);
Message msg = new Message(msgStr, dd, dd, false);
// true param means body-only, i.e. don't validate length/checksum
dd.Validate(msg, true, beginString, "magic");
// Verify can retrieve one of the inner groups.
// (Gotta use generic methods because code isn't generated for this DD)
Group magicGroup = new Group(6660, 7770, new[] { 7770, 6661 });
msg.GetGroup(1, magicGroup);
Group rabbitGroup = new Group(7770, 7711, new[] { 7711, 7722 });
magicGroup.GetGroup(2, rabbitGroup);
Assert.AreEqual("abracadabra", magicGroup.GetString(6661));
Assert.AreEqual("Floppy", rabbitGroup.GetString(7711));
Assert.AreEqual("white", rabbitGroup.GetString(7712));
}
[Test]
public void ValidateWrongTypeInRepeatingGroup()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.FIX44.MessageFactory f = new QuickFix.FIX44.MessageFactory();
string[] msgFields = {"8=FIX.4.4", "9=111", "35=V", "34=3", "49=sender", "52=20110909-09:09:09.999", "56=target",
"262=mdreqid", "263=0", "264=5",
"267=1", // MDReqGrp
"269=failboat", // should be a char
"146=1", // InstrmtMDReqGrp
"55=sym",
"10=91"};
string msgStr = string.Join(Message.SOH, msgFields) + Message.SOH;
string msgType = "V";
string beginString = "FIX.4.4";
Message message = f.Create(beginString, msgType);
message.FromString(msgStr, true, dd, dd, f);
Assert.That(() => dd.Validate(message, beginString, msgType), Throws.TypeOf<QuickFix.IncorrectDataFormat>());
}
[Test]
public void ValidateWrongTypeInNestedRepeatingGroup()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.FIX44.MessageFactory f = new QuickFix.FIX44.MessageFactory();
string[] msgFields = {"8=FIX.4.4", "9=185", "35=J", "34=3", "49=sender", "52=20110909-09:09:09.999", "56=target",
"70=AllocID", "71=0", "626=1", "857=0", "54=1", "55=sym", "53=1", "6=5.5", "75=20110909-09:09:09.999",
"73=1", // NoOrders
"11=clordid",
"756=1", // NoNested2PartyIDs
"757=nested2partyid",
"759=failboat", // supposed to be a int
"10=48"};
string msgStr = string.Join(Message.SOH, msgFields) + Message.SOH;
string msgType = "J";
string beginString = "FIX.4.4";
Message message = f.Create(beginString, msgType);
message.FromString(msgStr, true, dd, dd, f);
Assert.That(() => dd.Validate(message, beginString, msgType), Throws.TypeOf<QuickFix.IncorrectDataFormat>());
}
[Test]
public void ValidateDateAndTimeFields()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.FIX44.MessageFactory f = new QuickFix.FIX44.MessageFactory();
string[] msgFields = { "8=FIX.4.4", "9=104", "35=W", "34=3", "49=sender", "52=20110909-09:09:09.999", "56=target",
"55=sym", "268=1", "269=0", "272=20111012", "273=22:15:30.444", "10=19" };
string msgStr = string.Join(Message.SOH, msgFields) + Message.SOH;
string msgType = "W";
string beginString = "FIX.4.4";
Message message = f.Create(beginString, msgType);
message.FromString(msgStr, true, dd, dd, f);
try
{
dd.Validate(message, beginString, msgType);
}
catch (QuickFix.TagException e)
{
Console.WriteLine(e.ToString());
Console.WriteLine(e.Field);
throw;
}
}
[Test]
public void ValidateDateTime_Invalid()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.FIX44.MessageFactory f = new QuickFix.FIX44.MessageFactory();
// intentionally invalid SendingTime (52/DateTime)
string[] msgFields = { "8=FIX.4.4", "9=91", "35=W", "34=3", "49=sender", "52=20110909", "56=target",
"55=sym", "268=1", "269=0", "272=20111012", "273=22:15:30.444", "10=51" };
string msgStr = string.Join(Message.SOH, msgFields) + Message.SOH;
string msgType = "W";
string beginString = "FIX.4.4";
Message message = f.Create(beginString, msgType);
message.FromString(msgStr, true, dd, dd, f);
Assert.That(() => dd.Validate(message, beginString, msgType), Throws.TypeOf<QuickFix.IncorrectDataFormat>());
}
[Test]
public void ValidateDateOnly_Invalid()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.FIX44.MessageFactory f = new QuickFix.FIX44.MessageFactory();
// intentionally invalid MDEntryDate (272/DateOnly)
string[] msgFields = { "8=FIX.4.4", "9=117", "35=W", "34=3", "49=sender", "52=20110909-09:09:09.999", "56=target",
"55=sym", "268=1", "269=0", "272=20111012-22:15:30.444", "273=22:15:30.444", "10=175" };
string msgStr = string.Join(Message.SOH, msgFields) + Message.SOH;
string msgType = "W";
string beginString = "FIX.4.4";
Message message = f.Create(beginString, msgType);
message.FromString(msgStr, true, dd, dd, f);
Assert.That(() => dd.Validate(message, beginString, msgType), Throws.TypeOf<QuickFix.IncorrectDataFormat>());
}
[Test]
public void ValidateTimeOnly_Invalid()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.FIX44.MessageFactory f = new QuickFix.FIX44.MessageFactory();
// intentionally invalid MDEntryTime (272/TimeOnly)
string[] msgFields = { "8=FIX.4.4", "9=113", "35=W", "34=3", "49=sender", "52=20110909-09:09:09.999", "56=target",
"55=sym", "268=1", "269=0", "272=20111012", "273=20111012-22:15:30.444", "10=200" };
string msgStr = string.Join(Message.SOH, msgFields) + Message.SOH;
string msgType = "W";
string beginString = "FIX.4.4";
Message message = f.Create(beginString, msgType);
message.FromString(msgStr, true, dd, dd, f);
Assert.That(() => dd.Validate(message, beginString, msgType), Throws.TypeOf<QuickFix.IncorrectDataFormat>());
}
[Test]
public void DuplicateEnumsDoesNotThrow()
{
// If this test throws, it failed.
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadTestFIXSpec("FIX43_dup_enum");
}
[Test]
public void OptionalComponentRequiredField()
{
// issue #98 - message erroneously rejected because DD says that
// component-required field is missing even though component is not present
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.FIX44.MessageFactory f = new QuickFix.FIX44.MessageFactory();
string[] msgFields = { "8=FIX.4.4", "9=77", "35=AD", "34=3", "49=sender", "52=20110909-09:09:09.999", "56=target",
"568=tradereqid", "569=0", "10=109" };
string msgStr = string.Join(Message.SOH, msgFields) + Message.SOH;
string msgType = "AD";
string beginString = "FIX.4.4";
Message message = f.Create(beginString, msgType);
message.FromString(msgStr, true, dd, dd, f);
dd.Validate(message, beginString, msgType);
}
[Test]
public void RequiredComponentRequiredField()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.FIX44.MessageFactory f = new QuickFix.FIX44.MessageFactory();
string[] msgFields = { "8=FIX.4.4", "9=76", "35=7", "34=3", "49=sender", "52=20110909-09:09:09.999", "56=target",
"2=AdvId", "5=N", "4=B", "53=1", "10=138" };
string msgStr = string.Join(Message.SOH, msgFields) + Message.SOH;
string msgType = "7";
string beginString = "FIX.4.4";
Message message = f.Create(beginString, msgType);
message.FromString(msgStr, true, dd, dd, f);
var ex = Assert.Throws<QuickFix.RequiredTagMissing>(delegate { dd.Validate(message, beginString, msgType); });
Assert.AreEqual(55, ex.Field);
}
[Test]
public void ComponentFieldsRequirements()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.False(dd.Messages["AD"].ReqFields.Contains(55));
Assert.True(dd.Messages["7"].ReqFields.Contains(55));
}
[Test]
public void Issue134_RequiredIsOptional()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadTestFIXSpec("required_is_optional");
Assert.True(dd.Messages["magic"].ReqFields.Contains(1111)); //base required field
Assert.False(dd.Messages["magic"].ReqFields.Contains(5555)); //base optional field
Assert.False(dd.Messages["magic"].ReqFields.Contains(5556)); //component optional field
Assert.False(dd.Messages["magic"].Groups[6660].Required); // group isn't required
Assert.False(dd.Messages["magic"].Groups[6660].ReqFields.Contains(6662)); // group optional field
}
[Test] // Issue #66
public void ValidateMultipleValueStringType()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.FIX44.MessageFactory f = new QuickFix.FIX44.MessageFactory();
string[] msgFields = {"8=FIX.4.4", "9=99", "35=W", "34=3", "49=sender", "52=20110909-09:09:09.999", "56=target",
"55=sym",
"268=1", "269=0", "270=123.23", "271=2", "277=A B",
"10=213"};
string msgStr = string.Join( Message.SOH, msgFields ) + Message.SOH;
string msgType = "W";
string beginString = "FIX.4.4";
Message message = f.Create( beginString, msgType );
message.FromString(msgStr, true, dd, dd);
dd.Validate( message, beginString, msgType );
}
[Test] // Issue #66
public void ValidateMultipleValueStringType_Invalid()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX44");
QuickFix.FIX44.MessageFactory f = new QuickFix.FIX44.MessageFactory();
string[] msgFields = {"8=FIX.4.4", "9=99", "35=W", "34=3", "49=sender", "52=20110909-09:09:09.999", "56=target",
"55=sym",
"268=1", "269=0", "270=123.23", "271=2", "277=A 1",
"10=196"};
string msgStr = string.Join( Message.SOH, msgFields ) + Message.SOH;
string msgType = "W";
string beginString = "FIX.4.4";
Message message = f.Create( beginString, msgType );
message.FromString(msgStr, true, dd, dd);
Assert.That(() => dd.Validate(message, beginString, msgType), Throws.TypeOf<QuickFix.IncorrectTagValue>());
}
[Test] // Issue #282
public void ValidateTagSpecifiedWithoutAValue()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadFIXSpec("FIX42");
QuickFix.FIX42.MessageFactory f = new QuickFix.FIX42.MessageFactory();
string[] msgFields = {"8=FIX.4.2", "9=70", "35=B", "34=3", "49=sender", "52=20110909-09:09:09.999", "56=target",
"358=", "148=", "33=0", "10=150"};
string msgStr = string.Join(Message.SOH, msgFields) + Message.SOH;
string msgType = "B";
string beginString = "FIX.4.2";
Message message = f.Create(beginString, msgType);
message.FromString(msgStr, true, dd, dd);
dd.CheckFieldsHaveValues = true;
Assert.Throws<QuickFix.NoTagValue>(delegate { dd.Validate(message, beginString, msgType); });
dd.CheckFieldsHaveValues = false;
Assert.DoesNotThrow(delegate { dd.Validate(message, beginString, msgType); });
}
[Test] // Issue #493
public void ParseThroughComments()
{
QuickFix.DataDictionary.DataDictionary dd = new QuickFix.DataDictionary.DataDictionary();
dd.LoadTestFIXSpec("comments");
// The fact that it doesn't throw is sufficient, but we'll do some other checks anyway.
var logon = dd.GetMapForMessage("A");
Assert.True(logon.IsField(108)); // HeartBtInt
Assert.True(logon.IsField(9000)); // CustomField
var news = dd.GetMapForMessage("B");
Assert.True(news.IsField(148)); // Headline
Assert.True(news.IsGroup(33)); // LinesOfText
Assert.True(news.GetGroup(33).IsField(355)); // EncodedText
}
XmlNode MakeNode(string xmlString)
{
XmlDocument doc = new XmlDocument();
if (xmlString.StartsWith("<", StringComparison.Ordinal))
{
doc.LoadXml(xmlString);
return doc.DocumentElement;
}
return doc.CreateTextNode(xmlString);
}
[Test]
public void VerifyChildNode()
{
XmlNode parentNode = MakeNode("<message name='Daddy'/>");
Assert.DoesNotThrow(
delegate { QuickFix.DataDictionary.DataDictionary.VerifyChildNode(MakeNode("<field name='qty'/>"), parentNode); });
DictionaryParseException dpx = Assert.Throws<DictionaryParseException>(
delegate { QuickFix.DataDictionary.DataDictionary.VerifyChildNode(MakeNode("foo"), parentNode); });
Assert.AreEqual("Malformed data dictionary: Found text-only node containing 'foo'", dpx.Message);
dpx = Assert.Throws<DictionaryParseException>(
delegate { QuickFix.DataDictionary.DataDictionary.VerifyChildNode(MakeNode("<field>qty</field>"), parentNode); });
Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'message/Daddy'", dpx.Message);
}
}
}