1 #region Copyright © 2003-2008 Richard Beauchamp <rbeauchamp@gmail.com> 2 3 /* 4 * DomainObjects for .NET 5 * Copyright © 2003-2008 Richard Beauchamp 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 22 #endregion 23 24 using System.Collections.Generic; 25 using DomainObjects.Facade.Domain; 26 using DomainObjects.Facade.Transaction; 27 using DomainObjects.Test.Domain; 28 using NUnit.Framework; 29 30 namespace DomainObjects.Test.TestType.Service 31 { 32 /// <summary> 33 /// Within the implementation of <see cref="AfterCommit"/>, <see cref="ReorderValidator"/> validates that 34 /// DomainObjects has ordered the object transaction set correctly. 35 /// 36 /// This class is referred to by ITransactionSetAware interface documentation. 37 /// </summary> 38 public class ReorderValidator : ITransactionSetAware 39 { 40 /// <summary> 41 /// Called by DomainObjects before the current object transaction 42 /// begins the commit phase of the transaction. 43 /// </summary> 44 /// <param name="boundObjects">The objects that will be committed by the current transaction.</param> 45 public void BeforeCommit(List<TransactableObject> boundObjects) 46 { 47 // nothing implemented in this method 48 } 49 50 /// <summary> 51 /// Called by DomainObjects after the current object transaction 52 /// has successfully completed the commit phase of the transaction. 53 /// </summary> 54 /// <param name="boundObjects">The objects that were successfully committed by the current transaction.</param> 55 public void AfterCommit(List<TransactableObject> boundObjects) 56 { 57 bool foundProduct = false; 58 59 // validate that all ProductCategory instances in the transaction set 60 // have been ordered by DomainObjects before all Product instances. 61 foreach (TransactableObject boundObject in boundObjects) 62 { 63 if (boundObject is Product) 64 { 65 foundProduct = true; 66 } 67 else if (boundObject is ProductCategory) 68 { 69 Assert.IsTrue(!foundProduct, "An instance of a product was not found before an instance of a ProductCategory."); 70 } 71 } 72 } 73 74 /// <summary> 75 /// Called by DomainObjects if the current object transaction is aborted. 76 /// </summary> 77 /// <param name="boundObjects">The objects that were involved in the aborted transaction.</param> 78 public void OnAbort(List<TransactableObject> boundObjects) 79 { 80 // nothing implemented in this method 81 } 82 } 83 }