public void HiveManagerExtension_GetsProviderMatch_FromCustomRoot(string customRoot) { // Arrange var context = new FakeFrameworkContext(); var metadata = new ProviderMetadata("test", new Uri("unimportant://"), true, false); var groups = new[] { new ProviderMappingGroup("default-content", new WildcardUriMatch("content://*"), new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), context), new ProviderMappingGroup("default-storage", new WildcardUriMatch("storage://*"), new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), context), new ProviderMappingGroup("default-assets", new WildcardUriMatch("assets://*"), new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), context) }; HiveManager manager = new HiveManager(groups, context); // Act var work = manager.GetProviderGroup(new Uri(customRoot)); // Assert Assert.NotNull(work); }
public XmlStoreHiveTests() { using (DisposableTimer.TraceDuration <XmlStoreHiveTests>("Start setup", "End setup")) { // Create reader var xmlPath = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Substring("file:\\\\".Length + 1)), "App_Data\\umbraco.config"); _fakeFrameworkContext = new FakeFrameworkContext(); _dataContextFactory = new DataContextFactory(xmlPath); _readOnlyUnitOfWorkFactory = new ReadOnlyUnitOfWorkFactory(); _directHiveReadProvider = new HiveReadProvider(new HiveProviderSetup(_fakeFrameworkContext, "r-unit-tester", new FakeHiveProviderBootstrapper(), _readOnlyUnitOfWorkFactory, null, _dataContextFactory)); // Create writer _readWriteUnitOfWorkFactory = new ReadWriteUnitOfWorkFactory(); _writeProvider = new HiveReadWriteProvider(new HiveProviderSetup(_fakeFrameworkContext, "rw-unit-tester", new FakeHiveProviderBootstrapper(), null, _readWriteUnitOfWorkFactory, _dataContextFactory)); // Create hive wrappers for the readers and writers var governorRUowFactory = new ReadOnlyUnitOfWorkFactoryWrapper(new[] { _directHiveReadProvider }); var governorRWUowFactory = new ReadWriteUnitOfWorkFactoryWrapper(new[] { _writeProvider }); _hiveReadProviderViaGovernor = new Framework.Hive.PersistenceGovernor.HiveReadProvider(new HiveProviderSetup(_fakeFrameworkContext, "r-unit-tester", new FakeHiveProviderBootstrapper(), governorRUowFactory, null, null), new[] { _directHiveReadProvider }); _hiveReadWriteProviderViaGovernor = new Framework.Hive.PersistenceGovernor.HiveReadWriteProvider(new HiveProviderSetup(_fakeFrameworkContext, "rw-unit-tester", new FakeHiveProviderBootstrapper(), null, governorRWUowFactory, null), new[] { _writeProvider }); } }
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"); } }
protected virtual void Init() { var attributeTypeRegistry = new CmsAttributeTypeRegistry(); AttributeTypeRegistry.SetCurrent(attributeTypeRegistry); FrameworkContext = new FakeFrameworkContext(); var hive = CreateHiveManager(); RebelApplicationContext = CreateApplicationContext(hive); var resolverContext = new MockedMapResolverContext(FrameworkContext, hive, new MockedPropertyEditorFactory(RebelApplicationContext), new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); FrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(FrameworkContext) })); DevDataset = DemoDataHelper.GetDemoData(RebelApplicationContext, attributeTypeRegistry); FixedPropertyEditors = new FixedPropertyEditors(RebelApplicationContext); //ensure model binders ModelBinders.Binders.Remove(typeof(HiveId)); ModelBinders.Binders.Add(typeof(HiveId), new HiveIdModelBinder()); ModelBinders.Binders.Remove(typeof(DocumentTypeEditorModel)); ModelBinders.Binders.Add(typeof(DocumentTypeEditorModel), new DocumentTypeModelBinder()); ModelBinders.Binders.Remove(typeof(SizeModelBinder)); ModelBinders.Binders.Add(typeof(SizeModelBinder), new SizeModelBinder()); //set the model meta data provider ModelMetadataProviders.Current = new RebelModelMetadataProvider(); }
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 CacheTestSetupHelper() { _cacheReference = new MemoryCache("unit-tester"); var metadata = new ProviderMetadata("cache", new Uri("cache://"), false, true); var frameworkContext = new FakeFrameworkContext(); var schemaRepositoryFactory = new SchemaRepositoryFactory( metadata, new NullProviderRevisionRepositoryFactory <EntitySchema>(metadata, frameworkContext), frameworkContext, new DependencyHelper(metadata, new CacheHelper(CacheReference))); var revisionRepositoryFactory = new EntityRevisionRepositoryFactory( metadata, frameworkContext, new DependencyHelper(metadata, new CacheHelper(CacheReference))); var entityRepositoryFactory = new EntityRepositoryFactory( metadata, revisionRepositoryFactory, schemaRepositoryFactory, frameworkContext, new DependencyHelper(metadata, new CacheHelper(CacheReference))); var unitFactory = new ProviderUnitFactory(entityRepositoryFactory); var readonlyUnitFactory = new ReadonlyProviderUnitFactory(entityRepositoryFactory); ProviderSetup = new ProviderSetup(unitFactory, metadata, frameworkContext, new NoopProviderBootstrapper(), 0); ReadonlyProviderSetup = new ReadonlyProviderSetup(readonlyUnitFactory, metadata, frameworkContext, new NoopProviderBootstrapper(), 0); }
public TypeMapperTests() { var frameworkContext = new FakeFrameworkContext(); _mappingEngine = new FakeMappingEngine(frameworkContext); frameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new[] { _mappingEngine })); }
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 HiveManager_OpensContentWriter_InferredFromRepositoryType() { // Arrange var context = new FakeFrameworkContext(); var metadata = new ProviderMetadata("test", new Uri("unimportant://"), true, false); var groups = new[] { new ProviderMappingGroup("default-content", new WildcardUriMatch("content://*"), new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), context), new ProviderMappingGroup("default-storage", new WildcardUriMatch("storage://*"), new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), context), new ProviderMappingGroup("default-assets", new WildcardUriMatch("assets://*"), new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0), context) }; HiveManager manager = new HiveManager(groups, context); // Act var writer = manager.OpenWriter <IContentStore>(); // Assert Assert.IsNotNull(writer); }
public void Setup() { var frameworkContext = new FakeFrameworkContext(); var frameworkModelMapper = new FrameworkModelMapper(frameworkContext); _mapper = new MembershipWrapperModelMapper(_attributeTypeRegistry, frameworkContext); frameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { frameworkModelMapper, _mapper })); }
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 Setup() { // Setup languages _languages = new List<LanguageElement> { new LanguageElement { IsoCode = "en-GB", Name = "English (United Kingdom)", Fallbacks = new FallbackCollection { new FallbackElement { IsoCode = "en-US" } } }, new LanguageElement { IsoCode = "en-US", Name = "English (United States)", Fallbacks = new FallbackCollection() } }; // Setup hive var context = new FakeFrameworkContext(); //_hiveManager = FakeHiveCmsManager.NewWithNhibernate(new[] { CreateFakeDictionaryMappingGroup(context) }, context); _hiveManager = new HiveManager(CreateFakeDictionaryMappingGroup(context), context); var root = new TypedEntity { Id = FixedHiveIds.DictionaryVirtualRoot, EntitySchema = FixedSchemas.DictionaryRootSchema, UtcCreated = DateTime.Now, UtcModified = DateTime.Now, UtcStatusChanged = DateTime.Now }; var item1 = CreateDictionatyItem("test1", new Dictionary<string, string> { { "en-GB", "Hello GB" }, { "en-US", "Hello US" } }); var item2 = CreateDictionatyItem("test2", new Dictionary<string, string> { { "en-GB", "World GB" }, { "en-US", "World US" } }); var item3 = CreateDictionatyItem("test3", new Dictionary<string, string> { { "en-GB", "Something GB" }, { "en-US", "Something US" } }); // Act var writer = _hiveManager.GetWriter<IDictionaryStore>(); using (var uow = writer.Create<IDictionaryStore>()) { // Add entities uow.Repositories.AddOrUpdate(root); uow.Repositories.Revisions.AddOrUpdate(item1); uow.Repositories.Revisions.AddOrUpdate(item2); uow.Repositories.Revisions.AddOrUpdate(item3); // Add all relations uow.Repositories.AddRelation(FixedHiveIds.DictionaryVirtualRoot, item1.Item.Id, FixedRelationTypes.DefaultRelationType, 0); uow.Repositories.AddRelation(FixedHiveIds.DictionaryVirtualRoot, item2.Item.Id, FixedRelationTypes.DefaultRelationType, 0); uow.Repositories.AddRelation(item2.Item.Id, item3.Item.Id, FixedRelationTypes.DefaultRelationType, 0); uow.Complete(); } }
public void Engine_Deals_With_Duplicate_Mappings() { var frameworkContext = new FakeFrameworkContext(); var engine = new FakeMappingEngine(frameworkContext); //create duplicate mappings...though only the first will be added and no exception thrown engine.CreateMap <FakeMappingEngine, FakeMappingEngine>(); Assert.Throws <InvalidOperationException>(() => engine.CreateMap <FakeMappingEngine, FakeMappingEngine>()); }
public override void TestSetUp() { var serializer = new ServiceStackSerialiser(); _frameworkContext = new FakeFrameworkContext(serializer); _configuration = new IndexConfiguration(GetPathForTest()); var controller = new IndexController(_configuration, _frameworkContext); CacheProvider = new CacheProvider(controller, false); }
private void RunTest( HiveManager hiveManager, FakeFrameworkContext frameworkContext, Action installCallback = null) { var attributeTypeRegistry = new CmsAttributeTypeRegistry(); AttributeTypeRegistry.SetCurrent(attributeTypeRegistry); var appContext = new FakeUmbracoApplicationContext(hiveManager, false); var mockedPropertyEditorFactory = new MockedPropertyEditorFactory(appContext); var resolverContext = new MockedMapResolverContext(frameworkContext, hiveManager, mockedPropertyEditorFactory, new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); frameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(frameworkContext) })); var devDataset = DemoDataHelper.GetDemoData(appContext, attributeTypeRegistry); //Seup permissions var permissions = new Permission[] { new SavePermission(), new PublishPermission(), new HostnamesPermission(), new CopyPermission(), new MovePermission() } .Select(x => new Lazy <Permission, PermissionMetadata>(() => x, new PermissionMetadata(new Dictionary <string, object> { { "Id", x.Id }, { "Name", x.Name }, { "Type", x.Type } }))).ToArray(); var coreDataInstallTask = new EnsureCoreDataTask(frameworkContext, hiveManager, permissions); var devDatasetInstallTask = new DevDatasetInstallTask(frameworkContext, mockedPropertyEditorFactory, hiveManager, attributeTypeRegistry); //Act coreDataInstallTask.InstallOrUpgrade(); if (installCallback != null) { installCallback(); } devDatasetInstallTask.InstallOrUpgrade(); if (installCallback != null) { installCallback(); } //Assert var totalSchemaCount = CoreCmsData.RequiredCoreSchemas().Count() + devDataset.DocTypes.Count() + 1; // +1 for SystemRoot schema var totalEntityCount = CoreCmsData.RequiredCoreUserGroups(permissions).Count() + CoreCmsData.RequiredCoreRootNodes().Count() + devDataset.ContentData.Count(); var totalAttributeTypeCount = CoreCmsData.RequiredCoreSystemAttributeTypes().Count() + CoreCmsData.RequiredCoreUserAttributeTypes().Count(); DoCoreAssertions(hiveManager, totalSchemaCount, totalEntityCount, totalAttributeTypeCount, 2, permissions); }
public void ProviderMappingGroup_IsMatchForUri(string assertUri, string[] wildcardMatches, bool shouldMatch) { // Arrange var matches = wildcardMatches.Select(x => new WildcardUriMatch(x)).ToList(); var context = new FakeFrameworkContext(); var metadata = new ProviderMetadata("test", new Uri("unimportant://"), true, false); var readonlySetup = new UninstalledReadonlyProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0); var setup = new UninstalledProviderSetup(metadata, context, new NoopProviderBootstrapper(), 0); var group = new ProviderMappingGroup("default", matches, Enumerable.Repeat(readonlySetup, 1), Enumerable.Repeat(setup, 1), new FakeFrameworkContext()); // Assert Assert.That(shouldMatch, Is.EqualTo(group.IsMatchForUri(new Uri(assertUri)).Success)); }
private ProviderMappingGroup CreateFakeDictionaryMappingGroup(FakeFrameworkContext frameworkContext) { var helper = new NhibernateTestSetupHelper(frameworkContext, useNhProf:true); var uriMatch = new WildcardUriMatch(new Uri("dictionary://")); var persistenceMappingGroup = new ProviderMappingGroup( "dictionary", uriMatch, helper.ReadonlyProviderSetup, helper.ProviderSetup, frameworkContext); return persistenceMappingGroup; }
public MembershipWrapperTestSetupHelper(FakeFrameworkContext frameworkContext = null) { //clear out the Roles/Users xml files for the test membership provider var current = new DirectoryInfo(Common.CurrentAssemblyDirectory); while (current.Parent.GetDirectories("App_Data").SingleOrDefault() == null) { current = current.Parent; } var appData = current.Parent.GetDirectories("App_Data").Single(); foreach (var f in appData.GetFiles("*.xml")) { f.Delete(); } foreach (var f in appData.GetFiles("*.orig")) { f.CopyTo(Path.Combine(f.Directory.FullName, Path.GetFileNameWithoutExtension(f.Name) + ".xml")); } _fakeFrameworkContext = frameworkContext ?? new FakeFrameworkContext(); var attributeTypeRegistry = new CmsAttributeTypeRegistry(); var mapper = new MembershipWrapperModelMapper(attributeTypeRegistry, _fakeFrameworkContext); _fakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { mapper, new FrameworkModelMapper(_fakeFrameworkContext) })); var providerMetadata = new ProviderMetadata("r-unit-tester", new Uri("tester://"), true, false); //need to reset our custom membership provider before each test var membershipProvider = global::System.Web.Security.Membership.Providers.Cast <MembershipProvider>().OfType <CustomXmlMembershipProvider>().Single(); membershipProvider.Reset(); var configuredProviders = new List <ProviderElement>(new[] { new ProviderElement() { Name = "test", WildcardCharacter = "*" } }); var revisionSchemaFactory = new NullProviderRevisionRepositoryFactory <EntitySchema>(providerMetadata, _fakeFrameworkContext); var revisionRepositoryFactory = new NullProviderRevisionRepositoryFactory <TypedEntity>(providerMetadata, _fakeFrameworkContext); var schemaRepositoryFactory = new NullProviderSchemaRepositoryFactory(providerMetadata, _fakeFrameworkContext); var entityRepositoryFactory = new EntityRepositoryFactory(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, _fakeFrameworkContext, new Lazy <IEnumerable <MembershipProvider> >(() => global::System.Web.Security.Membership.Providers.Cast <MembershipProvider>()), configuredProviders); var readUnitFactory = new ReadonlyProviderUnitFactory(entityRepositoryFactory); var unitFactory = new ProviderUnitFactory(entityRepositoryFactory); ProviderSetup = new ProviderSetup(unitFactory, providerMetadata, _fakeFrameworkContext, null, 0); ReadonlyProviderSetup = new ReadonlyProviderSetup(readUnitFactory, providerMetadata, _fakeFrameworkContext, null, 0); }
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"); } }
private HiveEntityUri ExecuteBinding(IValueProvider form, RouteData routeData, out ModelBindingContext bindingContext, out ControllerContext controllerContext) { var modelBinder = new HiveEntityUriModelBinder(); var httpContextFactory = new FakeHttpContextFactory("~/Umbraco/Editors/ContentEditor/Edit/1", routeData); var fakeFrameworkContext = new FakeFrameworkContext(); var hive = FakeHiveCmsManager.New(fakeFrameworkContext); var resolverContext = new MockedMapResolverContext(hive, new MockedPropertyEditorFactory(), new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); var cmsPersistenceModelMapper = new CmsPersistenceModelMapper(resolverContext); var cmsModelMapper = new CmsDomainMapper(resolverContext); fakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractTypeMapper[] { webmModelMapper, cmsModelMapper, cmsPersistenceModelMapper })); var umbracoApplicationContext = new FakeUmbracoApplicationContext(hive); controllerContext = new ControllerContext( httpContextFactory.RequestContext, new ContentEditorController(new FakeBackOfficeRequestContext(umbracoApplicationContext))); //put both the form and route values in the value provider var routeDataValueProvider = new RouteDataValueProvider(controllerContext); var values = new ValueProviderCollection(new List <IValueProvider>() { form, routeDataValueProvider }); bindingContext = GetBindingContext(new HiveEntityUri(1), values); //do the binding! var model = modelBinder.BindModel(controllerContext, bindingContext); //assert! Assert.IsInstanceOfType(model, typeof(HiveEntityUri), "Model isn't a HiveEntityUri"); var boundModel = (HiveEntityUri)model; return(boundModel); }
private HiveId ExecuteBinding(IValueProvider form, RouteData routeData, out ModelBindingContext bindingContext, out ControllerContext controllerContext) { var modelBinder = new HiveIdModelBinder(); var httpContextFactory = new FakeHttpContextFactory("~/Rebel/Editors/ContentEditor/Edit/1", routeData); var fakeFrameworkContext = new FakeFrameworkContext(); var hive = FakeHiveCmsManager.New(fakeFrameworkContext); var appContext = new FakeRebelApplicationContext(hive); var resolverContext = new MockedMapResolverContext(fakeFrameworkContext, hive, new MockedPropertyEditorFactory(appContext), new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); fakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(fakeFrameworkContext) })); var rebelApplicationContext = new FakeRebelApplicationContext(hive); controllerContext = new ControllerContext( httpContextFactory.RequestContext, new ContentEditorController(new FakeBackOfficeRequestContext(rebelApplicationContext))); //put both the form and route values in the value provider var routeDataValueProvider = new RouteDataValueProvider(controllerContext); var values = new ValueProviderCollection(new List <IValueProvider>() { form, routeDataValueProvider }); bindingContext = GetBindingContext(new HiveId(1), values); //do the binding! var model = modelBinder.BindModel(controllerContext, bindingContext); //assert! Assert.That(model, Is.InstanceOf <HiveId>(), "Model isn't a HiveId"); var boundModel = (HiveId)model; return(boundModel); }
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); } }
public CachingProviderTests() { _fakeFrameworkContext = new FakeFrameworkContext(); var inMemory = new NHibernateInMemoryRepository(_fakeFrameworkContext); var dataContextFactory = new DataContextFactory(); var readWriteUnitOfWorkFactory = new ReadWriteUnitOfWorkFactory(); var directReaderProvider = new HiveReadWriteProvider(new HiveProviderSetup(_fakeFrameworkContext, "r-unit-tester", new FakeHiveProviderBootstrapper(), readWriteUnitOfWorkFactory, readWriteUnitOfWorkFactory, dataContextFactory)); var directReadWriteProvider = directReaderProvider; // Create hive wrappers for the readers and writers var governorRUowFactory = new ReadOnlyUnitOfWorkFactoryWrapper(new[] { directReaderProvider, inMemory.HiveReadProvider }); var governorRWUowFactory = new ReadWriteUnitOfWorkFactoryWrapper(new[] { directReadWriteProvider, inMemory.ReadWriteProvider }); _readerProviderViaHiveGovernor = _directReaderProvider = new Framework.Hive.PersistenceGovernor.HiveReadProvider(new HiveProviderSetup(_fakeFrameworkContext, "r-unit-wrapper", new FakeHiveProviderBootstrapper(), governorRUowFactory, null, null), new[] { _directReaderProvider }); _readWriteProviderViaHiveGovernor = _directReadWriteProvider = new Framework.Hive.PersistenceGovernor.HiveReadWriteProvider(new HiveProviderSetup(_fakeFrameworkContext, "rw-unit-wrapper", new FakeHiveProviderBootstrapper(), governorRUowFactory, governorRWUowFactory, null), new[] { _directReadWriteProvider }); }
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); } } }
private static HiveReadWriteProvider CreateReadWritter() { var builder = new NHibernateConfigBuilder("data source=:memory:", "unit-tester", SupportedNHDrivers.SqlLite, "thread_static", false); var config = builder.BuildConfiguration(); var sessionFactory = config.BuildSessionFactory(); _sessionForTest = sessionFactory.OpenSession(); var schemaWriter = new StringWriter(new StringBuilder()); new SchemaExport(config).Execute(false, true, false, _sessionForTest.Connection, schemaWriter); var fakeFrameworkContext = new FakeFrameworkContext(); var dataContextFactory = new DataContextFactory(fakeFrameworkContext, _sessionForTest, true); var readWriteRepositoryUnitOfWorkFactory = new ReadWriteUnitOfWorkFactory(); var writer = new HiveReadWriteProvider(new HiveProviderSetup(fakeFrameworkContext, "r-unit-tester", new FakeHiveProviderBootstrapper(), null, readWriteRepositoryUnitOfWorkFactory, dataContextFactory)); fakeFrameworkContext.TypeMappers.Add( new Lazy <AbstractTypeMapper, TypeMapperMetadata>( () => new ManualMapper(new NhLookupHelper(dataContextFactory), writer), new TypeMapperMetadata(true))); return(writer); }
private void RunTest( HiveManager hiveManager, FakeFrameworkContext frameworkContext, Action installCallback = null) { var attributeTypeRegistry = new CmsAttributeTypeRegistry(); AttributeTypeRegistry.SetCurrent(attributeTypeRegistry); var appContext = new FakeRebelApplicationContext(hiveManager, false); var mockedPropertyEditorFactory = new MockedPropertyEditorFactory(appContext); var resolverContext = new MockedMapResolverContext(frameworkContext, hiveManager, mockedPropertyEditorFactory, new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); frameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(frameworkContext) })); var devDataset = DemoDataHelper.GetDemoData(appContext, attributeTypeRegistry); //Setup permissions var permissions = new Permission[] { new SavePermission(), new PublishPermission(), new HostnamesPermission(), new CopyPermission(), new MovePermission() } .Select(x => new Lazy <Permission, PermissionMetadata>(() => x, new PermissionMetadata(new Dictionary <string, object> { { "Id", x.Id }, { "Name", x.Name }, { "Type", x.Type }, { "UserType", x.UserType } }))).ToArray(); //Setup security service var usersMembershipProvider = new UsersMembershipProvider { AppContext = appContext }; usersMembershipProvider.Initialize("UsersMembershipProvider", new NameValueCollection()); var usersMembershipService = new MembershipService <User, UserProfile>(frameworkContext, hiveManager, "security://user-profiles", "security://user-groups", Framework.Security.Model.FixedHiveIds.UserProfileVirtualRoot, usersMembershipProvider, Enumerable.Empty <MembershipProviderElement>()); ResetMembershipProvider(usersMembershipService.MembershipProvider); var membersMembershipProvider = new MembersMembershipProvider { AppContext = appContext }; membersMembershipProvider.Initialize("MembersMembershipProvider", new NameValueCollection()); var membersMembershipService = new MembershipService <Member, MemberProfile>(frameworkContext, hiveManager, "security://member-profiles", "security://member-groups", Framework.Security.Model.FixedHiveIds.MemberProfileVirtualRoot, membersMembershipProvider, Enumerable.Empty <MembershipProviderElement>()); ResetMembershipProvider(membersMembershipService.MembershipProvider); var permissionService = new PermissionsService(hiveManager, permissions, usersMembershipService); var publicAccessService = new PublicAccessService(hiveManager, membersMembershipService, appContext.FrameworkContext); var securityService = new SecurityService(usersMembershipService, membersMembershipService, permissionService, publicAccessService); var coreDataInstallTask = new EnsureCoreDataTask(frameworkContext, hiveManager, permissions, securityService); //var devDatasetInstallTask = new DevDatasetInstallTask(frameworkContext, mockedPropertyEditorFactory, hiveManager, attributeTypeRegistry); //Act coreDataInstallTask.InstallOrUpgrade(); if (installCallback != null) { installCallback(); } //devDatasetInstallTask.InstallOrUpgrade(); //if (installCallback != null) installCallback(); //Assert var totalSchemaCount = CoreCmsData.RequiredCoreSchemas().Count() + devDataset.DocTypes.Count() + 1; // +1 for SystemRoot schema var totalEntityCount = CoreCmsData.RequiredCoreUserGroups(permissions).Count() + CoreCmsData.RequiredCoreRootNodes().Count() + devDataset.ContentData.Count(); var totalAttributeTypeCount = CoreCmsData.RequiredCoreSystemAttributeTypes().Count() + CoreCmsData.RequiredCoreUserAttributeTypes().Count(); DoCoreAssertions(hiveManager, totalSchemaCount, totalEntityCount, totalAttributeTypeCount, 2, permissions, securityService); //CoreCmsData.RequiredCoreUsers().ForEach( // x => // { // securityService.UsersMembershipService.DeleteUser(x.Username, true); // securityService.MembersMembershipService.DeleteUser(x.Username, true); // }); ResetMembershipProvider(securityService.Users.MembershipProvider); ResetMembershipProvider(securityService.Members.MembershipProvider); }
public NHibernateHiveTests() { _fakeFrameworkContext = new FakeFrameworkContext(); _repository = new NHibernateInMemoryRepository(_fakeFrameworkContext); }