Beispiel #1
0
        public void Setup()
        {
            _register = RegisterFactory.Create();

            var composition = new Composition(_register, new TypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run));

            composition.Register(_ => Mock.Of <ILogger>());
            composition.Register(_ => Mock.Of <IDataTypeService>());
            composition.Register(_ => Mock.Of <IContentSection>());
            composition.RegisterUnique <IMediaPathScheme, UniqueMediaPathScheme>();

            composition.Configs.Add(SettingsForTests.GetDefaultGlobalSettings);
            composition.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings);

            composition.ComposeFileSystems();

            composition.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings);

            _factory = composition.CreateFactory();

            Current.Reset();
            Current.Factory = _factory;

            // make sure we start clean
            // because some tests will create corrupt or weird filesystems
            FileSystems.Reset();
        }
        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);
            var cacheHelper    = GetCacheHelper();
            var globalSettings = SettingsForTests.GetDefaultGlobalSettings();
            var typeLoader     = GetTypeLoader(cacheHelper.RuntimeCache, globalSettings, proflogger, Options.TypeLoader);

            var register = RegisterFactory.Create();

            Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run));

            Composition.RegisterUnique(typeLoader);
            Composition.RegisterUnique(logger);
            Composition.RegisterUnique(profiler);
            Composition.RegisterUnique <IProfilingLogger>(proflogger);
            Composition.RegisterUnique(cacheHelper);
            Composition.RegisterUnique(cacheHelper.RuntimeCache);

            TestObjects = new TestObjects(register);
            Compose();
            Current.Factory = Factory = Composition.CreateFactory();
            Initialize();
        }
Beispiel #3
0
        public PointPairList GetCharacteristicOfTransformationStraitComb()
        {
            Register reg = RegisterFactory.Create(schvn);

            reg.SetPolinomNull();
            PointPairList res = new PointPairList();

            for (int i = 0; i < reg.Diapason; i++)
            {
                double znachenya;

                if (isCalibrated)
                {
                    reg.AddOneCalibrated();
                }
                else
                {
                    reg.AddOne();
                }
                znachenya = Convert(reg);

                res.Add(i, znachenya);
            }
            return(res);
        }
        public void Setup()
        {
            Current.Reset();

            var register = RegisterFactory.Create();

            _composition = new Composition(register, new TypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run));
        }
Beispiel #5
0
        public ADC(NotationSystem schvn)
        {
            dac = new DAC(schvn);
            reg = RegisterFactory.Create(schvn);
            isTrackingCalibrated  = false;
            isCletchingCalibrated = false;

            RAM.Weights.InitRAMWeights(schvn);
        }
        public void CanConvertImageCropperPropertyEditor(string val1, string val2, bool expected)
        {
            try
            {
                var container   = RegisterFactory.Create();
                var composition = new Composition(container, new TypeLoader(), 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 imageCropperConfiguration = new ImageCropperConfiguration()
                {
                    Crops = new[]
                    {
                        new ImageCropperConfiguration.Crop()
                        {
                            Alias  = "thumb",
                            Width  = 100,
                            Height = 100
                        }
                    }
                };
                var dataTypeService = new TestObjects.TestDataTypeService(
                    new DataType(new ImageCropperPropertyEditor(Mock.Of <ILogger>(), mediaFileSystem, Mock.Of <IContentSection>(), Mock.Of <IDataTypeService>()))
                {
                    Id = 1, Configuration = imageCropperConfiguration
                });

                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();
            }
        }
Beispiel #7
0
        public ConsoleHost(TextReader reader, TextWriter writer)
        {
            this.reader = reader;
            this.writer = writer;

            this.runtime = new ConsoleRuntime(reader, writer);

            var register = RegisterFactory.Create();

            factory = runtime.Boot(register);
        }
Beispiel #8
0
        public virtual void TestSetup()
        {
            //normalize culture
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

            var register    = RegisterFactory.Create();
            var composition = new Composition(register, new TypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run));

            register.Register <IShortStringHelper>(_
                                                   => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())));

            Current.Factory = composition.CreateFactory();
        }
Beispiel #9
0
        public void Setup()
        {
            var register = RegisterFactory.Create();

            var composition = new Composition(register, new TypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run));

            composition.RegisterUnique <IServerRegistrar>(_ => new TestServerRegistrar());
            composition.RegisterUnique <IServerMessenger>(_ => new TestServerMessenger());

            composition.WithCollectionBuilder <CacheRefresherCollectionBuilder>()
            .Add <TestCacheRefresher>();

            Current.Factory = composition.CreateFactory();

            _distributedCache = new Umbraco.Web.Cache.DistributedCache();
        }
Beispiel #10
0
        public SCHVNRegister Convert(BinaryRegister regBinary)
        {
            SCHVNRegister regSchvn = RegisterFactory.Create(schvnNotSyst);

            double signal = bivaryDac.ZnachenyaI(regBinary);

            for (int ik1 = shcvnDac.schvn.n - 1; ik1 >= 0; ik1--)
            {
                if (shcvnDac.ZnachenyaC(regSchvn.AddBitValue(ik1, 1)) <= signal)
                {
                }
                else
                {
                    shcvnDac.AddBitValue(ik1, 0);
                }
            }
            return(regSchvn);
        }
Beispiel #11
0
        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 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 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);
        }
Beispiel #14
0
        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();
        }
