-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathPrimaryIndexInfoTest.cs
More file actions
148 lines (125 loc) · 4.09 KB
/
PrimaryIndexInfoTest.cs
File metadata and controls
148 lines (125 loc) · 4.09 KB
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
// Copyright (C) 2003-2010 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Ivan Galkin
// Created: 2009.03.17
using System;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using Xtensive.Core;
using Xtensive.Orm.Tests;
using Xtensive.Orm.Upgrade.Model;
namespace Xtensive.Orm.Tests.Indexing
{
[TestFixture]
public class PrimaryIndexInfoTest
{
private StorageModel storage;
private TableInfo table;
private PrimaryIndexInfo index;
[SetUp]
public void CreateStorage()
{
storage = new StorageModel("s1");
table = new TableInfo(storage, "table");
index = new PrimaryIndexInfo(table, "i");
}
[Test]
public void DenyIndexInfoConstructor()
{
var indexBefore = table.PrimaryIndex;
AssertEx.Throws<ArgumentException>(() => new PrimaryIndexInfo(null, "i2"));
AssertEx.Throws<ArgumentException>(() => new PrimaryIndexInfo(table, ""));
Assert.AreEqual(indexBefore, table.PrimaryIndex);
}
[Test]
public void AddRemoveColumnsTest()
{
var column = new StorageColumnInfo(table, "c");
Assert.AreEqual(1, table.Columns.Count);
column.Remove();
Assert.AreEqual(0, table.Columns.Count);
}
[Test]
public void DenyAddColumnTest()
{
var column = new StorageColumnInfo(table, "c");
AssertEx.Throws<ArgumentException>(() => new StorageColumnInfo(table, "c"));
}
[Test]
public void AddRemoveKeyColumnRefs()
{
var column = new StorageColumnInfo(table, "col1");
var colRef = new KeyColumnRef(index, column, Direction.Positive);
Assert.AreEqual(1, index.KeyColumns.Count);
colRef.Remove();
Assert.AreEqual(0, index.KeyColumns.Count);
column.Remove();
}
[Test]
public void AddRemoveValueColumnRefs()
{
var column = new StorageColumnInfo(table, "col1");
var colRef = new ValueColumnRef(index, column);
Assert.AreEqual(1, index.ValueColumns.Count);
colRef.Remove();
Assert.AreEqual(0, index.ValueColumns.Count);
}
[Test]
public void ValidateEmptyKeys()
{
new StorageColumnInfo(table, "c1", new StorageTypeInfo(typeof(string), null));
new StorageColumnInfo(table, "c2", new StorageTypeInfo(typeof(string), null));
AssertEx.Throws<AggregateException>(index.Validate);
}
[Test]
public void ValidateNullableKeyColumns()
{
var col = new StorageColumnInfo(table, "c2", new StorageTypeInfo(typeof (string), null, true));
new KeyColumnRef(index, col, Direction.Positive);
AssertEx.Throws<AggregateException>(index.Validate);
}
[Test]
public void ValidateDoubleColumnRefs()
{
var column = new StorageColumnInfo(table, "c");
new KeyColumnRef(index, column, Direction.Positive);
new ValueColumnRef(index, column);
AssertEx.Throws<AggregateException>(index.Validate);
}
[Test]
public void ValidateNotReferencedColumns()
{
new KeyColumnRef(index, new StorageColumnInfo(table, "key"), Direction.Positive);
new StorageColumnInfo(table, "col");
AssertEx.Throws<AggregateException>(index.Validate);
}
[Test]
public void ValidateDoubleKeysAndValuesColumnRefs()
{
var key = new StorageColumnInfo(table, "key");
var value = new StorageColumnInfo(table, "value");
new KeyColumnRef(index, key, Direction.Positive);
new KeyColumnRef(index, key, Direction.Negative);
new ValueColumnRef(index, value);
new ValueColumnRef(index, value);
AssertEx.Throws<AggregateException>(index.Validate);
}
[Test]
public void ValidateRefToColumnFromAnotherIndex()
{
var anoterTable = new TableInfo(storage, "t2");
var key = new StorageColumnInfo(anoterTable, "key");
var value = new StorageColumnInfo(anoterTable, "value");
new KeyColumnRef(index, key, Direction.Positive);
new ValueColumnRef(index, value);
AssertEx.Throws<AggregateException>(index.Validate);
}
[TearDown]
public void Dump()
{
storage.Dump();
}
}
}