-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathStorageInfoTest.cs
102 lines (92 loc) · 2.96 KB
/
StorageInfoTest.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
// 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 NUnit.Framework;
using Xtensive.Core;
using Xtensive.Orm.Tests;
using Xtensive.Modelling.Actions;
using Xtensive.Orm.Upgrade.Model;
namespace Xtensive.Orm.Tests.Indexing
{
[TestFixture]
public class StorageInfoTest
{
protected StorageModel storage;
protected TableInfo table1;
protected TableInfo table2;
protected PrimaryIndexInfo pi1;
protected PrimaryIndexInfo pi2;
protected SecondaryIndexInfo si1;
protected SecondaryIndexInfo si2;
protected ForeignKeyInfo fk1;
protected StorageColumnInfo column1;
protected StorageColumnInfo column2;
protected StorageColumnInfo column3;
protected StorageColumnInfo column4;
protected StorageColumnInfo column5;
[SetUp]
public void CreateModel()
{
storage = new StorageModel("storage") { Actions = new ActionSequence() };
// Table 1
table1 = new TableInfo(storage, "table1");
pi1 = new PrimaryIndexInfo(table1, "pk1");
column1 = new StorageColumnInfo(table1, "col1", new StorageTypeInfo(typeof(string), null, false));
column2 = new StorageColumnInfo(table1, "col2", new StorageTypeInfo(typeof(string), null));
column3 = new StorageColumnInfo(table1, "col3", new StorageTypeInfo(typeof(string), null));
new KeyColumnRef(pi1, column1, Direction.Positive);
pi1.PopulateValueColumns();
si1 = new SecondaryIndexInfo(table1, "ix1");
new KeyColumnRef(si1, column2, Direction.Positive);
si1.PopulatePrimaryKeyColumns();
// Table 2
table2 = new TableInfo(storage, "table2");
pi2 = new PrimaryIndexInfo(table2, "pk2");
column4 = new StorageColumnInfo(table2, "col4", new StorageTypeInfo(typeof(int), null));
column5 = new StorageColumnInfo(table2, "col5", new StorageTypeInfo(typeof(string), null));
new KeyColumnRef(pi2, column4, Direction.Negative);
pi2.PopulateValueColumns();
si2 = new SecondaryIndexInfo(table2, "ix2");
new KeyColumnRef(si2, column5, Direction.Positive);
si2.PopulatePrimaryKeyColumns();
// Foreign keys
fk1 = new ForeignKeyInfo(table2, "fk1")
{
PrimaryKey = pi1
};
fk1.ForeignKeyColumns.Set(si2);
}
[Test]
public void ValidateModel()
{
storage.Validate();
}
[Test]
public void StorageLogTest()
{
TestLog.Info("Actions:");
TestLog.Info("{0}", storage.Actions);
}
[Test]
public void RemoveReferencedColumnTest()
{
column5.Remove();
AssertEx.Throws<AggregateException>(storage.Validate);
}
[Test]
public void RemoveReferencedSecondaryIndexTest()
{
column5.Remove();
si2.Remove();
AssertEx.Throws<AggregateException>(storage.Validate);
}
[TearDown]
public void Dump()
{
storage.Dump();
}
}
}