|
9 | 9 | using OnTopic.Metadata;
|
10 | 10 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
11 | 11 | using OnTopic.Collections;
|
| 12 | +using OnTopic.Attributes; |
12 | 13 |
|
13 | 14 | namespace OnTopic.Tests {
|
14 | 15 |
|
@@ -278,21 +279,71 @@ public void LastModified_UpdateValue_ReturnsExpectedValue() {
|
278 | 279 | Assert.AreEqual<DateTime>(lastModified, topic.LastModified);
|
279 | 280 |
|
280 | 281 | }
|
| 282 | + |
281 | 283 | /*==========================================================================================================================
|
282 | 284 | | TEST: DERIVED TOPIC: UPDATE VALUE: RETURNS EXPECTED VALUE
|
283 | 285 | \-------------------------------------------------------------------------------------------------------------------------*/
|
284 | 286 | /// <summary>
|
285 |
| - /// Sets a derived topic, and ensures it is referenced correctly. |
| 287 | + /// Sets a derived topic to a topic entity, then replaces the references with a new topic entity. Ensures that both the |
| 288 | + /// derived topic as well as the underlying <see cref="AttributeValue"/> correctly reference the new value. |
286 | 289 | /// </summary>
|
287 | 290 | [TestMethod]
|
288 | 291 | public void DerivedTopic_UpdateValue_ReturnsExpectedValue() {
|
289 | 292 |
|
| 293 | + var topic = TopicFactory.Create("Topic", "Page"); |
| 294 | + var firstDerivedTopic = TopicFactory.Create("DerivedTopic", "Page"); |
| 295 | + var secondDerivedTopic = TopicFactory.Create("DerivedTopic", "Page", 1); |
| 296 | + var finalDerivedTopic = TopicFactory.Create("DerivedTopic", "Page", 2); |
| 297 | + |
| 298 | + topic.DerivedTopic = firstDerivedTopic; |
| 299 | + topic.DerivedTopic = secondDerivedTopic; |
| 300 | + topic.DerivedTopic = finalDerivedTopic; |
| 301 | + |
| 302 | + Assert.ReferenceEquals(topic.DerivedTopic, finalDerivedTopic); |
| 303 | + Assert.AreEqual<int>(2, topic.Attributes.GetInteger("TopicID", 0)); |
| 304 | + |
| 305 | + } |
| 306 | + |
| 307 | + /*========================================================================================================================== |
| 308 | + | TEST: DERIVED TOPIC: UNSAVED VALUE: RETURNS EXPECTED VALUE |
| 309 | + \-------------------------------------------------------------------------------------------------------------------------*/ |
| 310 | + /// <summary> |
| 311 | + /// Sets a derived topic to an unsaved topic entity. Ensures that the derived topic is correctly set, but that the <see |
| 312 | + /// cref="Topic.Id"/> is not persisted as an underlying <see cref="AttributeValue"/>. |
| 313 | + /// </summary> |
| 314 | + [TestMethod] |
| 315 | + public void DerivedTopic_UnsavedValue_ReturnsExpectedValue() { |
| 316 | + |
290 | 317 | var topic = TopicFactory.Create("Topic", "Page");
|
291 | 318 | var derivedTopic = TopicFactory.Create("DerivedTopic", "Page");
|
292 | 319 |
|
293 | 320 | topic.DerivedTopic = derivedTopic;
|
294 | 321 |
|
295 | 322 | Assert.ReferenceEquals(topic.DerivedTopic, derivedTopic);
|
| 323 | + Assert.AreEqual<int>(-2, topic.Attributes.GetInteger("TopicID", -2)); |
| 324 | + |
| 325 | + } |
| 326 | + |
| 327 | + /*========================================================================================================================== |
| 328 | + | TEST: DERIVED TOPIC: RESAVED VALUE: RETURNS EXPECTED VALUE |
| 329 | + \-------------------------------------------------------------------------------------------------------------------------*/ |
| 330 | + /// <summary> |
| 331 | + /// Sets a derived topic to an unsaved topic entity, then saves the entity and reestablishes the relationship. Ensures |
| 332 | + /// that the derived topic is correctly set, including the <see cref="Topic.Id"/> as an underlying <see |
| 333 | + /// cref="AttributeValue"/>. |
| 334 | + /// </summary> |
| 335 | + [TestMethod] |
| 336 | + public void DerivedTopic_ResavedValue_ReturnsExpectedValue() { |
| 337 | + |
| 338 | + var topic = TopicFactory.Create("Topic", "Page"); |
| 339 | + var derivedTopic = TopicFactory.Create("DerivedTopic", "Page"); |
| 340 | + |
| 341 | + topic.DerivedTopic = derivedTopic; |
| 342 | + derivedTopic.Id = 5; |
| 343 | + topic.DerivedTopic = derivedTopic; |
| 344 | + |
| 345 | + Assert.ReferenceEquals(topic.DerivedTopic, derivedTopic); |
| 346 | + Assert.AreEqual<int>(5, topic.Attributes.GetInteger("TopicID", -2)); |
296 | 347 |
|
297 | 348 | }
|
298 | 349 |
|
|
0 commit comments