Exemple #1
0
        public void WhenGetIsCalled_WithMultipleIds_MultipleItemsAreReturned(
            int allItemCount,
            int numbProviderCount,
            int numberOfPassthroughProviders)
        {
            // Arrange
            var    context          = new FakeFrameworkContext();
            var    providerGroup    = GroupedProviderMockHelper.GenerateProviderGroup(numbProviderCount, numberOfPassthroughProviders, allItemCount, context);
            var    idRoot           = new Uri("oh-yeah://this-is-my-root/");
            var    groupUnitFactory = new GroupUnitFactory(providerGroup.Writers, idRoot, FakeHiveCmsManager.CreateFakeRepositoryContext(context), context);
            HiveId int1             = HiveId.ConvertIntToGuid(1);
            HiveId int2             = HiveId.ConvertIntToGuid(2);
            HiveId int3             = HiveId.ConvertIntToGuid(3);


            // Act & Assert
            using (var uow = groupUnitFactory.Create <IContentStore>())
            {
                Assert.NotNull(uow.IdRoot);
                Assert.AreEqual(uow.IdRoot, idRoot);

                // TODO: This looks like a poor test since Get with multiple ids is actually just mocked to return three
                // but the purpose of this test is to establish that when running with multiple providers, some of which
                // are passthrough, only the correct number of items should be returned
                var items = uow.Repositories.Get <TypedEntity>(true, int1, int2, int3);
                Assert.That(items.Count(), Is.EqualTo(3 * numbProviderCount), "item count wrong");

                // Assert that the correct number of relations are returned too including passthrough providers being filtered for
                var parents = uow.Repositories.GetParentRelations(HiveId.Empty);
                Assert.That(parents.Count(), Is.EqualTo(GroupedProviderMockHelper.MockRelationCount * numbProviderCount), "parents count wrong");
            }
        }
Exemple #2
0
        public void WhenTypedEntity_IsReturnedFromGroupEntityRepository_ItsRelationProxies_HaveAbsoluteId()
        {
            // Arrange
            var context          = new FakeFrameworkContext();
            var providerGroup    = GroupedProviderMockHelper.GenerateProviderGroup(1, 0, 50, context);
            var idRoot           = new Uri("myroot://yeah/");
            var groupUnitFactory = new GroupUnitFactory(providerGroup.Writers, idRoot, FakeHiveCmsManager.CreateFakeRepositoryContext(context), context);

            // Act & Assert
            using (var uow = groupUnitFactory.Create())
            {
                Assert.NotNull(uow.IdRoot);
                Assert.AreEqual(uow.IdRoot, idRoot);

                var item = uow.Repositories.Get <TypedEntity>(HiveId.Empty);
                AssertIdsOfRelationProxiesForEntity(item, idRoot);

                var items = uow.Repositories.GetAll <TypedEntity>();
                Assert.True(items.Any());
                foreach (var typedEntity in items)
                {
                    AssertIdsOfRelationProxiesForEntity(typedEntity, idRoot);
                }
            }
        }
        public void WhenSourceIsAccessed_LazyRelation_CallsRepository_WithBothSourceAndDestinationId()
        {
            // Arrange
            var    context          = new FakeFrameworkContext();
            var    providerGroup    = GroupedProviderMockHelper.GenerateProviderGroup(1, 0, 50, context);
            var    idRoot           = new Uri("oh-yeah://this-is-my-root/");
            var    groupUnitFactory = new GroupUnitFactory(providerGroup.Writers, idRoot, FakeHiveCmsManager.CreateFakeRepositoryContext(context), context);
            HiveId int1             = HiveId.ConvertIntToGuid(1);
            HiveId int2             = HiveId.ConvertIntToGuid(2);

            // Act & Assert
            using (var uow = groupUnitFactory.Create())
            {
                var lazyRelation = new LazyRelation <TypedEntity>(uow.Repositories, FixedRelationTypes.DefaultRelationType, int1, int2, 0);

                IReadonlyRelation <IRelatableEntity, IRelatableEntity> blah = lazyRelation;
                IRelationById blah2 = lazyRelation;

                Assert.False(lazyRelation.IsLoaded);
                var source = lazyRelation.Source;
                Assert.True(lazyRelation.IsLoaded);
                var dest = lazyRelation.Destination;

                Assert.NotNull(source);
                Assert.NotNull(dest);
            }
        }
        public void Setup()
        {
            _frameworkContext = new FakeFrameworkContext();
            _unitScopedCache  = new DictionaryScopedCache();
            var providerGroup = GroupedProviderMockHelper.GenerateProviderGroup(1, 0, 1, _frameworkContext);
            var idRoot        = new Uri("oh-yeah://this-is-my-root/");

            _groupUnitFactory = new GroupUnitFactory(providerGroup.Writers, idRoot, FakeHiveCmsManager.CreateFakeRepositoryContext(_frameworkContext), _frameworkContext, () => _unitScopedCache);
        }
        public void MultipleTransactionCommits_ThrowsError()
        {
            // Arrange
            var context  = new FakeFrameworkContext();
            var provider = GroupedProviderMockHelper.MockEntityRepositoryFactory(1, new ProviderMetadata("test", new Uri("test://"), true, false), context);
            var factory  = new ProviderUnitFactory(provider);

            // Act
            using (var uow = factory.Create())
            {
                uow.Complete();
                Assert.Throws <TransactionCompletedException>(uow.Complete, "Second completion did not throw exception");
            }
        }
