This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
FluentSuperColumnTest.cs
161 lines (132 loc) · 4.13 KB
/
FluentSuperColumnTest.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
using System;
using System.Linq;
using NUnit.Framework;
using FluentCassandra.Types;
namespace FluentCassandra
{
[TestFixture]
public class FluentSuperColumnTest
{
[Test]
public void Parent_Set()
{
// arrange
// act
var actual = new FluentSuperColumn<AsciiType, AsciiType>();
// assert
Assert.AreSame(actual, actual.GetPath().SuperColumn);
}
[Test]
public void Path_Set()
{
// arrange
// act
var actual = new FluentSuperColumn<AsciiType, AsciiType>();
// assert
Assert.AreSame(actual, actual.GetPath().SuperColumn);
}
[Test]
public void Constructor_Test()
{
// arrange
var colName = "This is a test name";
var col1 = new FluentColumn<AsciiType> { ColumnName = "Test1", ColumnValue = 300M };
var col2 = new FluentColumn<AsciiType> { ColumnName = "Test2", ColumnValue = "Hello" };
// act
var actual = new FluentSuperColumn<AsciiType, AsciiType>();
actual.ColumnName = colName;
actual.Columns.Add(col1);
actual.Columns.Add(col2);
// assert
Assert.AreEqual(colName, (string)actual.ColumnName);
Assert.AreEqual(2, actual.Columns.Count);
}
[Test]
public void Constructor_Dynamic_Test()
{
// arrange
var colName = "This is a test name";
var col1 = "Test1";
var colValue1 = 300M;
var col2 = "Test2";
var colValue2 = "Hello";
// act
dynamic actual = new FluentSuperColumn<AsciiType, AsciiType>();
actual.Name = colName;
actual.Test1 = colValue1;
actual.Test2 = colValue2;
// assert
Assert.AreEqual(colName, (string)actual.Name);
//Assert.AreEqual(2, actual.Columns.CountColumns);
Assert.AreEqual(colValue1, (decimal)actual.Test1);
Assert.AreEqual(colValue1, (decimal)actual[col1]);
Assert.AreEqual(colValue2, (string)actual.Test2);
Assert.AreEqual(colValue2, (string)actual[col2]);
}
[Test]
public void Get_NonExistent_Column()
{
// arrange
var colName = "This is a test name";
var colValue1 = 300M;
var colValue2 = "Hello";
var expected = (string)null;
// act
dynamic superColumn = new FluentSuperColumn<AsciiType, AsciiType>();
superColumn.Name = colName;
superColumn.Test1 = colValue1;
superColumn.Test2 = colValue2;
var actual = superColumn.Test3;
// assert
Assert.AreEqual(expected, (string)actual);
}
[Test]
public void Mutation()
{
// arrange
var colName = "This is a test name";
var col1 = new FluentColumn<AsciiType> { ColumnName = "Test1", ColumnValue = 300M };
var col2 = new FluentColumn<AsciiType> { ColumnName = "Test2", ColumnValue = "Hello" };
// act
var actual = new FluentSuperColumn<AsciiType, AsciiType>();
actual.ColumnName = colName;
actual.Columns.Add(col1);
actual.Columns.Add(col2);
// assert
var mutations = actual.MutationTracker.GetMutations();
Assert.AreEqual(2, mutations.Count());
Assert.AreEqual(2, mutations.Count(x => x.Type == MutationType.Added));
var mut1 = mutations.FirstOrDefault(x => x.Column.ColumnName == "Test1");
var mut2 = mutations.FirstOrDefault(x => x.Column.ColumnName == "Test2");
Assert.AreSame(col1, mut1.Column);
Assert.AreSame(col2, mut2.Column);
Assert.AreSame(actual, mut1.Column.GetParent().SuperColumn);
Assert.AreSame(actual, mut2.Column.GetParent().SuperColumn);
}
[Test]
public void Dynamic_Mutation()
{
// arrange
var colName = "This is a test name";
var col1 = "Test1";
var colValue1 = 300M;
var col2 = "Test2";
var colValue2 = "Hello";
// act
dynamic actual = new FluentSuperColumn<AsciiType, AsciiType>();
actual.ColumnName = colName;
actual.Test1 = colValue1;
actual.Test2 = colValue2;
// assert
var mutations = ((IFluentRecord)actual).MutationTracker.GetMutations();
Assert.AreEqual(2, mutations.Count());
Assert.AreEqual(2, mutations.Count(x => x.Type == MutationType.Added));
var mut1 = mutations.FirstOrDefault(x => x.Column.ColumnName == col1);
var mut2 = mutations.FirstOrDefault(x => x.Column.ColumnName == col2);
Assert.IsNotNull(mut1);
Assert.IsNotNull(mut2);
Assert.AreSame(actual, mut1.Column.GetParent().SuperColumn);
Assert.AreSame(actual, mut2.Column.GetParent().SuperColumn);
}
}
}