Beispiel #15
0
        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
        }
Beispiel #16
0
 public void Setup()
 {
     container = RegisterFactory.Create();
 }
Beispiel #17
0
 private IRegister CreateRegister()
 {
     return(RegisterFactory.Create());
 }
Beispiel #18
0
        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!
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
 /// <summary>
 /// Gets the application register.
 /// </summary>
 protected virtual IRegister GetRegister()
 {
     return(RegisterFactory.Create());
 }
Beispiel #21
0
        // tests that a container conforms

        private IRegister GetRegister() => RegisterFactory.Create();
 public Converter(NotationSystem binaryNotSyst, NotationSystem schvnNotSyst)
 {
     bivaryDac = new DAC(binaryNotSyst);
     shcvnDac  = new DAC(schvnNotSyst);
     regSchvn  = RegisterFactory.Create(schvnNotSyst) as SCHVNRegister;
 }
Beispiel #23
0
        public ActionResult Index(RegisterModels model)
        {
            try
            {
                string msg        = "";
                byte[] photoByte1 = null;
                byte[] photoByte2 = null;

                //Customer Image
                if (!string.IsNullOrEmpty(model.CustomerDetail.ImageURL))
                {
                    model.CustomerDetail.ImageURL = model.CustomerDetail.ImageURL.Replace(CommonHelper.PublicImages, "").Replace(Commons.Image200_200, "");
                }
                if (model.CustomerDetail.PictureUpload != null && model.CustomerDetail.PictureUpload.ContentLength > 0)
                {
                    Byte[] imgByte1 = new Byte[model.CustomerDetail.PictureUpload.ContentLength];
                    model.CustomerDetail.PictureUpload.InputStream.Read(imgByte1, 0, model.CustomerDetail.PictureUpload.ContentLength);
                    model.CustomerDetail.PictureByte   = imgByte1;
                    model.CustomerDetail.ImageURL      = Guid.NewGuid() + Path.GetExtension(model.CustomerDetail.PictureUpload.FileName);
                    model.CustomerDetail.PictureUpload = null;
                    photoByte1 = imgByte1;
                }
                //Merchant Image
                if (!string.IsNullOrEmpty(model.MerchantDetail.ImageURL))
                {
                    model.MerchantDetail.ImageURL = model.MerchantDetail.ImageURL.Replace(CommonHelper.PublicImages, "").Replace(Commons.Image200_200, "");
                }
                if (model.MerchantDetail.PictureUpload != null && model.MerchantDetail.PictureUpload.ContentLength > 0)
                {
                    Byte[] imgByte2 = new Byte[model.MerchantDetail.PictureUpload.ContentLength];
                    model.MerchantDetail.PictureUpload.InputStream.Read(imgByte2, 0, model.MerchantDetail.PictureUpload.ContentLength);
                    model.MerchantDetail.PictureByte   = imgByte2;
                    model.MerchantDetail.ImageURL      = Guid.NewGuid() + Path.GetExtension(model.MerchantDetail.PictureUpload.FileName);
                    model.MerchantDetail.PictureUpload = null;
                    photoByte2 = imgByte2;
                }
                bool result = _factory.Create(model, ref msg);
                if (result)
                {
                    if (!string.IsNullOrEmpty(model.CustomerDetail.ImageURL) && photoByte1 != null)
                    {
                        var          originalDirectory = new DirectoryInfo(string.Format("{0}Uploads\\", Server.MapPath(@"\")));
                        var          path = string.Format("{0}{1}", originalDirectory, model.CustomerDetail.ImageURL);
                        MemoryStream ms   = new MemoryStream(photoByte1, 0, photoByte1.Length);
                        ms.Write(photoByte1, 0, photoByte1.Length);
                        System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true);

                        ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.CustomerDetail.ImageURL, ref photoByte1);

                        FTP.UploadClient(model.CustomerDetail.ImageURL, photoByte1);

                        ImageHelper.Me.TryDeleteImageUpdated(path);
                    }
                    if (!string.IsNullOrEmpty(model.MerchantDetail.ImageURL) && photoByte2 != null)
                    {
                        var          originalDirectory = new DirectoryInfo(string.Format("{0}Uploads\\", Server.MapPath(@"\")));
                        var          path = string.Format("{0}{1}", originalDirectory, model.MerchantDetail.ImageURL);
                        MemoryStream ms   = new MemoryStream(photoByte2, 0, photoByte2.Length);
                        ms.Write(photoByte2, 0, photoByte2.Length);
                        System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true);

                        ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.MerchantDetail.ImageURL, ref photoByte2);

                        FTP.UploadClient(model.MerchantDetail.ImageURL, photoByte2);

                        ImageHelper.Me.TryDeleteImageUpdated(path);
                    }
                    VerificationModels models = new VerificationModels();
                    models.ReSendEmail = model.CustomerDetail.Email;
                    return(new HttpStatusCodeResult(HttpStatusCode.OK));
                }
                else
                {
                    //ModelState.AddModelError("CustomerDetail.Email", msg);
                    model.CustomerDetail.ImageURL = "";
                    model.MerchantDetail.ImageURL = "";
                    Response.StatusCode           = (int)HttpStatusCode.BadRequest;
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("RegisterCreate: ", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
Beispiel #24
0
 public void Setup()
 {
     register = RegisterFactory.Create();
     factory  = null;
 }
Beispiel #25
0
        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);
        }