Merge lp:~adam-rpconnelly/dbversion/cmdtimeout into lp:dbversion
- cmdtimeout
- Merge into trunk
Proposed by
Adam Connelly
Status: | Merged |
---|---|
Merged at revision: | 50 |
Proposed branch: | lp:~adam-rpconnelly/dbversion/cmdtimeout |
Merge into: | lp:dbversion |
Diff against target: | 450 lines |
To merge this branch: | bzr merge lp:~adam-rpconnelly/dbversion/cmdtimeout |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Colin Winning | Approve | ||
Review via email: mp+121925@code.launchpad.net |
Commit message
Description of the change
Moved the code to convert the property value to an int into the PropertyService.
To post a comment you must log in.
Revision history for this message
Colin Winning (colinwinning) wrote : | # |
Revision history for this message
Colin Winning (colinwinning) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/DatabaseVersion.Tests/Manifests/ManifestReaderTests.cs' | |||
2 | --- src/DatabaseVersion.Tests/Manifests/ManifestReaderTests.cs 2011-10-10 18:43:53 +0000 | |||
3 | +++ src/DatabaseVersion.Tests/Manifests/ManifestReaderTests.cs 2012-08-29 19:06:19 +0000 | |||
4 | @@ -95,9 +95,8 @@ | |||
5 | 95 | 95 | ||
6 | 96 | Mock<IDatabaseTaskFactory > factory = new Mock<IDatabaseTaskFactory>(); | 96 | Mock<IDatabaseTaskFactory > factory = new Mock<IDatabaseTaskFactory>(); |
7 | 97 | Mock<IDatabaseTask > task = new Mock<IDatabaseTask>(); | 97 | Mock<IDatabaseTask > task = new Mock<IDatabaseTask>(); |
8 | 98 | Mock<IMessageService> messageService = new Mock<IMessageService>(); | ||
9 | 99 | factory.Setup(f => f.CanCreate(It.Is<XElement>(r => r.Name == "script"))).Returns(true); | 98 | factory.Setup(f => f.CanCreate(It.Is<XElement>(r => r.Name == "script"))).Returns(true); |
11 | 100 | factory.Setup(f => f.Create(It.Is<XElement>(r => r.Name == "script"), 0, It.IsAny<IDatabaseVersion>(), messageService.Object)).Returns(task.Object); | 99 | factory.Setup(f => f.Create(It.Is<XElement>(r => r.Name == "script"), 0, It.IsAny<IDatabaseVersion>())).Returns(task.Object); |
12 | 101 | 100 | ||
13 | 102 | reader.Factories = new[] { factory.Object }; | 101 | reader.Factories = new[] { factory.Object }; |
14 | 103 | 102 | ||
15 | @@ -116,9 +115,8 @@ | |||
16 | 116 | 115 | ||
17 | 117 | Mock<IDatabaseTaskFactory > factory = new Mock<IDatabaseTaskFactory>(); | 116 | Mock<IDatabaseTaskFactory > factory = new Mock<IDatabaseTaskFactory>(); |
18 | 118 | Mock<IDatabaseTask > task = new Mock<IDatabaseTask>(); | 117 | Mock<IDatabaseTask > task = new Mock<IDatabaseTask>(); |
19 | 119 | Mock<IMessageService> messageService = new Mock<IMessageService>(); | ||
20 | 120 | factory.Setup(f => f.CanCreate(It.IsAny<XElement>())).Returns(true); | 118 | factory.Setup(f => f.CanCreate(It.IsAny<XElement>())).Returns(true); |
22 | 121 | factory.Setup(f => f.Create(It.IsAny<XElement>(), It.IsAny<int>(), It.IsAny<IDatabaseVersion>(), messageService.Object)).Returns(task.Object); | 119 | factory.Setup(f => f.Create(It.IsAny<XElement>(), It.IsAny<int>(), It.IsAny<IDatabaseVersion>())).Returns(task.Object); |
23 | 122 | 120 | ||
24 | 123 | reader.Factories = new[] { factory.Object }; | 121 | reader.Factories = new[] { factory.Object }; |
25 | 124 | 122 | ||
26 | @@ -129,7 +127,7 @@ | |||
27 | 129 | int expectedOrder = 0; | 127 | int expectedOrder = 0; |
28 | 130 | foreach (IDatabaseTask createdTask in version.Tasks) | 128 | foreach (IDatabaseTask createdTask in version.Tasks) |
29 | 131 | { | 129 | { |
31 | 132 | factory.Verify(f => f.Create(It.IsAny<XElement>(), expectedOrder, It.IsAny<IDatabaseVersion>(), messageService.Object)); | 130 | factory.Verify(f => f.Create(It.IsAny<XElement>(), expectedOrder, It.IsAny<IDatabaseVersion>())); |
32 | 133 | expectedOrder++; | 131 | expectedOrder++; |
33 | 134 | } | 132 | } |
34 | 135 | } | 133 | } |
35 | 136 | 134 | ||
36 | === modified file 'src/DatabaseVersion.Tests/Property/PropertyServiceTests.cs' | |||
37 | --- src/DatabaseVersion.Tests/Property/PropertyServiceTests.cs 2011-09-02 23:16:14 +0000 | |||
38 | +++ src/DatabaseVersion.Tests/Property/PropertyServiceTests.cs 2012-08-29 19:06:19 +0000 | |||
39 | @@ -85,6 +85,6 @@ | |||
40 | 85 | 85 | ||
41 | 86 | // Assert | 86 | // Assert |
42 | 87 | Assert.Equal(0, service.Properties.Count()); | 87 | Assert.Equal(0, service.Properties.Count()); |
44 | 88 | } | 88 | } |
45 | 89 | 89 | ||
46 | 90 | [Fact] | 90 | [Fact] |
47 | 91 | public void ShouldBeAbleToReturnPropertyAsInt() | 91 | public void ShouldBeAbleToReturnPropertyAsInt() |
48 | 92 | { | 92 | { |
49 | 93 | // Arrange | 93 | // Arrange |
50 | 94 | var service = new PropertyService(); | 94 | var service = new PropertyService(); |
51 | 95 | service.Add(new Property { Key = "myProperty", Value = "100" }); | 95 | service.Add(new Property { Key = "myProperty", Value = "100" }); |
52 | 96 | 96 | ||
53 | 97 | // Act | 97 | // Act |
54 | 98 | var value = service.GetInt("myProperty"); | 98 | var value = service.GetInt("myProperty"); |
55 | 99 | 99 | ||
56 | 100 | // Assert | 100 | // Assert |
57 | 101 | Assert.Equal(100, value); | 101 | Assert.Equal(100, value); |
58 | 102 | } | 102 | } |
59 | 103 | 103 | ||
60 | 104 | [Fact] | 104 | [Fact] |
61 | 105 | public void ShouldReturnNullIfPropertyIsNotAnInt() | 105 | public void ShouldReturnNullIfPropertyIsNotAnInt() |
62 | 106 | { | 106 | { |
63 | 107 | // Arrange | 107 | // Arrange |
64 | 108 | var service = new PropertyService(); | 108 | var service = new PropertyService(); |
65 | 109 | service.Add(new Property { Key = "myProperty", Value = "abcd" }); | 109 | service.Add(new Property { Key = "myProperty", Value = "abcd" }); |
66 | 110 | 110 | ||
67 | 111 | // Act | 111 | // Act |
68 | 112 | var value = service.GetInt("myProperty"); | 112 | var value = service.GetInt("myProperty"); |
69 | 113 | 113 | ||
70 | 114 | // Assert | 114 | // Assert |
71 | 115 | Assert.Null(value); | 115 | Assert.Null(value); |
72 | 116 | } | 116 | } |
73 | 117 | 117 | ||
74 | 118 | [Fact] | 118 | [Fact] |
75 | 119 | public void ShouldReturnNullFromGetIntIfPropertyIsNotSet() | 119 | public void ShouldReturnNullFromGetIntIfPropertyIsNotSet() |
76 | 120 | { | 120 | { |
77 | 121 | // Arrange | 121 | // Arrange |
78 | 122 | var service = new PropertyService(); | 122 | var service = new PropertyService(); |
79 | 123 | 123 | ||
80 | 124 | // Act | 124 | // Act |
81 | 125 | var value = service.GetInt("myProperty"); | 125 | var value = service.GetInt("myProperty"); |
82 | 126 | 126 | ||
83 | 127 | // Assert | 127 | // Assert |
84 | 128 | Assert.Null(value); | 128 | Assert.Null(value); |
85 | 129 | } | 129 | } |
86 | 130 | } | 130 | } |
87 | 131 | } | 131 | } |
88 | 132 | 132 | ||
89 | === modified file 'src/DatabaseVersion.Tests/Sql/ScriptTaskFactoryTests.cs' | |||
90 | --- src/DatabaseVersion.Tests/Sql/ScriptTaskFactoryTests.cs 2011-10-10 09:00:52 +0000 | |||
91 | +++ src/DatabaseVersion.Tests/Sql/ScriptTaskFactoryTests.cs 2012-08-29 19:06:19 +0000 | |||
92 | @@ -63,7 +63,7 @@ | |||
93 | 63 | new XAttribute(XName.Get("file"), "path/file.sql")); | 63 | new XAttribute(XName.Get("file"), "path/file.sql")); |
94 | 64 | 64 | ||
95 | 65 | // Act | 65 | // Act |
97 | 66 | IDatabaseTask task = this.factory.Create(element, 0, null, null); | 66 | IDatabaseTask task = this.factory.Create(element, 0, null); |
98 | 67 | 67 | ||
99 | 68 | // Assert | 68 | // Assert |
100 | 69 | Assert.IsType<ScriptTask>(task); | 69 | Assert.IsType<ScriptTask>(task); |
101 | @@ -78,7 +78,7 @@ | |||
102 | 78 | new XAttribute(XName.Get("file"), "path/file.sql")); | 78 | new XAttribute(XName.Get("file"), "path/file.sql")); |
103 | 79 | 79 | ||
104 | 80 | // Act | 80 | // Act |
106 | 81 | IDatabaseTask task = this.factory.Create(element, 0, null, null); | 81 | IDatabaseTask task = this.factory.Create(element, 0, null); |
107 | 82 | 82 | ||
108 | 83 | // Assert | 83 | // Assert |
109 | 84 | Assert.Equal("path/file.sql", ((ScriptTask)task).FileName); | 84 | Assert.Equal("path/file.sql", ((ScriptTask)task).FileName); |
110 | @@ -93,7 +93,7 @@ | |||
111 | 93 | new XAttribute(XName.Get("file"), "path/file.sql")); | 93 | new XAttribute(XName.Get("file"), "path/file.sql")); |
112 | 94 | 94 | ||
113 | 95 | // Act | 95 | // Act |
115 | 96 | IDatabaseTask task = this.factory.Create(element, 25, null, null); | 96 | IDatabaseTask task = this.factory.Create(element, 25, null); |
116 | 97 | 97 | ||
117 | 98 | // Assert | 98 | // Assert |
118 | 99 | Assert.Equal(25, task.ExecutionOrder); | 99 | Assert.Equal(25, task.ExecutionOrder); |
119 | 100 | 100 | ||
120 | === modified file 'src/DatabaseVersion.Tests/Sql/ScriptTaskTests.cs' | |||
121 | --- src/DatabaseVersion.Tests/Sql/ScriptTaskTests.cs 2012-01-24 22:01:24 +0000 | |||
122 | +++ src/DatabaseVersion.Tests/Sql/ScriptTaskTests.cs 2012-08-29 19:06:19 +0000 | |||
123 | @@ -9,6 +9,7 @@ | |||
124 | 9 | using Moq; | 9 | using Moq; |
125 | 10 | using System.Data; | 10 | using System.Data; |
126 | 11 | using System.IO; | 11 | using System.IO; |
127 | 12 | using dbversion.Property; | ||
128 | 12 | using dbversion.Tasks; | 13 | using dbversion.Tasks; |
129 | 13 | using dbversion.Version; | 14 | using dbversion.Version; |
130 | 14 | using NHibernate; | 15 | using NHibernate; |
131 | @@ -18,10 +19,12 @@ | |||
132 | 18 | private readonly Mock<ISession> session = new Mock<ISession>() { DefaultValue = DefaultValue.Mock }; | 19 | private readonly Mock<ISession> session = new Mock<ISession>() { DefaultValue = DefaultValue.Mock }; |
133 | 19 | private readonly Mock<IDbCommand> command = new Mock<IDbCommand>(); | 20 | private readonly Mock<IDbCommand> command = new Mock<IDbCommand>(); |
134 | 20 | private readonly Mock<IMessageService> messageService = new Mock<IMessageService> { DefaultValue = DefaultValue.Mock }; | 21 | private readonly Mock<IMessageService> messageService = new Mock<IMessageService> { DefaultValue = DefaultValue.Mock }; |
135 | 22 | private readonly Mock<IPropertyService> propertyService = new Mock<IPropertyService>(); | ||
136 | 21 | 23 | ||
137 | 22 | public ScriptTaskTests() | 24 | public ScriptTaskTests() |
138 | 23 | { | 25 | { |
139 | 24 | this.session.Setup(s => s.Connection.CreateCommand()).Returns(command.Object); | 26 | this.session.Setup(s => s.Connection.CreateCommand()).Returns(command.Object); |
140 | 27 | this.command.SetupProperty(c => c.CommandTimeout); | ||
141 | 25 | } | 28 | } |
142 | 26 | 29 | ||
143 | 27 | [Fact] | 30 | [Fact] |
144 | @@ -32,7 +35,7 @@ | |||
145 | 32 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); | 35 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); |
146 | 33 | version.Setup(v => v.Archive.GetScriptPath("1\\database.xml", "scripts\\schema.sql")).Returns("1\\scripts\\schema.sql"); | 36 | version.Setup(v => v.Archive.GetScriptPath("1\\database.xml", "scripts\\schema.sql")).Returns("1\\scripts\\schema.sql"); |
147 | 34 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns(this.GetStream("A")); | 37 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns(this.GetStream("A")); |
149 | 35 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object); | 38 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object, this.propertyService.Object); |
150 | 36 | 39 | ||
151 | 37 | // Act | 40 | // Act |
152 | 38 | task.Execute(session.Object, 1, 1); | 41 | task.Execute(session.Object, 1, 1); |
153 | @@ -49,7 +52,7 @@ | |||
154 | 49 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); | 52 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); |
155 | 50 | version.Setup(v => v.Archive.GetScriptPath("1\\database.xml", "scripts\\schema.sql")).Returns("1\\scripts\\schema.sql"); | 53 | version.Setup(v => v.Archive.GetScriptPath("1\\database.xml", "scripts\\schema.sql")).Returns("1\\scripts\\schema.sql"); |
156 | 51 | version.Setup(v => v.Archive.GetFile("1\\scripts\\schema.sql")).Returns(GetStream("ABCDE")); | 54 | version.Setup(v => v.Archive.GetFile("1\\scripts\\schema.sql")).Returns(GetStream("ABCDE")); |
158 | 52 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object); | 55 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object, this.propertyService.Object); |
159 | 53 | 56 | ||
160 | 54 | // Act | 57 | // Act |
161 | 55 | task.Execute(session.Object, 1, 1); | 58 | task.Execute(session.Object, 1, 1); |
162 | @@ -67,7 +70,7 @@ | |||
163 | 67 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); | 70 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); |
164 | 68 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( | 71 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( |
165 | 69 | GetStream("ABCDE" + Environment.NewLine + "GO" + Environment.NewLine + "FGHIJ")); | 72 | GetStream("ABCDE" + Environment.NewLine + "GO" + Environment.NewLine + "FGHIJ")); |
167 | 70 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object); | 73 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object, this.propertyService.Object); |
168 | 71 | 74 | ||
169 | 72 | // Act | 75 | // Act |
170 | 73 | task.Execute(session.Object, 1, 1); | 76 | task.Execute(session.Object, 1, 1); |
171 | @@ -96,7 +99,7 @@ | |||
172 | 96 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); | 99 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); |
173 | 97 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( | 100 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( |
174 | 98 | GetStream(ScriptWithDifferentCasedSeparators)); | 101 | GetStream(ScriptWithDifferentCasedSeparators)); |
176 | 99 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object); | 102 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object, this.propertyService.Object); |
177 | 100 | 103 | ||
178 | 101 | // Act | 104 | // Act |
179 | 102 | task.Execute(session.Object, 1, 1); | 105 | task.Execute(session.Object, 1, 1); |
180 | @@ -124,7 +127,7 @@ | |||
181 | 124 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); | 127 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); |
182 | 125 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( | 128 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( |
183 | 126 | GetStream(ScriptWithSeparatorsWithinLines)); | 129 | GetStream(ScriptWithSeparatorsWithinLines)); |
185 | 127 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object); | 130 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object, this.propertyService.Object); |
186 | 128 | 131 | ||
187 | 129 | // Act | 132 | // Act |
188 | 130 | task.Execute(session.Object, 1, 1); | 133 | task.Execute(session.Object, 1, 1); |
189 | @@ -147,7 +150,7 @@ | |||
190 | 147 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); | 150 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); |
191 | 148 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( | 151 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( |
192 | 149 | GetStream(ScriptWithSeparatorAtStartOfScript)); | 152 | GetStream(ScriptWithSeparatorAtStartOfScript)); |
194 | 150 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object); | 153 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object, this.propertyService.Object); |
195 | 151 | 154 | ||
196 | 152 | // Act | 155 | // Act |
197 | 153 | task.Execute(session.Object, 1, 1); | 156 | task.Execute(session.Object, 1, 1); |
198 | @@ -168,7 +171,7 @@ | |||
199 | 168 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); | 171 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); |
200 | 169 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( | 172 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( |
201 | 170 | GetStream(ScriptWithSeparatorAtEndOfScript)); | 173 | GetStream(ScriptWithSeparatorAtEndOfScript)); |
203 | 171 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object); | 174 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object, this.propertyService.Object); |
204 | 172 | 175 | ||
205 | 173 | // Act | 176 | // Act |
206 | 174 | task.Execute(session.Object, 1, 1); | 177 | task.Execute(session.Object, 1, 1); |
207 | @@ -186,7 +189,7 @@ | |||
208 | 186 | version.Setup(v => v.Archive.GetScriptPath("1\\database.xml", "scripts\\schema.sql")).Returns("1\\scripts\\schema.sql"); | 189 | version.Setup(v => v.Archive.GetScriptPath("1\\database.xml", "scripts\\schema.sql")).Returns("1\\scripts\\schema.sql"); |
209 | 187 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( | 190 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( |
210 | 188 | GetStream(ScriptWithSeparatorAtEndOfScript)); | 191 | GetStream(ScriptWithSeparatorAtEndOfScript)); |
212 | 189 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object); | 192 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object, this.propertyService.Object); |
213 | 190 | Exception exception = new Exception(); | 193 | Exception exception = new Exception(); |
214 | 191 | command.Setup(c=>c.ExecuteNonQuery()).Throws(exception); | 194 | command.Setup(c=>c.ExecuteNonQuery()).Throws(exception); |
215 | 192 | 195 | ||
216 | @@ -207,7 +210,7 @@ | |||
217 | 207 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); | 210 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); |
218 | 208 | version.Setup(v => v.Archive.GetScriptPath("1\\database.xml", "scripts\\schema.sql")).Returns("1\\scripts\\schema.sql"); | 211 | version.Setup(v => v.Archive.GetScriptPath("1\\database.xml", "scripts\\schema.sql")).Returns("1\\scripts\\schema.sql"); |
219 | 209 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns((Stream)null); | 212 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns((Stream)null); |
221 | 210 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object); | 213 | ScriptTask task = new ScriptTask("scripts\\schema.sql", 0, version.Object, messageService.Object, this.propertyService.Object); |
222 | 211 | 214 | ||
223 | 212 | // Act | 215 | // Act |
224 | 213 | Exception thrownException = Record.Exception(() => task.Execute(new Mock<ISession>().Object, 1, 1)); | 216 | Exception thrownException = Record.Exception(() => task.Execute(new Mock<ISession>().Object, 1, 1)); |
225 | @@ -217,6 +220,44 @@ | |||
226 | 217 | Assert.Equal("The script file \"1\\scripts\\schema.sql\" does not exist in the archive.", thrownException.Message); | 220 | Assert.Equal("The script file \"1\\scripts\\schema.sql\" does not exist in the archive.", thrownException.Message); |
227 | 218 | } | 221 | } |
228 | 219 | 222 | ||
229 | 223 | [Fact] | ||
230 | 224 | public void ShouldSetCommandTimeoutIfSpecified() | ||
231 | 225 | { | ||
232 | 226 | // Arrange | ||
233 | 227 | Mock<IDatabaseVersion> version = new Mock<IDatabaseVersion>{ DefaultValue = DefaultValue.Mock }; | ||
234 | 228 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); | ||
235 | 229 | version.Setup(v => v.Archive.GetScriptPath("1\\database.xml", "scripts\\schema.sql")).Returns("1\\scripts\\schema.sql"); | ||
236 | 230 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( | ||
237 | 231 | GetStream(ScriptWithSeparatorAtEndOfScript)); | ||
238 | 232 | var task = new ScriptTask("scripts\\test.sql", 0, version.Object, this.messageService.Object, this.propertyService.Object); | ||
239 | 233 | |||
240 | 234 | propertyService.Setup(p => p.GetInt(ScriptTask.CommandTimeoutPropertyName)).Returns(100); | ||
241 | 235 | |||
242 | 236 | // Act | ||
243 | 237 | task.Execute(this.session.Object, 1, 1); | ||
244 | 238 | |||
245 | 239 | // Assert | ||
246 | 240 | Assert.Equal(100, task.TaskTimeout); | ||
247 | 241 | } | ||
248 | 242 | |||
249 | 243 | [Fact] | ||
250 | 244 | public void ShouldNotSetCommandTimeoutIfNotSpecified() | ||
251 | 245 | { | ||
252 | 246 | // Arrange | ||
253 | 247 | Mock<IDatabaseVersion> version = new Mock<IDatabaseVersion> { DefaultValue = DefaultValue.Mock }; | ||
254 | 248 | version.Setup(v => v.ManifestPath).Returns("1\\database.xml"); | ||
255 | 249 | version.Setup(v => v.Archive.GetScriptPath("1\\database.xml", "scripts\\schema.sql")).Returns("1\\scripts\\schema.sql"); | ||
256 | 250 | version.Setup(v => v.Archive.GetFile(It.IsAny<string>())).Returns( | ||
257 | 251 | GetStream(ScriptWithSeparatorAtEndOfScript)); | ||
258 | 252 | var task = new ScriptTask("scripts\\test.sql", 0, version.Object, this.messageService.Object, this.propertyService.Object); | ||
259 | 253 | |||
260 | 254 | // Act | ||
261 | 255 | task.Execute(this.session.Object, 1, 1); | ||
262 | 256 | |||
263 | 257 | // Assert | ||
264 | 258 | Assert.Null(task.TaskTimeout); | ||
265 | 259 | } | ||
266 | 260 | |||
267 | 220 | private Stream GetStream(string contents) | 261 | private Stream GetStream(string contents) |
268 | 221 | { | 262 | { |
269 | 222 | return new MemoryStream(Encoding.Default.GetBytes(contents)); | 263 | return new MemoryStream(Encoding.Default.GetBytes(contents)); |
270 | 223 | 264 | ||
271 | === modified file 'src/DatabaseVersion/Manifests/ManifestReader.cs' | |||
272 | --- src/DatabaseVersion/Manifests/ManifestReader.cs 2011-10-10 18:43:53 +0000 | |||
273 | +++ src/DatabaseVersion/Manifests/ManifestReader.cs 2012-08-29 19:06:19 +0000 | |||
274 | @@ -58,7 +58,7 @@ | |||
275 | 58 | IDatabaseTaskFactory factory = this.Factories.FirstOrDefault(f => f.CanCreate(element)); | 58 | IDatabaseTaskFactory factory = this.Factories.FirstOrDefault(f => f.CanCreate(element)); |
276 | 59 | if (factory != null) | 59 | if (factory != null) |
277 | 60 | { | 60 | { |
279 | 61 | return factory.Create(element, element.ElementsBeforeSelf().Count(), version, MessageService); | 61 | return factory.Create(element, element.ElementsBeforeSelf().Count(), version); |
280 | 62 | } | 62 | } |
281 | 63 | } | 63 | } |
282 | 64 | 64 | ||
283 | 65 | 65 | ||
284 | === modified file 'src/DatabaseVersion/Property/IPropertyService.cs' | |||
285 | --- src/DatabaseVersion/Property/IPropertyService.cs 2011-09-02 23:16:14 +0000 | |||
286 | +++ src/DatabaseVersion/Property/IPropertyService.cs 2012-08-29 19:06:19 +0000 | |||
287 | @@ -51,6 +51,17 @@ | |||
288 | 51 | /// The prefix to look for. | 51 | /// The prefix to look for. |
289 | 52 | /// </param> | 52 | /// </param> |
290 | 53 | IEnumerable<Property> StartingWith(string prefix); | 53 | IEnumerable<Property> StartingWith(string prefix); |
291 | 54 | |||
292 | 55 | /// <summary> | ||
293 | 56 | /// Gets the specified property as an int. | ||
294 | 57 | /// </summary> | ||
295 | 58 | /// <param name='key'> | ||
296 | 59 | /// The property key. | ||
297 | 60 | /// </param> | ||
298 | 61 | /// <returns> | ||
299 | 62 | /// The int value or null if the property is not defined, or is not an int. | ||
300 | 63 | /// </returns> | ||
301 | 64 | int? GetInt(string key); | ||
302 | 54 | } | 65 | } |
303 | 55 | } | 66 | } |
304 | 56 | 67 | ||
305 | 57 | 68 | ||
306 | === modified file 'src/DatabaseVersion/Property/PropertyService.cs' | |||
307 | --- src/DatabaseVersion/Property/PropertyService.cs 2011-09-03 23:15:46 +0000 | |||
308 | +++ src/DatabaseVersion/Property/PropertyService.cs 2012-08-29 19:06:19 +0000 | |||
309 | @@ -53,14 +53,7 @@ | |||
310 | 53 | { | 53 | { |
311 | 54 | get | 54 | get |
312 | 55 | { | 55 | { |
321 | 56 | Property propertyValue; | 56 | return this.Get(propertyName); |
314 | 57 | |||
315 | 58 | if (this.properties.TryGetValue(propertyName, out propertyValue)) | ||
316 | 59 | { | ||
317 | 60 | return propertyValue; | ||
318 | 61 | } | ||
319 | 62 | |||
320 | 63 | return null; | ||
322 | 64 | } | 57 | } |
323 | 65 | } | 58 | } |
324 | 66 | 59 | ||
325 | @@ -88,6 +81,47 @@ | |||
326 | 88 | { | 81 | { |
327 | 89 | return this.properties.Where(p => p.Key.StartsWith(prefix)).Select(p => p.Value); | 82 | return this.properties.Where(p => p.Key.StartsWith(prefix)).Select(p => p.Value); |
328 | 90 | } | 83 | } |
329 | 84 | |||
330 | 85 | /// <summary> | ||
331 | 86 | /// Gets the specified property as an int. | ||
332 | 87 | /// </summary> | ||
333 | 88 | /// <param name='key'> | ||
334 | 89 | /// The property key. | ||
335 | 90 | /// </param> | ||
336 | 91 | /// <returns> | ||
337 | 92 | /// The int value or null if the property is not defined, or is not an int. | ||
338 | 93 | /// </returns> | ||
339 | 94 | public int? GetInt(string key) | ||
340 | 95 | { | ||
341 | 96 | Validate.NotNull(() => key); | ||
342 | 97 | |||
343 | 98 | int value; | ||
344 | 99 | var property = this.Get(key); | ||
345 | 100 | |||
346 | 101 | if (property != null && int.TryParse(property.Value, out value)) | ||
347 | 102 | { | ||
348 | 103 | return value; | ||
349 | 104 | } | ||
350 | 105 | |||
351 | 106 | return null; | ||
352 | 107 | } | ||
353 | 108 | |||
354 | 109 | /// <summary> | ||
355 | 110 | /// Get the property with the specified name. | ||
356 | 111 | /// </summary> | ||
357 | 112 | /// <param name='propertyName'> | ||
358 | 113 | /// The name of the property. | ||
359 | 114 | /// </param> | ||
360 | 115 | private Property Get(string propertyName) | ||
361 | 116 | { | ||
362 | 117 | Property propertyValue; | ||
363 | 118 | if (this.properties.TryGetValue(propertyName, out propertyValue)) | ||
364 | 119 | { | ||
365 | 120 | return propertyValue; | ||
366 | 121 | } | ||
367 | 122 | |||
368 | 123 | return null; | ||
369 | 124 | } | ||
370 | 91 | } | 125 | } |
371 | 92 | } | 126 | } |
372 | 93 | 127 | ||
373 | 94 | 128 | ||
374 | === modified file 'src/DatabaseVersion/Tasks/IDatabaseTaskFactory.cs' | |||
375 | --- src/DatabaseVersion/Tasks/IDatabaseTaskFactory.cs 2011-10-10 18:43:53 +0000 | |||
376 | +++ src/DatabaseVersion/Tasks/IDatabaseTaskFactory.cs 2012-08-29 19:06:19 +0000 | |||
377 | @@ -19,8 +19,7 @@ | |||
378 | 19 | /// <param name="element">The element containing the definition of the task.</param> | 19 | /// <param name="element">The element containing the definition of the task.</param> |
379 | 20 | /// <param name="executionOrder">The zero-based execution order of the task.</param> | 20 | /// <param name="executionOrder">The zero-based execution order of the task.</param> |
380 | 21 | /// <param name="version">The database version that the task is contained within.</param> | 21 | /// <param name="version">The database version that the task is contained within.</param> |
381 | 22 | /// <param name="messageService">The Message Service to use for logging</param> | ||
382 | 23 | /// <returns>The new task.</returns> | 22 | /// <returns>The new task.</returns> |
384 | 24 | IDatabaseTask Create(XElement element, int executionOrder, IDatabaseVersion version, IMessageService messageService); | 23 | IDatabaseTask Create(XElement element, int executionOrder, IDatabaseVersion version); |
385 | 25 | } | 24 | } |
386 | 26 | } | 25 | } |
387 | 27 | 26 | ||
388 | === modified file 'src/DatabaseVersion/Tasks/Sql/ScriptTask.cs' | |||
389 | --- src/DatabaseVersion/Tasks/Sql/ScriptTask.cs 2012-01-24 22:01:24 +0000 | |||
390 | +++ src/DatabaseVersion/Tasks/Sql/ScriptTask.cs 2012-08-29 19:06:19 +0000 | |||
391 | @@ -9,6 +9,7 @@ | |||
392 | 9 | using System.Diagnostics; | 9 | using System.Diagnostics; |
393 | 10 | using System.Text.RegularExpressions; | 10 | using System.Text.RegularExpressions; |
394 | 11 | 11 | ||
395 | 12 | using dbversion.Property; | ||
396 | 12 | using dbversion.Version; | 13 | using dbversion.Version; |
397 | 13 | 14 | ||
398 | 14 | using NHibernate; | 15 | using NHibernate; |
399 | @@ -27,6 +28,11 @@ | |||
400 | 27 | "{0}{1}|{0}{1}{0}|{1}{0}"; | 28 | "{0}{1}|{0}{1}{0}|{1}{0}"; |
401 | 28 | 29 | ||
402 | 29 | /// <summary> | 30 | /// <summary> |
403 | 31 | /// The name of the command timeout property. | ||
404 | 32 | /// </summary> | ||
405 | 33 | public const string CommandTimeoutPropertyName = "dbversion.sql.command_timeout"; | ||
406 | 34 | |||
407 | 35 | /// <summary> | ||
408 | 30 | /// The regex object created from the regex format. | 36 | /// The regex object created from the regex format. |
409 | 31 | /// </summary> | 37 | /// </summary> |
410 | 32 | private readonly Regex StringSplitRegex; | 38 | private readonly Regex StringSplitRegex; |
411 | @@ -36,15 +42,30 @@ | |||
412 | 36 | /// </summary> | 42 | /// </summary> |
413 | 37 | private readonly IDatabaseVersion version; | 43 | private readonly IDatabaseVersion version; |
414 | 38 | 44 | ||
415 | 45 | private readonly IPropertyService propertyService; | ||
416 | 46 | |||
417 | 39 | protected override string GetTaskDescription() | 47 | protected override string GetTaskDescription() |
418 | 40 | { | 48 | { |
419 | 41 | return string.Format("Executing script \"{0}\"", this.GetScriptPath()); | 49 | return string.Format("Executing script \"{0}\"", this.GetScriptPath()); |
420 | 42 | } | 50 | } |
421 | 43 | 51 | ||
423 | 44 | public ScriptTask(string fileName, int executionOrder, IDatabaseVersion version, IMessageService messageService) | 52 | /// <summary> |
424 | 53 | /// The Timeout in seconds for the task | ||
425 | 54 | /// </summary> | ||
426 | 55 | /// <returns>The Timeout in seconds or if none set null</returns> | ||
427 | 56 | public int? TaskTimeout | ||
428 | 57 | { | ||
429 | 58 | get | ||
430 | 59 | { | ||
431 | 60 | return this.propertyService.GetInt(CommandTimeoutPropertyName); | ||
432 | 61 | } | ||
433 | 62 | } | ||
434 | 63 | |||
435 | 64 | public ScriptTask(string fileName, int executionOrder, IDatabaseVersion version, IMessageService messageService, IPropertyService propertyService) | ||
436 | 45 | : base(fileName, executionOrder, messageService) | 65 | : base(fileName, executionOrder, messageService) |
437 | 46 | { | 66 | { |
438 | 47 | this.version = version; | 67 | this.version = version; |
439 | 68 | this.propertyService = propertyService; | ||
440 | 48 | 69 | ||
441 | 49 | this.StringSplitRegex = GetStringSplitRegex(); | 70 | this.StringSplitRegex = GetStringSplitRegex(); |
442 | 50 | } | 71 | } |
443 | @@ -119,6 +140,7 @@ | |||
444 | 119 | using (var command = session.Connection.CreateCommand()) | 140 | using (var command = session.Connection.CreateCommand()) |
445 | 120 | { | 141 | { |
446 | 121 | session.Transaction.Enlist(command); | 142 | session.Transaction.Enlist(command); |
447 | 143 | if (TaskTimeout.HasValue) command.CommandTimeout = TaskTimeout.Value; | ||
448 | 122 | command.CommandText = batch; | 144 | command.CommandText = batch; |
449 | 123 | command.ExecuteNonQuery(); | 145 | command.ExecuteNonQuery(); |
450 | 124 | } | 146 | } |
451 | 125 | 147 | ||
452 | === modified file 'src/DatabaseVersion/Tasks/Sql/ScriptTaskFactory.cs' | |||
453 | --- src/DatabaseVersion/Tasks/Sql/ScriptTaskFactory.cs 2011-10-10 09:00:52 +0000 | |||
454 | +++ src/DatabaseVersion/Tasks/Sql/ScriptTaskFactory.cs 2012-08-29 19:06:19 +0000 | |||
455 | @@ -7,19 +7,34 @@ | |||
456 | 7 | using System.Xml.Linq; | 7 | using System.Xml.Linq; |
457 | 8 | using System.ComponentModel.Composition; | 8 | using System.ComponentModel.Composition; |
458 | 9 | 9 | ||
459 | 10 | using dbversion.Property; | ||
460 | 10 | using dbversion.Version; | 11 | using dbversion.Version; |
461 | 11 | 12 | ||
462 | 12 | [Export(typeof(IDatabaseTaskFactory))] | 13 | [Export(typeof(IDatabaseTaskFactory))] |
463 | 13 | public class ScriptTaskFactory : IDatabaseTaskFactory | 14 | public class ScriptTaskFactory : IDatabaseTaskFactory |
464 | 14 | { | 15 | { |
465 | 16 | [Import] | ||
466 | 17 | public IPropertyService PropertyService | ||
467 | 18 | { | ||
468 | 19 | get; | ||
469 | 20 | set; | ||
470 | 21 | } | ||
471 | 22 | |||
472 | 23 | [Import] | ||
473 | 24 | public IMessageService MessageService | ||
474 | 25 | { | ||
475 | 26 | get; | ||
476 | 27 | set; | ||
477 | 28 | } | ||
478 | 29 | |||
479 | 15 | public bool CanCreate(XElement element) | 30 | public bool CanCreate(XElement element) |
480 | 16 | { | 31 | { |
481 | 17 | return element != null && element.Name == "script"; | 32 | return element != null && element.Name == "script"; |
482 | 18 | } | 33 | } |
483 | 19 | 34 | ||
485 | 20 | public IDatabaseTask Create(XElement element, int executionOrder, IDatabaseVersion version, IMessageService messageService) | 35 | public IDatabaseTask Create(XElement element, int executionOrder, IDatabaseVersion version) |
486 | 21 | { | 36 | { |
488 | 22 | return new ScriptTask(element.Attribute(XName.Get("file")).Value, executionOrder, version, messageService); | 37 | return new ScriptTask(element.Attribute(XName.Get("file")).Value, executionOrder, version, this.MessageService, this.PropertyService); |
489 | 23 | } | 38 | } |
490 | 24 | } | 39 | } |
491 | 25 | } | 40 | } |
All looks good to me.