Пример #1
0
        public void AddingItemsLazily_AndManually_AsParent_CountIsCorrect()
        {
            // Arrange
            var existingItemForParent        = HiveModelCreationHelper.MockTypedEntity();
            var unsavedItemForAddingAsParent = HiveModelCreationHelper.MockTypedEntity();
            var connectedChild = HiveModelCreationHelper.MockTypedEntity();

            existingItemForParent.Id = HiveId.ConvertIntToGuid(1); // Assign Ids to mimic a lazy-loading valid scenario
            connectedChild.Id        = HiveId.ConvertIntToGuid(2); // It's connected with a lazy-loader so it should have an Id

            var rpc = new RelationProxyCollection(connectedChild);

            // Act
            // This delegate mimics a lazy-loader, which returns RelationById to stipulate that
            // the lazy loader must return existing items from the datastore
            rpc.LazyLoadDelegate = ownerIdOfCollection =>
            {
                var parent = new RelationById(HiveId.ConvertIntToGuid(1), ownerIdOfCollection, FixedRelationTypes.DefaultRelationType, 0);
                var parentShouldOverrideManuallyAdded = new RelationById(existingItemForParent.Id, ownerIdOfCollection, FixedRelationTypes.DefaultRelationType, 0);
                return(new RelationProxyBucket(new[] { parent, parentShouldOverrideManuallyAdded }, Enumerable.Empty <RelationById>()));
            };
            rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType);

            // Assert
            Assert.AreEqual(1, rpc.Count());
            Assert.AreEqual(0, rpc.GetManualProxies().Count());

            // Try adding more; count should not be affected
            rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType);
            rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType);
            rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType);
            rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType);
            Assert.AreEqual(1, rpc.Count());
            Assert.AreEqual(0, rpc.GetManualProxies().Count());

            // This is a second parent so should affect count
            rpc.EnlistParent(unsavedItemForAddingAsParent, FixedRelationTypes.DefaultRelationType);
            Assert.AreEqual(2, rpc.Count());
            Assert.AreEqual(1, rpc.GetManualProxies().Count());
        }
        public void AddingItemsManually_AsParent_CountIsCorrect()
        {
            // Arrange
            var disconnectedParent = HiveModelCreationHelper.MockTypedEntity();
            var disconnectedChild = HiveModelCreationHelper.MockTypedEntity();
            var rpc = new RelationProxyCollection(disconnectedChild);

            // Act
            rpc.EnlistParent(disconnectedParent, FixedRelationTypes.DefaultRelationType);
            
            // Assert
            Assert.AreEqual(1, rpc.Count());
            Assert.AreEqual(1, rpc.GetManualProxies().Count());
        }
Пример #3
0
        public void AddingItemsManually_AsParent_CountIsCorrect()
        {
            // Arrange
            var disconnectedParent = HiveModelCreationHelper.MockTypedEntity();
            var disconnectedChild  = HiveModelCreationHelper.MockTypedEntity();
            var rpc = new RelationProxyCollection(disconnectedChild);

            // Act
            rpc.EnlistParent(disconnectedParent, FixedRelationTypes.DefaultRelationType);

            // Assert
            Assert.AreEqual(1, rpc.Count());
            Assert.AreEqual(1, rpc.GetManualProxies().Count());
        }
        public void AddingItemsLazily_AsParent_CountIsCorrect()
        {
            // Arrange
            var connectedChild = HiveModelCreationHelper.MockTypedEntity();
            connectedChild.Id = HiveId.ConvertIntToGuid(2); // It's connected with a lazy-loader so it should have an Id
            var rpc = new RelationProxyCollection(connectedChild);

            // Act
            rpc.LazyLoadDelegate = ownerIdOfProxyColl =>
                                       {
                                           var parent = new RelationById(HiveId.ConvertIntToGuid(1), ownerIdOfProxyColl, FixedRelationTypes.DefaultRelationType, 0);
                                           return new RelationProxyBucket(new[] { parent }, Enumerable.Empty<RelationById>());
                                       };

            // Assert
            Assert.AreEqual(1, rpc.Count());
            Assert.AreEqual(0, rpc.GetManualProxies().Count());
        }
Пример #5
0
        public void AddingItemsLazily_AsParent_CountIsCorrect()
        {
            // Arrange
            var connectedChild = HiveModelCreationHelper.MockTypedEntity();

            connectedChild.Id = HiveId.ConvertIntToGuid(2); // It's connected with a lazy-loader so it should have an Id
            var rpc = new RelationProxyCollection(connectedChild);

            // Act
            rpc.LazyLoadDelegate = ownerIdOfProxyColl =>
            {
                var parent = new RelationById(HiveId.ConvertIntToGuid(1), ownerIdOfProxyColl, FixedRelationTypes.DefaultRelationType, 0);
                return(new RelationProxyBucket(new[] { parent }, Enumerable.Empty <RelationById>()));
            };

            // Assert
            Assert.AreEqual(1, rpc.Count());
            Assert.AreEqual(0, rpc.GetManualProxies().Count());
        }
        public void AddingItemsLazily_AndManually_AsParent_CountIsCorrect()
        {
            // Arrange
            var existingItemForParent = HiveModelCreationHelper.MockTypedEntity();
            var unsavedItemForAddingAsParent = HiveModelCreationHelper.MockTypedEntity();
            var connectedChild = HiveModelCreationHelper.MockTypedEntity();

            existingItemForParent.Id = HiveId.ConvertIntToGuid(1); // Assign Ids to mimic a lazy-loading valid scenario
            connectedChild.Id = HiveId.ConvertIntToGuid(2); // It's connected with a lazy-loader so it should have an Id

            var rpc = new RelationProxyCollection(connectedChild);

            // Act
            // This delegate mimics a lazy-loader, which returns RelationById to stipulate that 
            // the lazy loader must return existing items from the datastore
            rpc.LazyLoadDelegate = ownerIdOfCollection =>
            {
                var parent = new RelationById(HiveId.ConvertIntToGuid(1), ownerIdOfCollection, FixedRelationTypes.DefaultRelationType, 0);
                var parentShouldOverrideManuallyAdded = new RelationById(existingItemForParent.Id, ownerIdOfCollection, FixedRelationTypes.DefaultRelationType, 0);
                return new RelationProxyBucket(new[] { parent, parentShouldOverrideManuallyAdded }, Enumerable.Empty<RelationById>());
            };
            rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType);

            // Assert
            Assert.AreEqual(1, rpc.Count());
            Assert.AreEqual(0, rpc.GetManualProxies().Count());

            // Try adding more; count should not be affected
            rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType);
            rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType);
            rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType);
            rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType);
            Assert.AreEqual(1, rpc.Count());
            Assert.AreEqual(0, rpc.GetManualProxies().Count());

            // This is a second parent so should affect count
            rpc.EnlistParent(unsavedItemForAddingAsParent, FixedRelationTypes.DefaultRelationType);
            Assert.AreEqual(2, rpc.Count());
            Assert.AreEqual(1, rpc.GetManualProxies().Count());
        }