Exemple #6
0
        public void WhenProviderIsMatched_IdIsRemappedToMappingGroup_OnReturn(
            int allItemCount,
            int numbProviderCount,
            int numberOfPassthroughProviders)
        {
            // Arrange
            var context          = new FakeFrameworkContext();
            var providerGroup    = GroupedProviderMockHelper.GenerateProviderGroup(numbProviderCount, numberOfPassthroughProviders, allItemCount, context);
            var idRoot           = new Uri("oh-yeah://this-is-my-root/");
            var groupUnitFactory = new GroupUnitFactory(providerGroup.Writers, idRoot, FakeHiveCmsManager.CreateFakeRepositoryContext(context), context);



            // Act & Assert
            using (var uow = groupUnitFactory.Create <IContentStore>())
            {
                Assert.NotNull(uow.IdRoot);
                Assert.AreEqual(uow.IdRoot, idRoot);

                var singleItem = uow.Repositories.Get <TypedEntity>(HiveId.Empty);
                Assert.NotNull(singleItem);
                Assert.NotNull(singleItem.Id.ProviderGroupRoot);
                Assert.AreEqual(singleItem.Id.ProviderGroupRoot, idRoot);
                Assert.NotNull(singleItem.Id.ProviderId);
                Assert.True(singleItem.Id.ToString(HiveIdFormatStyle.AsUri).StartsWith(idRoot.ToString()), "Was: " + singleItem.Id.ToFriendlyString());

                var items             = uow.Repositories.GetAll <TypedEntity>();
                var itemShouldBeCount = allItemCount * numbProviderCount;
                Assert.AreEqual(itemShouldBeCount, items.Count());
                foreach (var typedEntity in items)
                {
                    AssertEntityIdIsRooted(idRoot, ((IReferenceByHiveId)typedEntity).Id);
                }

                AssertRelationsIdsHaveRoot(uow.Repositories.GetParentRelations(HiveId.Empty), idRoot);
                AssertRelationsIdsHaveRoot(uow.Repositories.GetDescendentRelations(HiveId.Empty), idRoot);
                AssertRelationsIdsHaveRoot(uow.Repositories.GetChildRelations(HiveId.Empty), idRoot);
                AssertRelationsIdsHaveRoot(uow.Repositories.GetAncestorRelations(HiveId.Empty), idRoot);
            }
        }
Exemple #7
0
        public void WhenTypedEntity_IsReturnedFromGroupEntityRepository_AllObjects_HaveProviderId()
        {
            // Arrange
            var context          = new FakeFrameworkContext();
            var providerGroup    = GroupedProviderMockHelper.GenerateProviderGroup(1, 0, 50, context);
            var idRoot           = new Uri("myroot://yeah/");
            var groupUnitFactory = new GroupUnitFactory(providerGroup.Writers, idRoot, FakeHiveCmsManager.CreateFakeRepositoryContext(context), context);

            // Act & Assert
            using (var uow = groupUnitFactory.Create())
            {
                Assert.NotNull(uow.IdRoot);
                Assert.AreEqual(uow.IdRoot, idRoot);

                var singleItem        = uow.Repositories.Get <TypedEntity>(HiveId.Empty);
                var allDependentItems = singleItem.GetAllIdentifiableItems().ToArray();
                Assert.IsTrue(allDependentItems.Any());
                Assert.That(allDependentItems.Select(x => x.Id).Distinct().Count(), Is.GreaterThan(1));
                foreach (var referenceByHiveId in allDependentItems)
                {
                    AssertEntityIdIsRooted(idRoot, referenceByHiveId.Id);
                }
            }
        }