public void CanConvertImageCropperPropertyEditor(string val1, string val2, bool expected) { try { var container = RegisterFactory.Create(); var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); composition.WithCollectionBuilder <PropertyValueConverterCollectionBuilder>(); Current.Factory = composition.CreateFactory(); var logger = Mock.Of <ILogger>(); var scheme = Mock.Of <IMediaPathScheme>(); var config = Mock.Of <IContentSection>(); var mediaFileSystem = new MediaFileSystem(Mock.Of <IFileSystem>(), config, scheme, logger); var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new ImageCropperPropertyEditor(Mock.Of <ILogger>(), mediaFileSystem, Mock.Of <IContentSection>(), Mock.Of <IDataTypeService>())) { Id = 1 }); var factory = new PublishedContentTypeFactory(Mock.Of <IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty <IPropertyValueConverter>()), dataTypeService); var converter = new ImageCropperValueConverter(); var result = converter.ConvertSourceToIntermediate(null, factory.CreatePropertyType("test", 1), val1, false); // does not use type for conversion var resultShouldMatch = val2.DeserializeImageCropperValue(); if (expected) { Assert.AreEqual(resultShouldMatch, result); } else { Assert.AreNotEqual(resultShouldMatch, result); } } finally { Current.Reset(); } }
public List <PointPairList>[] GetCharacteristicOfTransformationFullComb() { List <PointPairList> res = new List <PointPairList>(); List <PointPairList> resSecondaryLines = new List <PointPairList>(); Register reg = RegisterFactory.Create(schvn); reg.SetPolinomNull(); PointPairList list = new PointPairList(); for (int i = 0; i < schvn.GetNumberOfCombinations() - 1; i++) { double znachenyaI = ZnachenyaI(reg); double znachenyaR = Convert(reg); list.Add(znachenyaI, znachenyaR); reg.IncPolinom(); double znachenyaI_next = ZnachenyaI(reg); double znachenyaR_next = Convert(reg); if (znachenyaI_next < znachenyaI) { res.Add(list); list = new PointPairList(); } } res.Add(list); PointPairList listOfSecondary = new PointPairList(); listOfSecondary.Add(0, 0); foreach (PointPairList member in res) { listOfSecondary.Add(member[0]); resSecondaryLines.Add(listOfSecondary); listOfSecondary = new PointPairList(); listOfSecondary.Add(member[member.Count - 1]); } return(new List <PointPairList>[] { res, resSecondaryLines }); }
public void PackageActionCollectionBuilderWorks() { var container = RegisterFactory.Create(); var composition = new Composition(container, new TypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); composition.WithCollectionBuilder <PackageActionCollectionBuilder>() .Add(() => TypeLoader.GetPackageActions()); Current.Factory = composition.CreateFactory(); var actions = Current.PackageActions; Assert.AreEqual(2, actions.Count()); // order is unspecified, but both must be there var hasAction1 = actions.ElementAt(0) is PackageAction1 || actions.ElementAt(1) is PackageAction1; var hasAction2 = actions.ElementAt(0) is PackageAction2 || actions.ElementAt(1) is PackageAction2; Assert.IsTrue(hasAction1); Assert.IsTrue(hasAction2); }
public virtual void Initialize() { Current.Reset(); var container = RegisterFactory.Create(); var ioHelper = IOHelper.Default; var logger = new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()); var typeFinder = new TypeFinder(Mock.Of <ILogger>()); var typeLoader = new TypeLoader(ioHelper, typeFinder, NoAppCache.Instance, new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), logger, false); var composition = new Composition(container, typeLoader, Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); composition.RegisterUnique <ILogger>(_ => Mock.Of <ILogger>()); composition.RegisterUnique <IProfiler>(_ => Mock.Of <IProfiler>()); composition.RegisterUnique(typeLoader); composition.WithCollectionBuilder <MapperCollectionBuilder>() .AddCoreMappers(); composition.RegisterUnique <ISqlContext>(_ => SqlContext); var factory = Current.Factory = composition.CreateFactory(); var pocoMappers = new NPoco.MapperCollection { new PocoMapper() }; var pocoDataFactory = new FluentPocoDataFactory((type, iPocoDataFactory) => new PocoDataBuilder(type, pocoMappers).Init()); var sqlSyntax = new SqlCeSyntaxProvider(); SqlContext = new SqlContext(sqlSyntax, DatabaseType.SQLCe, pocoDataFactory, new Lazy <IMapperCollection>(() => factory.GetInstance <IMapperCollection>())); Mappers = factory.GetInstance <IMapperCollection>(); SetUp(); }
public virtual void SetUp() { // should not need this if all other tests were clean // but hey, never know, better avoid garbage-in Reset(); // get/merge the attributes marking the method and/or the classes Options = TestOptionAttributeBase.GetTestOptions <UmbracoTestAttribute>(); // FIXME: align to runtimes & components - don't redo everything here var(logger, profiler) = GetLoggers(Options.Logger); var proflogger = new ProfilingLogger(logger, profiler); IOHelper = Umbraco.Core.IO.IOHelper.Default; TypeFinder = new TypeFinder(logger); var appCaches = GetAppCaches(); var globalSettings = SettingsForTests.GetDefaultGlobalSettings(); var typeLoader = GetTypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, globalSettings, proflogger, Options.TypeLoader); var register = RegisterFactory.Create(); Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run)); Composition.RegisterUnique(IOHelper); Composition.RegisterUnique(TypeFinder); Composition.RegisterUnique(typeLoader); Composition.RegisterUnique(logger); Composition.RegisterUnique(profiler); Composition.RegisterUnique <IProfilingLogger>(proflogger); Composition.RegisterUnique(appCaches); TestObjects = new TestObjects(register); Compose(); Current.Factory = Factory = Composition.CreateFactory(); Initialize(); }
public virtual void Initialize() { Current.Reset(); var sqlSyntax = new SqlCeSyntaxProvider(); var container = RegisterFactory.Create(); var logger = new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()); var typeLoader = new TypeLoader(NullCacheProvider.Instance, LocalTempStorage.Default, logger, false); var composition = new Composition(container, typeLoader, Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); composition.RegisterUnique <ILogger>(_ => Mock.Of <ILogger>()); composition.RegisterUnique <IProfiler>(_ => Mock.Of <IProfiler>()); composition.RegisterUnique(typeLoader); composition.WithCollectionBuilder <MapperCollectionBuilder>() .Add(() => composition.TypeLoader.GetAssignedMapperTypes()); var factory = Current.Factory = composition.CreateFactory(); Mappers = factory.GetInstance <IMapperCollection>(); var pocoMappers = new NPoco.MapperCollection { new PocoMapper() }; var pocoDataFactory = new FluentPocoDataFactory((type, iPocoDataFactory) => new PocoDataBuilder(type, pocoMappers).Init()); SqlContext = new SqlContext(sqlSyntax, DatabaseType.SQLCe, pocoDataFactory, Mappers); SetUp(); }
public void Setup() { // remove all handlers first DoThing1 = null; DoThing2 = null; DoThing3 = null; var register = RegisterFactory.Create(); var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); _testObjects = new TestObjects(register); composition.RegisterUnique(factory => new FileSystems(factory, factory.TryGetInstance <ILogger>())); composition.WithCollectionBuilder <MapperCollectionBuilder>(); composition.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); composition.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); Current.Reset(); Current.Factory = composition.CreateFactory(); SettingsForTests.Reset(); // ensure we have configuration }
// tests that a container conforms private IRegister GetRegister() => RegisterFactory.Create();
/// <summary> /// Gets the application register. /// </summary> protected virtual IRegister GetRegister() { return(RegisterFactory.Create()); }
public Converter(NotationSystem binaryNotSyst, NotationSystem schvnNotSyst) { bivaryDac = new DAC(binaryNotSyst); shcvnDac = new DAC(schvnNotSyst); regSchvn = RegisterFactory.Create(schvnNotSyst) as SCHVNRegister; }
private StatusRegister SetBit(bool flag, uint bit, RegisterFactory registerFactory) => new StatusRegister(registerFactory(Registers.Status, flag ? (Value | bit) : (Value & ~bit)));
public void Setup() { container = RegisterFactory.Create(); }
public void DoThisOnDevice(Device device) { device.DoSomeStuffOn(RegisterFactory.GetRegister(RegisterType.reg1), SomeCommonlyUsedStrategy); }
public void StandaloneTest() { IFactory factory = null; // clear foreach (var file in Directory.GetFiles(Path.Combine(IOHelper.MapPath("~/App_Data")), "NuCache.*")) { File.Delete(file); } // settings // reset the current version to 0.0.0, clear connection strings ConfigurationManager.AppSettings[Constants.AppSettings.ConfigurationStatus] = ""; // FIXME: we need a better management of settings here (and, true config files?) // create the very basic and essential things we need var logger = new ConsoleLogger(); var profiler = new LogProfiler(logger); var profilingLogger = new ProfilingLogger(logger, profiler); var appCaches = new AppCaches(); // FIXME: has HttpRuntime stuff? var databaseFactory = new UmbracoDatabaseFactory(logger, new Lazy <IMapperCollection>(() => factory.GetInstance <IMapperCollection>())); var typeLoader = new TypeLoader(appCaches.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger); var mainDom = new SimpleMainDom(); var runtimeState = new RuntimeState(logger, null, null, new Lazy <IMainDom>(() => mainDom), new Lazy <IServerRegistrar>(() => factory.GetInstance <IServerRegistrar>())); // create the register and the composition var register = RegisterFactory.Create(); var composition = new Composition(register, typeLoader, profilingLogger, runtimeState); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState); // create the core runtime and have it compose itself var coreRuntime = new CoreRuntime(); coreRuntime.Compose(composition); // determine actual runtime level runtimeState.DetermineRuntimeLevel(databaseFactory, logger); Console.WriteLine(runtimeState.Level); // going to be Install BUT we want to force components to be there (nucache etc) runtimeState.Level = RuntimeLevel.Run; var composerTypes = typeLoader.GetTypes <IComposer>() // all of them .Where(x => !x.FullName.StartsWith("Umbraco.Tests.")) // exclude test components .Where(x => x != typeof(WebInitialComposer) && x != typeof(WebFinalComposer)); // exclude web runtime var composers = new Composers(composition, composerTypes, Enumerable.Empty <Attribute>(), profilingLogger); composers.Compose(); // must registers stuff that WebRuntimeComponent would register otherwise // FIXME: UmbracoContext creates a snapshot that it does not register with the accessor // and so, we have to use the UmbracoContextPublishedSnapshotAccessor // the UmbracoContext does not know about the accessor // else that would be a catch-22 where they both know about each other? //composition.Register<IPublishedSnapshotAccessor, TestPublishedSnapshotAccessor>(Lifetime.Singleton); composition.Register <IPublishedSnapshotAccessor, UmbracoContextPublishedSnapshotAccessor>(Lifetime.Singleton); composition.Register <IUmbracoContextAccessor, TestUmbracoContextAccessor>(Lifetime.Singleton); composition.Register <IVariationContextAccessor, TestVariationContextAccessor>(Lifetime.Singleton); composition.Register <IDefaultCultureAccessor, TestDefaultCultureAccessor>(Lifetime.Singleton); composition.Register <ISiteDomainHelper>(_ => Mock.Of <ISiteDomainHelper>(), Lifetime.Singleton); composition.Register(_ => Mock.Of <IImageUrlGenerator>(), Lifetime.Singleton); composition.RegisterUnique(f => new DistributedCache()); composition.WithCollectionBuilder <UrlProviderCollectionBuilder>().Append <DefaultUrlProvider>(); composition.RegisterUnique <IDistributedCacheBinder, DistributedCacheBinder>(); composition.RegisterUnique <IExamineManager>(f => ExamineManager.Instance); composition.RegisterUnique <IUmbracoContextFactory, UmbracoContextFactory>(); composition.RegisterUnique <IMacroRenderer, MacroRenderer>(); composition.RegisterUnique <MediaUrlProviderCollection>(_ => new MediaUrlProviderCollection(Enumerable.Empty <IMediaUrlProvider>())); // initialize some components only/individually composition.WithCollectionBuilder <ComponentCollectionBuilder>() .Clear() .Append <DistributedCacheBinderComponent>(); // configure composition.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); composition.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); // create and register the factory Current.Factory = factory = composition.CreateFactory(); // instantiate and initialize components var components = factory.GetInstance <ComponentCollection>(); // do stuff Console.WriteLine(runtimeState.Level); // install if (true || runtimeState.Level == RuntimeLevel.Install) { var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var file = databaseFactory.Configured ? Path.Combine(path, "UmbracoNPocoTests.sdf") : Path.Combine(path, "Umbraco.sdf"); if (File.Exists(file)) { File.Delete(file); } // create the database file // databaseBuilder.ConfigureEmbeddedDatabaseConnection() can do it too, // but then it wants to write the connection string to web.config = bad var connectionString = databaseFactory.Configured ? databaseFactory.ConnectionString : "Data Source=|DataDirectory|\\Umbraco.sdf;Flush Interval=1;"; using (var engine = new SqlCeEngine(connectionString)) { engine.CreateDatabase(); } //var databaseBuilder = factory.GetInstance<DatabaseBuilder>(); //databaseFactory.Configure(DatabaseBuilder.EmbeddedDatabaseConnectionString, Constants.DbProviderNames.SqlCe); //databaseBuilder.CreateDatabaseSchemaAndData(); if (!databaseFactory.Configured) { databaseFactory.Configure(DatabaseBuilder.EmbeddedDatabaseConnectionString, Constants.DbProviderNames.SqlCe); } var scopeProvider = factory.GetInstance <IScopeProvider>(); using (var scope = scopeProvider.CreateScope()) { var creator = new DatabaseSchemaCreator(scope.Database, logger); creator.InitializeDatabaseSchema(); scope.Complete(); } } // done installing runtimeState.Level = RuntimeLevel.Run; components.Initialize(); // instantiate to register events // should be done by Initialize? // should we invoke Initialize? _ = factory.GetInstance <IPublishedSnapshotService>(); // at that point, Umbraco can run! // though, we probably still need to figure out what depends on HttpContext... var contentService = factory.GetInstance <IContentService>(); var content = contentService.GetById(1234); Assert.IsNull(content); // create a document type and a document var contentType = new ContentType(-1) { Alias = "ctype", Name = "ctype" }; factory.GetInstance <IContentTypeService>().Save(contentType); content = new Content("test", -1, contentType); contentService.Save(content); // assert that it is possible to get the document back content = contentService.GetById(content.Id); Assert.IsNotNull(content); Assert.AreEqual("test", content.Name); // need an UmbracoCOntext to access the cache // FIXME: not exactly pretty, should not depend on HttpContext var httpContext = Mock.Of <HttpContextBase>(); var umbracoContextFactory = factory.GetInstance <IUmbracoContextFactory>(); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(httpContext); var umbracoContext = umbracoContextReference.UmbracoContext; // assert that there is no published document var pcontent = umbracoContext.Content.GetById(content.Id); Assert.IsNull(pcontent); // but a draft document pcontent = umbracoContext.Content.GetById(true, content.Id); Assert.IsNotNull(pcontent); Assert.AreEqual("test", pcontent.Name()); Assert.IsTrue(pcontent.IsDraft()); // no published URL Assert.AreEqual("#", pcontent.Url()); // now publish the document + make some unpublished changes contentService.SaveAndPublish(content); content.Name = "testx"; contentService.Save(content); // assert that snapshot has been updated and there is now a published document pcontent = umbracoContext.Content.GetById(content.Id); Assert.IsNotNull(pcontent); Assert.AreEqual("test", pcontent.Name()); Assert.IsFalse(pcontent.IsDraft()); // but the URL is the published one - no draft URL Assert.AreEqual("/test/", pcontent.Url()); // and also an updated draft document pcontent = umbracoContext.Content.GetById(true, content.Id); Assert.IsNotNull(pcontent); Assert.AreEqual("testx", pcontent.Name()); Assert.IsTrue(pcontent.IsDraft()); // and the published document has a URL Assert.AreEqual("/test/", pcontent.Url()); umbracoContextReference.Dispose(); mainDom.Stop(); components.Terminate(); // exit! }
public SignUpController() { _factory = new RegisterFactory(); _BaseFactory = new BaseFactory(); _checkIpFactory = new CheckIpAddressFactory(); }
/// <summary>Creates new IRegister, which only differs in the interrupt flag, which is set to the given value.</summary> public StatusRegister SetInterrupt(bool flag, RegisterFactory registerFactory) => SetBit(flag, InterruptBit, registerFactory);
/// <summary>Creates new IRegister, which only differs in the signed flag, which is set to the given value.</summary> public StatusRegister SetSigned(bool flag, RegisterFactory registerFactory) => SetBit(flag, SignedBit, registerFactory);
public Alu(RegisterFactory registerFactory) { this.registerFactory = registerFactory; }
/// <summary>Creates new IRegister, which only differs in the zero flag, which is set to the given value.</summary> public StatusRegister SetZero(bool flag, RegisterFactory registerFactory) => SetBit(flag, ZeroBit, registerFactory);
/// <summary>Creates new IRegister, which only differs in the overflow flag, which is set to the given value.</summary> public StatusRegister SetOverflow(bool flag, RegisterFactory registerFactory) => SetBit(flag, OverflowBit, registerFactory);
public void ValidateComposition() { // this is almost what CoreRuntime does, without // - managing MainDom // - configuring for unhandled exceptions, assembly resolution, application root path // - testing for database, and for upgrades (runtime level) // - assigning the factory to Current.Factory // create the very basic and essential things we need var logger = new ConsoleLogger(); var profiler = Mock.Of <IProfiler>(); var profilingLogger = new ProfilingLogger(logger, profiler); var appCaches = AppCaches.Disabled; var databaseFactory = Mock.Of <IUmbracoDatabaseFactory>(); var typeLoader = new TypeLoader(appCaches.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger); var runtimeState = Mock.Of <IRuntimeState>(); Mock.Get(runtimeState).Setup(x => x.Level).Returns(RuntimeLevel.Run); var mainDom = Mock.Of <IMainDom>(); Mock.Get(mainDom).Setup(x => x.IsMainDom).Returns(true); // create the register and the composition var register = RegisterFactory.Create(); var composition = new Composition(register, typeLoader, profilingLogger, runtimeState); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState); // create the core runtime and have it compose itself var coreRuntime = new CoreRuntime(); coreRuntime.Compose(composition); // get the components // all of them? var composerTypes = typeLoader.GetTypes <IComposer>(); // filtered composerTypes = composerTypes .Where(x => !x.FullName.StartsWith("Umbraco.Tests")); // single? //var componentTypes = new[] { typeof(CoreRuntimeComponent) }; var composers = new Composers(composition, composerTypes, Enumerable.Empty <Attribute>(), profilingLogger); // get components to compose themselves composers.Compose(); // create the factory var factory = composition.CreateFactory(); // at that point Umbraco is fully composed // but nothing is initialized (no maindom, nothing - beware!) // to actually *run* Umbraco standalone, better use a StandaloneRuntime // that would inherit from CoreRuntime and ensure everything starts // get components to initialize themselves //components.Initialize(factory); // and then, validate var lightInjectContainer = (LightInject.ServiceContainer)factory.Concrete; var results = lightInjectContainer.Validate().ToList(); foreach (var resultGroup in results.GroupBy(x => x.Severity).OrderBy(x => x.Key)) { Console.WriteLine($"{resultGroup.Key}: {resultGroup.Count()}"); } foreach (var resultGroup in results.GroupBy(x => x.Severity).OrderBy(x => x.Key)) { foreach (var result in resultGroup) { Console.WriteLine(); Console.Write(ToText(result)); } } Assert.AreEqual(0, results.Count); }
public void Setup() { register = RegisterFactory.Create(); factory = null; }
private IRegister CreateRegister() { return(RegisterFactory.Create()); }
public void SimpleConverter3Test() { Current.Reset(); var register = RegisterFactory.Create(); var composition = new Composition(register, new TypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); composition.WithCollectionBuilder <PropertyValueConverterCollectionBuilder>() .Append <SimpleConverter3A>() .Append <SimpleConverter3B>(); IPublishedModelFactory factory = new PublishedModelFactory(new[] { typeof(PublishedSnapshotTestObjects.TestElementModel1), typeof(PublishedSnapshotTestObjects.TestElementModel2), typeof(PublishedSnapshotTestObjects.TestContentModel1), typeof(PublishedSnapshotTestObjects.TestContentModel2), }); register.Register(f => factory); Current.Factory = composition.CreateFactory(); var cacheMock = new Mock <IPublishedContentCache>(); var cacheContent = new Dictionary <int, IPublishedContent>(); cacheMock.Setup(x => x.GetById(It.IsAny <int>())).Returns <int>(id => cacheContent.TryGetValue(id, out IPublishedContent content) ? content : null); var publishedSnapshotMock = new Mock <IPublishedSnapshot>(); publishedSnapshotMock.Setup(x => x.Content).Returns(cacheMock.Object); var publishedSnapshotAccessorMock = new Mock <IPublishedSnapshotAccessor>(); publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot).Returns(publishedSnapshotMock.Object); register.Register(f => publishedSnapshotAccessorMock.Object); var converters = Current.Factory.GetInstance <PropertyValueConverterCollection>(); var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new VoidEditor(Mock.Of <ILogger>())) { Id = 1 }, new DataType(new VoidEditor("2", Mock.Of <ILogger>())) { Id = 2 }); var contentTypeFactory = new PublishedContentTypeFactory(factory, converters, dataTypeService); IEnumerable <IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType, int i) { yield return(contentTypeFactory.CreatePropertyType(contentType, "prop" + i, i)); } var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", t => CreatePropertyTypes(t, 1)); var elementType2 = contentTypeFactory.CreateContentType(1001, "element2", t => CreatePropertyTypes(t, 2)); var contentType1 = contentTypeFactory.CreateContentType(1002, "content1", t => CreatePropertyTypes(t, 1)); var contentType2 = contentTypeFactory.CreateContentType(1003, "content2", t => CreatePropertyTypes(t, 2)); var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> { { "prop1", "val1" } }, false); var element2 = new PublishedElement(elementType2, Guid.NewGuid(), new Dictionary <string, object> { { "prop2", "1003" } }, false); var cnt1 = new SolidPublishedContent(contentType1) { Id = 1003, Properties = new[] { new SolidPublishedProperty { Alias = "prop1", SolidHasValue = true, SolidValue = "val1" } } }; var cnt2 = new SolidPublishedContent(contentType1) { Id = 1004, Properties = new[] { new SolidPublishedProperty { Alias = "prop2", SolidHasValue = true, SolidValue = "1003" } } }; cacheContent[cnt1.Id] = cnt1.CreateModel(); cacheContent[cnt2.Id] = cnt2.CreateModel(); // can get the actual property Clr type // ie ModelType gets properly mapped by IPublishedContentModelFactory // must test ModelClrType with special equals 'cos they are not ref-equals Assert.IsTrue(ModelType.Equals(typeof(IEnumerable <>).MakeGenericType(ModelType.For("content1")), contentType2.GetPropertyType("prop2").ModelClrType)); Assert.AreEqual(typeof(IEnumerable <PublishedSnapshotTestObjects.TestContentModel1>), contentType2.GetPropertyType("prop2").ClrType); // can create a model for an element var model1 = factory.CreateModel(element1); Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestElementModel1>(model1); Assert.AreEqual("val1", ((PublishedSnapshotTestObjects.TestElementModel1)model1).Prop1); // can create a model for a published content var model2 = factory.CreateModel(element2); Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestElementModel2>(model2); var mmodel2 = (PublishedSnapshotTestObjects.TestElementModel2)model2; // and get direct property Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestContentModel1[]>(model2.Value("prop2")); Assert.AreEqual(1, ((PublishedSnapshotTestObjects.TestContentModel1[])model2.Value("prop2")).Length); // and get model property Assert.IsInstanceOf <IEnumerable <PublishedSnapshotTestObjects.TestContentModel1> >(mmodel2.Prop2); Assert.IsInstanceOf <PublishedSnapshotTestObjects.TestContentModel1[]>(mmodel2.Prop2); var mmodel1 = mmodel2.Prop2.First(); // and we get what we want Assert.AreSame(cacheContent[mmodel1.Id], mmodel1); }