public override void SetUp() { base.SetUp(); _owningOrder = DomainObjectIDs.Order1.GetObject <Order> (); _endPointID = RelationEndPointID.Resolve(_owningOrder, o => o.OrderItems); _collectionEndPointMock = MockRepository.GenerateStrictMock <ICollectionEndPoint>(); StubCollectionEndPoint(_collectionEndPointMock, TestableClientTransaction, _owningOrder); _virtualEndPointProviderStub = MockRepository.GenerateStub <IVirtualEndPointProvider> (); _virtualEndPointProviderStub .Stub(stub => stub.GetOrCreateVirtualEndPoint(_endPointID)) .Return(_collectionEndPointMock); _endPointDataStub = MockRepository.GenerateStub <IDomainObjectCollectionData>(); _endPointDataDecorator = new ReadOnlyCollectionDataDecorator(_endPointDataStub); _commandStub = MockRepository.GenerateStub <IDataManagementCommand>(); _nestedCommandMock = MockRepository.GenerateMock <IDataManagementCommand> (); _nestedCommandMock.Stub(stub => stub.GetAllExceptions()).Return(new Exception[0]); _expandedCommandFake = new ExpandedCommand(_nestedCommandMock); _delegatingData = new EndPointDelegatingCollectionData(_endPointID, _virtualEndPointProviderStub); _orderItem1 = DomainObjectIDs.OrderItem1.GetObject <OrderItem>(); _orderItem2 = DomainObjectIDs.OrderItem2.GetObject <OrderItem>(); ClientTransactionScope.EnterNullScope(); // no active transaction }
public override void SetUp() { base.SetUp(); _order1 = DomainObjectIDs.Order1.GetObject <Order> (Transaction); _order2 = DomainObjectIDs.Order2.GetObject <Order> (Transaction); _order3 = DomainObjectIDs.Order3.GetObject <Order> (Transaction); // Collection currently contains _order1, _order2 _modifiedCollectionData = new DomainObjectCollectionData(new[] { _order1, _order2 }); // _order1 will stay, _order2 will be removed, _order3 will be added _newCollection = new OrderCollection { _order1, _order3 }; _mockRepository = new MockRepository(); _collectionManagerMock = _mockRepository.StrictMock <ICollectionEndPointCollectionManager> (); _command = new CollectionEndPointSetCollectionCommand( CollectionEndPoint, _newCollection, _modifiedCollectionData, _collectionManagerMock, TransactionEventSinkMock); }
public static void Add(this IDomainObjectCollectionData data, DomainObject domainObject) { ArgumentUtility.CheckNotNull("data", data); ArgumentUtility.CheckNotNull("domainObject", domainObject); data.Insert(data.Count, domainObject); }
public bool HasDataChanged(IDomainObjectCollectionData currentData, IDomainObjectCollectionData originalData) { ArgumentUtility.CheckNotNull("currentData", currentData); ArgumentUtility.CheckNotNull("originalData", originalData); return(!originalData.SequenceEqual(currentData)); }
public CollectionEndPointSetCollectionCommand( ICollectionEndPoint modifiedEndPoint, DomainObjectCollection newCollection, IDomainObjectCollectionData modifiedCollectionData, ICollectionEndPointCollectionManager collectionEndPointCollectionManager, IClientTransactionEventSink transactionEventSink) : base( ArgumentUtility.CheckNotNull("modifiedEndPoint", modifiedEndPoint), null, null, ArgumentUtility.CheckNotNull("transactionEventSink", transactionEventSink)) { ArgumentUtility.CheckNotNull("newCollection", newCollection); ArgumentUtility.CheckNotNull("modifiedCollectionData", modifiedCollectionData); ArgumentUtility.CheckNotNull("collectionEndPointCollectionManager", collectionEndPointCollectionManager); if (modifiedEndPoint.IsNull) { throw new ArgumentException("Modified end point is null, a NullEndPointModificationCommand is needed.", "modifiedEndPoint"); } _newCollection = newCollection; _modifiedCollectionData = modifiedCollectionData; _collectionEndPointCollectionManager = collectionEndPointCollectionManager; var oldOppositeObjects = ModifiedCollectionData; _removedObjects = oldOppositeObjects.Where(oldObject => !NewCollection.Contains(oldObject.ID)).ToArray(); var newOppositeObjects = NewCollection.Cast <DomainObject> (); _addedObjects = newOppositeObjects.Where(newObject => !ModifiedCollectionData.ContainsObjectID(newObject.ID)).ToArray(); }
public CollectionEndPointRemoveCommand( ICollectionEndPoint modifiedEndPoint, DomainObject removedObject, IDomainObjectCollectionData collectionData, IRelationEndPointProvider endPointProvider, IClientTransactionEventSink transactionEventSink) : base( ArgumentUtility.CheckNotNull("modifiedEndPoint", modifiedEndPoint), ArgumentUtility.CheckNotNull("removedObject", removedObject), null, ArgumentUtility.CheckNotNull("transactionEventSink", transactionEventSink)) { ArgumentUtility.CheckNotNull("collectionData", collectionData); ArgumentUtility.CheckNotNull("endPointProvider", endPointProvider); if (modifiedEndPoint.IsNull) { throw new ArgumentException("Modified end point is null, a NullEndPointModificationCommand is needed.", "modifiedEndPoint"); } _index = modifiedEndPoint.Collection.IndexOf(removedObject); _modifiedCollectionData = collectionData; _modifiedCollection = modifiedEndPoint.Collection; _endPointProvider = endPointProvider; }
public static void AddRangeAndCheckItems(this IDomainObjectCollectionData data, IEnumerable <DomainObject> domainObjects, Type requiredItemType) { ArgumentUtility.CheckNotNull("data", data); ArgumentUtility.CheckNotNull("domainObjects", domainObjects); var index = 0; foreach (var domainObject in domainObjects) { if (domainObject == null) { throw ArgumentUtility.CreateArgumentItemNullException("domainObjects", index); } if (requiredItemType != null && !requiredItemType.IsInstanceOfType(domainObject)) { throw ArgumentUtility.CreateArgumentItemTypeException("domainObjects", index, requiredItemType, domainObject.ID.ClassDefinition.ClassType); } if (data.ContainsObjectID(domainObject.ID)) { throw new ArgumentException( string.Format("Item {1} of parameter '{0}' is a duplicate ('{2}').", "domainObjects", index, domainObject.ID), "domainObjects"); } data.Add(domainObject); ++index; } }
/// <summary> /// Initializes a new <see cref="DomainObjectCollection"/> as a shallow copy of a given enumeration of <see cref="DomainObject"/>s. /// </summary> /// <param name="domainObjects">The <see cref="DomainObject"/>s to copy. Must not be <see langword="null"/>.</param> /// <param name="requiredItemType">The required item type of the new collection.</param> /// <exception cref="System.ArgumentNullException"><paramref name="domainObjects"/> is <see langword="null"/>.</exception> public DomainObjectCollection(IEnumerable <DomainObject> domainObjects, Type requiredItemType) { var dataStore = new DomainObjectCollectionData(); dataStore.AddRangeAndCheckItems(domainObjects, requiredItemType); _dataStrategy = CreateDataStrategyForStandAloneCollection(dataStore, requiredItemType, this); }
public static void ReplaceContents(this IDomainObjectCollectionData data, IEnumerable <DomainObject> domainObjects) { ArgumentUtility.CheckNotNull("data", data); ArgumentUtility.CheckNotNull("domainObjects", domainObjects); data.Clear(); data.AddRange(domainObjects); }
IDomainObjectCollectionData IAssociatableDomainObjectCollection.TransformToStandAlone() { var originalDataStrategy = _dataStrategy; // copy data so that new stand-alone collection contains the same data as before var standAloneDataStore = new DomainObjectCollectionData(_dataStrategy); _dataStrategy = CreateDataStrategyForStandAloneCollection(standAloneDataStore, RequiredItemType, this); return(originalDataStrategy); }
private void CheckOriginalDataMatches(IDomainObjectCollectionData expected, IDomainObjectCollectionData actual) { var expectedInner = DomainObjectCollectionDataTestHelper.GetWrappedDataAndCheckType <CopyOnWriteDomainObjectCollectionData> ( (ReadOnlyCollectionDataDecorator)expected); var actualInner = DomainObjectCollectionDataTestHelper.GetWrappedDataAndCheckType <CopyOnWriteDomainObjectCollectionData> ( (ReadOnlyCollectionDataDecorator)actual); Assert.That(actualInner, Is.SameAs(expectedInner)); }
/// <summary> /// Creates an <see cref="IDomainObjectCollectionData"/> object for stand-alone collections. The returned object takes care of argument checks, /// required item checks, and event raising. /// </summary> /// <param name="dataStore">The data store to use for the collection.</param> /// <param name="requiredItemType">The required item type to use for the collection.</param> /// <param name="eventRaiser">The event raiser to use for raising events.</param> /// <returns>An instance of <see cref="IDomainObjectCollectionData"/> that can be used for stand-alone collections.</returns> public static IDomainObjectCollectionData CreateDataStrategyForStandAloneCollection( IDomainObjectCollectionData dataStore, Type requiredItemType, IDomainObjectCollectionEventRaiser eventRaiser) { ArgumentUtility.CheckNotNull("dataStore", dataStore); ArgumentUtility.CheckNotNull("eventRaiser", eventRaiser); return(new ModificationCheckingCollectionDataDecorator(requiredItemType, new EventRaisingCollectionDataDecorator(eventRaiser, dataStore))); }
IDomainObjectCollectionData IAssociatableDomainObjectCollection.TransformToAssociated( RelationEndPointID endPointID, IAssociatedCollectionDataStrategyFactory associatedCollectionDataStrategyFactory) { ArgumentUtility.CheckNotNull("endPointID", endPointID); var originalDataStrategy = _dataStrategy; _dataStrategy = associatedCollectionDataStrategyFactory.CreateDataStrategyForEndPoint(endPointID); return(originalDataStrategy); }
public static void AddRange(this IDomainObjectCollectionData data, IEnumerable <DomainObject> domainObjects) { ArgumentUtility.CheckNotNull("data", data); ArgumentUtility.CheckNotNull("domainObjects", domainObjects); foreach (var domainObject in domainObjects) { Add(data, domainObject); } }
public override void SetUp() { base.SetUp(); _domainObject = DomainObjectMother.CreateFakeObject <Order> (); _wrappedData = new DomainObjectCollectionData(new[] { _domainObject }); _decoratorWithRealData = new ChangeCachingCollectionDataDecorator(_wrappedData); _strategyStrictMock = new MockRepository().StrictMock <ICollectionEndPointChangeDetectionStrategy> (); }
public override void SetUp() { base.SetUp(); _wrappedDataStub = MockRepository.GenerateStub <IDomainObjectCollectionData>(); _readOnlyDecorator = new ReadOnlyCollectionDataDecorator(_wrappedDataStub); _order1 = DomainObjectIDs.Order1.GetObject <Order> (); _order3 = DomainObjectIDs.Order3.GetObject <Order> (); _order4 = DomainObjectIDs.Order4.GetObject <Order> (); _order5 = DomainObjectIDs.Order5.GetObject <Order> (); }
public ChangeCachingCollectionDataDecorator(IDomainObjectCollectionData wrappedData) : base(new ObservableCollectionDataDecorator(ArgumentUtility.CheckNotNull("wrappedData", wrappedData))) { _observedWrappedData = (ObservableCollectionDataDecorator)WrappedData; _unobservedWrappedData = wrappedData; _originalData = new CopyOnWriteDomainObjectCollectionData(_observedWrappedData); _observedWrappedData.CollectionChanged += WrappedData_CollectionChanged(); _isCacheUpToDate = true; _cachedHasChangedFlag = false; }
public override void SetUp() { base.SetUp(); _mockRepository = new MockRepository(); _wrappedDataMock = _mockRepository.StrictMock <IDomainObjectCollectionData> (); _decorator = new TestDomainObjectCollectionDecorator(_wrappedDataMock); _order1 = DomainObjectMother.CreateFakeObject <Order> (); _order3 = DomainObjectMother.CreateFakeObject <Order> (); }
public override void SetUp() { base.SetUp(); _wrappedDataMock = MockRepository.GenerateMock <IDomainObjectCollectionData> (); _modificationCheckingDecorator = new ModificationCheckingCollectionDataDecorator(typeof(Order), _wrappedDataMock); _modificationCheckingDecoratorWithoutRequiredItemType = new ModificationCheckingCollectionDataDecorator(null, _wrappedDataMock); _order1 = DomainObjectIDs.Order1.GetObject <Order> (); _order3 = DomainObjectIDs.Order3.GetObject <Order> (); _orderItem1 = DomainObjectIDs.OrderItem1.GetObject <OrderItem>(); }
public override void SetUp() { base.SetUp(); _order1 = DomainObjectIDs.Order1.GetObject <Order> (); _order3 = DomainObjectIDs.Order3.GetObject <Order> (); _order4 = DomainObjectIDs.Order4.GetObject <Order> (); _currentData = new DomainObjectCollectionData(new[] { _order1, _order3 }); _strategy = new SubCollectionEndPointChangeDetectionStrategy(); }
public override void SetUp() { base.SetUp(); _associatedCollectionDataStrategyFactoryMock = MockRepository.GenerateStrictMock <IAssociatedCollectionDataStrategyFactory> (); _provider = new CollectionEndPointCollectionProvider(_associatedCollectionDataStrategyFactoryMock); _endPointID = RelationEndPointID.Create(DomainObjectIDs.Customer1, typeof(Customer), "Orders"); _dataStrategyStub = MockRepository.GenerateStub <IDomainObjectCollectionData> (); _dataStrategyStub.Stub(stub => stub.RequiredItemType).Return(typeof(Order)); }
private static IDomainObjectCollectionData CheckStrategy(IDomainObjectCollectionData dataStrategy) { ArgumentUtility.CheckNotNull("dataStrategy", dataStrategy); if (!typeof(T).IsAssignableFrom(dataStrategy.RequiredItemType) && !dataStrategy.IsReadOnly) { var message = string.Format( "The given data strategy must have a required item type of '{0}' in order to be used with this collection type.", typeof(T)); throw new ArgumentException(message, "dataStrategy"); } return(dataStrategy); }
public static void CheckAssociatedCollectionStrategy( IDomainObjectCollectionData domainObjectCollectionData, Type expectedRequiredItemType, RelationEndPointID expectedEndPointID) { Assert.That(domainObjectCollectionData, Is.TypeOf <ModificationCheckingCollectionDataDecorator> ()); var checkingDecorator = (ModificationCheckingCollectionDataDecorator)domainObjectCollectionData; Assert.That(checkingDecorator.RequiredItemType, Is.SameAs(expectedRequiredItemType)); var delegator = GetWrappedDataAndCheckType <EndPointDelegatingCollectionData> (checkingDecorator); Assert.That(delegator.AssociatedEndPointID, Is.EqualTo(expectedEndPointID)); }
public override void SetUp() { base.SetUp(); _customer1 = DomainObjectIDs.Customer1.GetObject <Customer> (); _customer2 = DomainObjectIDs.Customer2.GetObject <Customer> (); _customer3NotInCollection = DomainObjectIDs.Customer3.GetObject <Customer> (); _collection = CreateCustomerCollection(); _readOnlyCollection = DomainObjectCollectionFactory.Instance.CreateReadOnlyCollection( typeof(DomainObjectCollection), new[] { _customer1, _customer2 }); _dataStrategyMock = MockRepository.GenerateMock <IDomainObjectCollectionData> (); _collectionWithDataStrategyMock = new DomainObjectCollection(_dataStrategyMock); }
/// <summary> /// Creates a collection of the given <paramref name="collectionType"/> via reflection, passing in the given /// <see cref="IDomainObjectCollectionData"/> object as the data storage strategy. /// The collection must provide a constructor that takes a single parameter of type <see cref="IDomainObjectCollectionData"/>. /// </summary> /// <param name="collectionType">The type of the collection to create.</param> /// <param name="dataStrategy">The data strategy to use for the new collection.</param> /// <returns>An instance of the given <paramref name="collectionType"/>.</returns> /// <exception cref="MissingMethodException">The <paramref name="collectionType"/> does not provide a constructor taking /// a single parameter of type <see cref="IDomainObjectCollectionData"/>.</exception> public DomainObjectCollection CreateCollection(Type collectionType, IDomainObjectCollectionData dataStrategy) { ArgumentUtility.CheckNotNull("collectionType", collectionType); ArgumentUtility.CheckNotNull("dataStrategy", dataStrategy); var ctor = collectionType.GetConstructor( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(IDomainObjectCollectionData) }, null); if (ctor == null) { throw CreateMissingConstructorException(collectionType); } return((DomainObjectCollection)ctor.Invoke(new[] { dataStrategy })); }
public CollectionEndPointDeleteCommand( ICollectionEndPoint modifiedEndPoint, IDomainObjectCollectionData collectionData, IClientTransactionEventSink transactionEventSink) : base( ArgumentUtility.CheckNotNull("modifiedEndPoint", modifiedEndPoint), null, null, ArgumentUtility.CheckNotNull("transactionEventSink", transactionEventSink)) { if (modifiedEndPoint.IsNull) { throw new ArgumentException("Modified end point is null, a NullEndPointModificationCommand is needed.", "modifiedEndPoint"); } _modifiedCollectionData = collectionData; _modifiedCollection = modifiedEndPoint.Collection; }
public static bool SetEquals(this IDomainObjectCollectionData collection, IEnumerable <DomainObject> comparedSet) { ArgumentUtility.CheckNotNull("collection", collection); ArgumentUtility.CheckNotNull("comparedSet", comparedSet); var setOfComparedObjects = new HashSet <DomainObject> (); // this is used to get rid of all duplicates to get a correct result foreach (var domainObject in comparedSet) { if (collection.GetObject(domainObject.ID) != domainObject) { return(false); } setOfComparedObjects.Add(domainObject); } // the collection must contain exactly the same number of items as the comparedSet (duplicates ignored) return(collection.Count == setOfComparedObjects.Count); }
public override void SetUp() { base.SetUp(); _transaction = ClientTransaction.CreateRootTransaction(); _domainObject = DomainObjectIDs.Customer1.GetObject <Customer> (_transaction); _order1 = DomainObjectIDs.Order1.GetObject <Order> (_transaction); _order2 = DomainObjectIDs.Order2.GetObject <Order> (_transaction); _relationEndPointID = RelationEndPointID.Create(DomainObject.ID, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders"); _collectionEndPoint = RelationEndPointObjectMother.CreateCollectionEndPoint( _relationEndPointID, new[] { _order1, _order2 }, _transaction); _collectionMockEventReceiver = MockRepository.GenerateStrictMock <DomainObjectCollectionMockEventReceiver> (_collectionEndPoint.Collection); _collectionDataMock = new MockRepository().StrictMock <IDomainObjectCollectionData> (); CollectionDataMock.Replay(); _endPointProviderStub = MockRepository.GenerateStub <IRelationEndPointProvider>(); _transactionEventSinkMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>(); }
protected DomainObjectCollectionDataDecoratorBase(IDomainObjectCollectionData wrappedData) { ArgumentUtility.CheckNotNull("wrappedData", wrappedData); _wrappedData = wrappedData; }
public TestableObservableCollectionDataDecorator(IDomainObjectCollectionData wrappedData, IEventSink eventSink) : base(wrappedData) { _eventSink = eventSink; }