1
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
2
+ using Aerospike . Database . LINQPadDriver . Extensions ;
3
+ using System ;
4
+ using System . Collections . Generic ;
5
+ using System . Linq ;
6
+ using System . Text ;
7
+ using System . Threading . Tasks ;
8
+
9
+ namespace Aerospike . Database . LINQPadDriver . Extensions . Tests
10
+ {
11
+ [ TestClass ( ) ]
12
+ public class ToCodeAPITests
13
+ {
14
+ [ TestMethod ( ) ]
15
+ public void ToAPICodeTest ( )
16
+ {
17
+ var aRecord = ARecord . FromJson ( "tns" , "tset" , ARecordTests . jsonRecords ) ;
18
+
19
+ var records = new ARecord [ ] { aRecord } ;
20
+
21
+ var codeBlocks = records . ToAPICode ( ) . ToList ( ) ;
22
+
23
+ Assert . AreEqual ( 2 , codeBlocks . Count ) ;
24
+
25
+ var codeBlock1 = @"tns.tset.Get(new Byte[] { (byte) 0,(byte) 128,(byte) 162,(byte) 69,(byte) 250,(byte) 190,(byte) 87,(byte) 153,(byte) 151,(byte) 7,(byte) 220,(byte) 65,(byte) 206,(byte) 214,(byte) 14,(byte) 220,(byte) 74,(byte) 199,(byte) 172,(byte) 64 })" ;
26
+ var codeBlock2 = @"tns.tset.Put(new Byte[] { (byte) 0,(byte) 128,(byte) 162,(byte) 69,(byte) 250,(byte) 190,(byte) 87,(byte) 153,(byte) 151,(byte) 7,(byte) 220,(byte) 65,(byte) 206,(byte) 214,(byte) 14,(byte) 220,(byte) 74,(byte) 199,(byte) 172,(byte) 64 },
27
+ new Dictionary<string,object>() {{""account_id"", 794875L},
28
+ {""transaction_count"", 6L},
29
+ {""bucket_start_date"", DateTime.Parse(""2018-12-27T05:00:00.0000"")},
30
+ {""bucket_end_date"", DateTime.Parse(""2016-09-06T00:00:00.0000"")},
31
+ {""transactions"", new List<Object>() { new Dictionary<Object,Object>() { {""date"",DateTime.Parse(""2011-12-28T00:00:00.0000"")},{""amount"",1197L},{""transaction_code"",""buy""},{""symbol"",""nvda""},{""price"",12.733002429934103361119923647M},{""total"",15241.403908631122D} },new Dictionary<Object,Object>() { {""date"",DateTime.Parse(""2016-06-13T00:00:00.0000"")},{""amount"",8797L},{""transaction_code"",""buy""},{""symbol"",""nvda""},{""price"",46.538731724063914896305504953M},{""total"",409401.2229765903D} },new Dictionary<Object,Object>() { {""date"",DateTime.Parse(""2016-08-31T00:00:00.0000"")},{""amount"",6146L},{""transaction_code"",""sell""},{""symbol"",""ebay""},{""price"",""32.11600884852845894101847079582512378692626953125""},{""total"",""197384.9903830559086514995215""} },new Dictionary<Object,Object>() { {""date"",DateTime.Parse(""2004-11-22T00:00:00.0000"")},{""amount"",253L},{""transaction_code"",""buy""},{""symbol"",""amzn""},{""price"",""37.77441226157566944721111212857067584991455078125""},{""total"",""9556.926302178644370144411369""} },new Dictionary<Object,Object>() { {""date"",DateTime.Parse(""2002-05-23T00:00:00.0000"")},{""amount"",4521L},{""transaction_code"",""buy""},{""symbol"",""nvda""},{""price"",""10.763069758141103449133879621513187885284423828125""},{""total"",""48659.83837655592869353426977""} },new Dictionary<Object,Object>() { {""date"",DateTime.Parse(""1999-09-01T00:00:00.0000"")},{""amount"",955L},{""transaction_code"",""buy""},{""symbol"",""csco""},{""price"",""27.992136535152877030441231909207999706268310546875""},{""total"",""26732.49039107099756407137647""} } }}})" ;
32
+
33
+ Assert . AreEqual ( codeBlock1 , codeBlocks [ 0 ] ) ;
34
+ Assert . AreEqual ( codeBlock2 , codeBlocks [ 1 ] ) ;
35
+
36
+ codeBlocks = records . ToAPICode ( useAerospikeAPI : true ) . ToList ( ) ;
37
+
38
+ Assert . AreEqual ( 2 , codeBlocks . Count ) ;
39
+
40
+ codeBlock1 = @"ASClient.Get(null,
41
+ new Key(""tns"",""tset"",new Byte[] { (byte) 0,(byte) 128,(byte) 162,(byte) 69,(byte) 250,(byte) 190,(byte) 87,(byte) 153,(byte) 151,(byte) 7,(byte) 220,(byte) 65,(byte) 206,(byte) 214,(byte) 14,(byte) 220,(byte) 74,(byte) 199,(byte) 172,(byte) 64 }))" ;
42
+ codeBlock2 = @"ASClient.Put(null,
43
+ new Key(""tns"",""tset"",new Byte[] { (byte) 0,(byte) 128,(byte) 162,(byte) 69,(byte) 250,(byte) 190,(byte) 87,(byte) 153,(byte) 151,(byte) 7,(byte) 220,(byte) 65,(byte) 206,(byte) 214,(byte) 14,(byte) 220,(byte) 74,(byte) 199,(byte) 172,(byte) 64 }),
44
+ new Bin(""account_id"", Value.Get(794875L)),
45
+ new Bin(""transaction_count"", Value.Get(6L)),
46
+ new Bin(""bucket_start_date"", Value.Get(""2018-12-27T05:00:00.0000"")),
47
+ new Bin(""bucket_end_date"", Value.Get(""2016-09-06T00:00:00.0000"")),
48
+ new Bin(""transactions"", Value.Get(new List<Object>() { new Dictionary<Object,Object>() { {""date"",""2011-12-28T00:00:00.0000""},{""amount"",1197L},{""transaction_code"",""buy""},{""symbol"",""nvda""},{""price"",12.733002429934103D},{""total"",15241.403908631122D} },new Dictionary<Object,Object>() { {""date"",""2016-06-13T00:00:00.0000""},{""amount"",8797L},{""transaction_code"",""buy""},{""symbol"",""nvda""},{""price"",46.538731724063915D},{""total"",409401.2229765903D} },new Dictionary<Object,Object>() { {""date"",""2016-08-31T00:00:00.0000""},{""amount"",6146L},{""transaction_code"",""sell""},{""symbol"",""ebay""},{""price"",""32.11600884852845894101847079582512378692626953125""},{""total"",""197384.9903830559086514995215""} },new Dictionary<Object,Object>() { {""date"",""2004-11-22T00:00:00.0000""},{""amount"",253L},{""transaction_code"",""buy""},{""symbol"",""amzn""},{""price"",""37.77441226157566944721111212857067584991455078125""},{""total"",""9556.926302178644370144411369""} },new Dictionary<Object,Object>() { {""date"",""2002-05-23T00:00:00.0000""},{""amount"",4521L},{""transaction_code"",""buy""},{""symbol"",""nvda""},{""price"",""10.763069758141103449133879621513187885284423828125""},{""total"",""48659.83837655592869353426977""} },new Dictionary<Object,Object>() { {""date"",""1999-09-01T00:00:00.0000""},{""amount"",955L},{""transaction_code"",""buy""},{""symbol"",""csco""},{""price"",""27.992136535152877030441231909207999706268310546875""},{""total"",""26732.49039107099756407137647""} } })))" ;
49
+
50
+ Assert . AreEqual ( codeBlock1 , codeBlocks [ 0 ] ) ;
51
+ Assert . AreEqual ( codeBlock2 , codeBlocks [ 1 ] ) ;
52
+ }
53
+ }
54
+ }
0 commit comments