forked from SolrNet/SolrNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteCommandTests.cs
135 lines (111 loc) · 4.68 KB
/
DeleteCommandTests.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
#region license
// Copyright (c) 2007-2010 Mauricio Scheffer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion
using MbUnit.Framework;
using Moroco;
using SolrNet.Commands;
using SolrNet.Commands.Parameters;
namespace SolrNet.Tests {
[TestFixture]
public class DeleteCommandTests {
[Test]
public void DeleteById() {
const string id = "123123";
var conn = new Mocks.MSolrConnection();
conn.post = conn.post
.Args("/update", string.Format("<delete><id>{0}</id></delete>", id));
var cmd = new DeleteCommand(new DeleteByIdAndOrQueryParam(new[] { id }, null, null), null);
cmd.Execute(conn);
Assert.AreEqual(1, conn.post.Calls);
}
[Test]
public void DeleteByMultipleId() {
var ids = new[] {"123", "456"};
var conn = new Mocks.MSolrConnection();
var xml = string.Format("<delete><id>{0}</id><id>{1}</id></delete>", ids[0], ids[1]);
conn.post = conn.post.Args("/update", xml);
var cmd = new DeleteCommand(new DeleteByIdAndOrQueryParam(ids, null, null), null);
cmd.Execute(conn);
Assert.AreEqual(1, conn.post.Calls);
}
[Test]
public void DeleteByQuery() {
const string queryString = "someQuery";
var q = new SolrQuery(queryString);
var xml = string.Format("<delete><query>{0}</query></delete>", queryString);
var conn = new Mocks.MSolrConnection();
conn.post = conn.post.Args("/update", xml);
var querySerializer = new Mocks.MSolrQuerySerializer();
querySerializer.serialize += _ => queryString;
var cmd = new DeleteCommand(new DeleteByIdAndOrQueryParam(null, q, querySerializer), null);
cmd.Execute(conn);
Assert.AreEqual(1, conn.post.Calls);
}
[Test]
public void DeleteByIdAndQuery() {
var ids = new[] { "123", "456" };
const string queryString = "someQuery";
var xml = string.Format("<delete><id>{0}</id><id>{1}</id><query>{2}</query></delete>", ids[0], ids[1], queryString);
var conn = new Mocks.MSolrConnection();
conn.post = conn.post.Args("/update", xml);
var q = new SolrQuery(queryString);
var querySerializer = new Mocks.MSolrQuerySerializer();
querySerializer.serialize += _ => queryString;
var cmd = new DeleteCommand(new DeleteByIdAndOrQueryParam(ids, q, querySerializer), null);
cmd.Execute(conn);
Assert.AreEqual(1, conn.post.Calls);
}
[Test]
public void DeleteFromCommitted() {
const string id = "123123";
var xml = string.Format("<delete fromCommitted=\"true\"><id>{0}</id></delete>", id);
var conn = new Mocks.MSolrConnection();
conn.post = conn.post.Args("/update", xml);
var cmd = new DeleteCommand(new DeleteByIdAndOrQueryParam(new[] { id }, null, null), null)
{
FromCommitted = true
};
cmd.Execute(conn);
Assert.AreEqual(1, conn.post.Calls);
}
[Test]
public void DeleteFromCommittedAndFromPending() {
const string id = "123123";
var conn = new Mocks.MSolrConnection();
var xml = string.Format("<delete fromPending=\"false\" fromCommitted=\"false\"><id>{0}</id></delete>", id);
conn.post = conn.post.Args("/update", xml);
var cmd = new DeleteCommand(new DeleteByIdAndOrQueryParam(new[] { id }, null, null), null)
{
FromCommitted = false,
FromPending = false
};
cmd.Execute(conn);
Assert.AreEqual(1, conn.post.Calls);
}
[Test]
public void DeleteFromPending() {
const string id = "123123";
var conn = new Mocks.MSolrConnection();
var xml = string.Format("<delete fromPending=\"true\"><id>{0}</id></delete>", id);
conn.post = conn.post.Args("/update", xml);
var cmd = new DeleteCommand(new DeleteByIdAndOrQueryParam(new[] { id }, null, null), null)
{
FromPending = true
};
cmd.Execute(conn);
Assert.AreEqual(1, conn.post.Calls);
}
}
}