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
/
Issue39CompositeTypeAsKey.cs
120 lines (94 loc) · 3.38 KB
/
Issue39CompositeTypeAsKey.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
using System;
using System.Collections.Generic;
using System.Linq;
using FluentCassandra.Types;
using Xunit;
namespace FluentCassandra.Bugs
{
public class Issue39CompositeTypeAsKey : IUseFixture<CassandraDatabaseSetupFixture>, IDisposable
{
private CassandraContext _db;
public void SetFixture(CassandraDatabaseSetupFixture data)
{
var setup = data.DatabaseSetup();
_db = setup.DB;
}
public void Dispose()
{
_db.Dispose();
}
[Fact]
public void Test_Composite2()
{
// arrange
var keyspace = _db.Keyspace;
// create column family using API
_db.TryDropColumnFamily("Data");
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
FamilyName = "Data",
KeyValueType = CassandraType.CompositeType(CassandraType.AsciiType, CassandraType.AsciiType),
ColumnNameType = CassandraType.AsciiType,
DefaultColumnValueType = CassandraType.BytesType
});
InsertData2("TT", "A", new Dictionary<string, string> { { "Status", "Working" } });
// act
var actual = GetData2("TT", "A", "Status");
// assert
Assert.NotNull(actual);
Assert.Equal(1, actual.Columns.Count);
}
public void InsertData2(string key1, string key2, Dictionary<string, string> values)
{
var productFamily = _db.GetColumnFamily("Data");
var key = new CompositeType<AsciiType, AsciiType>(key1, key2);
var post = productFamily.CreateRecord(key);
_db.Attach(post);
foreach (var fieldValue in values)
post.TrySetColumn(fieldValue.Key, fieldValue.Value);
_db.SaveChanges();
}
public FluentColumnFamily GetData2(string key1, string key2, params CassandraObject[] columns)
{
var productFamily = _db.GetColumnFamily("Data");
var key = new CompositeType<AsciiType, AsciiType>(key1, key2);
return productFamily.Get(key).FetchColumns(columns).FirstOrDefault();
}
[Fact]
public void Test_Composite3()
{
// arrange
var keyspace = _db.Keyspace;
// create column family using API
_db.TryDropColumnFamily("Data");
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
FamilyName = "Data",
KeyValueType = CassandraType.CompositeType(CassandraType.AsciiType, CassandraType.AsciiType, CassandraType.TimeUUIDType),
ColumnNameType = CassandraType.AsciiType,
DefaultColumnValueType = CassandraType.BytesType
});
var stamp = new DateTimeOffset(2012, 6, 22, 4, 41, 00, TimeSpan.Zero);
InsertData3("TT", "A", stamp, new Dictionary<string, string> { { "Status", "Working" } });
// act
var actual = GetData3("TT", "A", stamp, "Status");
// assert
Assert.NotNull(actual);
Assert.Equal(1, actual.Columns.Count);
}
public void InsertData3(string key1, string key2, DateTimeOffset stamp, Dictionary<string, string> values)
{
var productFamily = _db.GetColumnFamily("Data");
var key = new CompositeType<AsciiType, AsciiType, TimeUUIDType>(key1, key2, stamp);
var post = productFamily.CreateRecord(key);
_db.Attach(post);
foreach (var fieldValue in values)
post.TrySetColumn(fieldValue.Key, fieldValue.Value);
_db.SaveChanges();
}
public FluentColumnFamily GetData3(string key1, string key2, DateTimeOffset stamp, params CassandraObject[] columns)
{
var productFamily = _db.GetColumnFamily("Data");
var key = new CompositeType<AsciiType, AsciiType, TimeUUIDType>(key1, key2, stamp);
return productFamily.Get(key).FetchColumns(columns).FirstOrDefault();
}
}
}