public void U4_4055_4056()
        {
            var settings    = SettingsForTests.GenerateMockSettings();
            var contentMock = Mock.Get(settings.RequestHandler);

            contentMock.Setup(x => x.CharCollection).Returns(Enumerable.Empty <IChar>());
            contentMock.Setup(x => x.ConvertUrlsToAscii).Returns(false);
            SettingsForTests.ConfigureSettings(settings);

            const string input = "publishedVersion";

            Assert.AreEqual("PublishedVersion", input.ConvertCase(StringAliasCaseType.PascalCase));                                                     // obsolete, use the one below
            Assert.AreEqual("PublishedVersion", input.ToCleanString(CleanStringType.ConvertCase | CleanStringType.PascalCase | CleanStringType.Ascii)); // role, case and code
        }
        public void Setup()
        {
            //init the config singleton
            var config = SettingsForTests.GetDefault();

            SettingsForTests.ConfigureSettings(config);

            // media fs wants this
            ApplicationContext.Current = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()));

            // start clean
            // because some tests will create corrupt or weird filesystems
            FileSystemProviderManager.ResetCurrent();
        }
        public override void Initialize()
        {
            base.Initialize();
            SettingsForTests.ConfigureSettings(SettingsForTests.GenerateMockSettings());
            this.relationService = new Mock <IRelationService>();
            this.dataTypeService = new Mock <IDataTypeService>();

            this.serviceMock = new Mock <NexuService>(
                this.ProfilingLogger,
                this.relationService.Object,
                PropertyParserResolver.Current,
                this.dataTypeService.Object)
            {
                CallBase = true
            };
            this.service = this.serviceMock.Object;
        }
        public void Uri_From_Umbraco(string sourceUrl, string expectedUrl, bool directoryUrls, bool trailingSlash)
        {
            ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", directoryUrls ? "true" : "false");

            var settings    = SettingsForTests.GenerateMockSettings();
            var requestMock = Mock.Get(settings.RequestHandler);

            requestMock.Setup(x => x.AddTrailingSlash).Returns(trailingSlash);
            SettingsForTests.ConfigureSettings(settings);

            UriUtility.SetAppDomainAppVirtualPath("/");

            var expectedUri = NewUri(expectedUrl);
            var sourceUri   = NewUri(sourceUrl);
            var resultUri   = UriUtility.UriFromUmbraco(sourceUri);

            Assert.AreEqual(expectedUri.ToString(), resultUri.ToString());
        }
Exemple #5
0
        public override void Initialize()
        {
            base.Initialize();

            this.nexuServiceMock    = new Mock <INexuService>();
            this.mappingEngineMock  = new Mock <IMappingEngine>();
            this.contentServiceMock = new Mock <IContentService>();
            this.mediaServiceMock   = new Mock <IMediaService>();

            // Mocked settings are now necessary
            SettingsForTests.ConfigureSettings(SettingsForTests.GenerateMockSettings());

            // Routing context necessary for published content request
            this.RouteData = new RouteData();
            var routingContext = this.GetRoutingContext(
                "http://localhost",
                -1,
                this.RouteData,
                true,
                UmbracoConfig.For.UmbracoSettings());

            // setup umbraco context
            this.UmbracoContext = routingContext.UmbracoContext;

            this.controller = new NexuApiController(
                this.UmbracoContext,
                this.nexuServiceMock.Object,
                this.mappingEngineMock.Object,
                this.contentServiceMock.Object,
                this.mediaServiceMock.Object)
            {
                Request = new HttpRequestMessage
                {
                    Properties =
                    {
                        {
                            HttpPropertyKeys.HttpConfigurationKey,
                            new HttpConfiguration()
                        }
                    }
                }
            };
        }
        public void Convert_From_Standard_Xml()
        {
            var config = SettingsForTests.GenerateMockSettings();

            var contentMock = Mock.Get(config.Content);

            contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(true);

            SettingsForTests.ConfigureSettings(config);

            var nodeId = 2112;

            var xml  = XElement.Parse(@"<Image id=""2112"" version=""5b3e46ab-3e37-4cfa-ab70-014234b5bd39"" parentID=""2222"" level=""3"" writerID=""0"" nodeType=""1032"" template=""0"" sortOrder=""1"" createDate=""2010-05-19T17:32:46"" updateDate=""2010-05-19T17:32:46"" nodeName=""Sam's Umbraco Image"" urlName=""acnestressscrub"" writerName=""Administrator"" nodeTypeAlias=""Image"" path=""-1,1111,2222,2112"" isDoc="""">
				<umbracoFile><![CDATA[/media/1234/blah.pdf]]></umbracoFile>
				<umbracoWidth>115</umbracoWidth>
				<umbracoHeight>268</umbracoHeight>
				<umbracoBytes>10726</umbracoBytes>
				<umbracoExtension>jpg</umbracoExtension>
				<Image id=""3113"" version=""5b3e46ab-3e37-4cfa-ab70-014234b5bd33"" parentID=""2112"" level=""4"" writerID=""0"" nodeType=""1032"" template=""0"" sortOrder=""2"" createDate=""2010-05-19T17:32:46"" updateDate=""2010-05-19T17:32:46"" nodeName=""Another Umbraco Image"" urlName=""acnestressscrub"" writerName=""Administrator"" nodeTypeAlias=""Image"" path=""-1,1111,2222,2112,3113"" isDoc="""">
					<umbracoFile><![CDATA[/media/1234/blah.pdf]]></umbracoFile>
					<umbracoWidth>115</umbracoWidth>
					<umbracoHeight>268</umbracoHeight>
					<umbracoBytes>10726</umbracoBytes>
					<umbracoExtension>jpg</umbracoExtension>
				</Image>
			</Image>"            );
            var node = xml.DescendantsAndSelf("Image").Single(x => (int)x.Attribute("id") == nodeId);

            var publishedMedia = new PublishedMediaCache(ApplicationContext);

            var nav = node.CreateNavigator();

            var converted = publishedMedia.CreateFromCacheValues(
                publishedMedia.ConvertFromXPathNodeIterator(nav.Select("/Image"), nodeId));

            Assert.AreEqual(nodeId, converted.Id);
            Assert.AreEqual(3, converted.Level);
            Assert.AreEqual(1, converted.SortOrder);
            Assert.AreEqual("Sam's Umbraco Image", converted.Name);
            Assert.AreEqual("-1,1111,2222,2112", converted.Path);
        }
        public void TestNoScope()
        {
            content.TestingUpdateSitemapProvider = false;

            var settings    = SettingsForTests.GenerateMockSettings();
            var contentMock = Mock.Get(settings.Content);

            contentMock.Setup(x => x.XmlCacheEnabled).Returns(false);
            SettingsForTests.ConfigureSettings(settings);

            var contentType = new ContentType(-1)
            {
                Alias = "contenttype", Name = "test"
            };

            ApplicationContext.Services.ContentTypeService.Save(contentType);

            _cacheHandler = new CacheRefresherEventHandler(true);
            _cacheHandler.OnApplicationStarted(null, ApplicationContext);

            var xml = content.Instance.XmlContent;

            Assert.IsNotNull(xml);
            var beforeXml = xml.OuterXml;
            var item      = new Content("name", -1, contentType);

            ApplicationContext.Services.ContentService.SaveAndPublishWithStatus(item);

            Console.WriteLine("Xml Before:");
            Console.WriteLine(xml.OuterXml);
            Assert.AreEqual(beforeXml, xml.OuterXml);

            xml = content.Instance.XmlContent;
            Assert.IsNotNull(xml);
            Console.WriteLine("Xml After:");
            Console.WriteLine(xml.OuterXml);
            var node = xml.GetElementById(item.Id.ToString());

            Assert.IsNotNull(node);
        }
        public override void Initialize()
        {
            // required so we can access property.Value
            //PropertyValueConvertersResolver.Current = new PropertyValueConvertersResolver();

            base.Initialize();

            //generate new mock settings and assign so we can configure in individual tests
            _umbracoSettings = SettingsForTests.GenerateMockSettings();
            SettingsForTests.ConfigureSettings(_umbracoSettings);

            var scriptingMock = Mock.Get(_umbracoSettings.Scripting);

            scriptingMock.Setup(x => x.DataTypeModelStaticMappings).Returns(new List <IRazorStaticMapping>());

            // need to specify a custom callback for unit tests
            // AutoPublishedContentTypes generates properties automatically
            // when they are requested, but we must declare those that we
            // explicitely want to be here...

            var propertyTypes = new[]
            {
                // AutoPublishedContentType will auto-generate other properties
                new PublishedPropertyType("umbracoNaviHide", 0, "?"),
                new PublishedPropertyType("selectedNodes", 0, "?"),
                new PublishedPropertyType("umbracoUrlAlias", 0, "?"),
                new PublishedPropertyType("content", 0, Constants.PropertyEditors.TinyMCEAlias),
                new PublishedPropertyType("testRecursive", 0, "?"),
                new PublishedPropertyType("siteTitle", 0, "?"),
                new PublishedPropertyType("creatorName", 0, "?"),
                new PublishedPropertyType("blah", 0, "?"),     // ugly error when that one is missing...
            };
            var type = new AutoPublishedContentType(0, "anything", propertyTypes);

            PublishedContentType.GetPublishedContentTypeCallback = (alias) => type;
        }
 private void InitializeSettings()
 {
     // Stub up all the settings in Umbraco so we don't need a big app.config file.
     settings = SettingsForTests.GenerateMockSettings();
     SettingsForTests.ConfigureSettings(settings);
 }
        public void Init()
        {
            var config = SettingsForTests.GetDefault();

            SettingsForTests.ConfigureSettings(config);
        }
Exemple #11
0
 public override void Initialize()
 {
     base.Initialize();
     SettingsForTests.ConfigureSettings(SettingsForTests.GenerateMockSettings());
 }
        public void TestScopeMany(bool complete)
        {
            content.TestingUpdateSitemapProvider = false;

            var settings    = SettingsForTests.GenerateMockSettings();
            var contentMock = Mock.Get(settings.Content);

            contentMock.Setup(x => x.XmlCacheEnabled).Returns(false);
            SettingsForTests.ConfigureSettings(settings);

            var contentType = new ContentType(-1)
            {
                Alias = "contenttype", Name = "test"
            };

            ApplicationContext.Services.ContentTypeService.Save(contentType);

            _cacheHandler = new CacheRefresherEventHandler(true);
            _cacheHandler.OnApplicationStarted(null, ApplicationContext);

            var xml = content.Instance.XmlContent;

            Assert.IsNotNull(xml);
            var       beforeXml      = xml;
            var       beforeOuterXml = beforeXml.OuterXml;
            var       item           = new Content("name", -1, contentType);
            const int count          = 10;
            var       ids            = new int[count];
            var       clones         = 0;

            SafeXmlReaderWriter.Cloning = () => { clones++; };

            Console.WriteLine("Xml Before:");
            Console.WriteLine(xml.OuterXml);

            using (var scope = ApplicationContext.Current.ScopeProvider.CreateScope())
            {
                ApplicationContext.Services.ContentService.SaveAndPublishWithStatus(item);

                for (var i = 0; i < count; i++)
                {
                    var temp = new Content("content_" + i, -1, contentType);
                    ApplicationContext.Services.ContentService.SaveAndPublishWithStatus(temp);
                    ids[i] = temp.Id;
                }

                // this should never change
                Assert.AreEqual(beforeOuterXml, beforeXml.OuterXml);

                xml = content.Instance.XmlContent;
                Assert.IsNotNull(xml);
                Console.WriteLine("Xml InScope (before complete):");
                Console.WriteLine(xml.OuterXml);
                Assert.AreEqual(beforeOuterXml, xml.OuterXml);

                if (complete)
                {
                    scope.Complete();
                }

                xml = content.Instance.XmlContent;
                Assert.IsNotNull(xml);
                Console.WriteLine("Xml InScope (after complete):");
                Console.WriteLine(xml.OuterXml);
                Assert.AreEqual(beforeOuterXml, xml.OuterXml);
            }

            var scopeProvider = ApplicationContext.Current.ScopeProvider as IScopeProviderInternal;

            Assert.IsNotNull(scopeProvider);
            // ambient scope may be null, or maybe not, depending on whether the code that
            // was called did proper scoped work, or some direct (NoScope) use of the database
            Assert.IsNull(scopeProvider.AmbientContext);

            // limited number of clones!
            Assert.AreEqual(complete ? 1 : 0, clones);

            // this should never change
            Assert.AreEqual(beforeOuterXml, beforeXml.OuterXml);

            xml = content.Instance.XmlContent;
            Assert.IsNotNull(xml);
            Console.WriteLine("Xml After:");
            Console.WriteLine(xml.OuterXml);
            if (complete)
            {
                var node = xml.GetElementById(item.Id.ToString());
                Assert.IsNotNull(node);

                for (var i = 0; i < 10; i++)
                {
                    node = xml.GetElementById(ids[i].ToString());
                    Assert.IsNotNull(node);
                }
            }
            else
            {
                Assert.AreEqual(beforeOuterXml, xml.OuterXml); // nothing has changed!
            }
        }
        public void TestScope(bool complete)
        {
            content.TestingUpdateSitemapProvider = false;

            var httpContextItems = new Hashtable();

            content.HttpContextItemsGetter = () => httpContextItems;

            var settings    = SettingsForTests.GenerateMockSettings();
            var contentMock = Mock.Get(settings.Content);

            contentMock.Setup(x => x.XmlCacheEnabled).Returns(false);
            SettingsForTests.ConfigureSettings(settings);

            var contentType = new ContentType(-1)
            {
                Alias = "contenttype", Name = "test"
            };

            ApplicationContext.Services.ContentTypeService.Save(contentType);

            _cacheHandler = new CacheRefresherEventHandler(true);
            _cacheHandler.OnApplicationStarted(null, ApplicationContext);

            var xml = content.Instance.XmlContent;

            Assert.IsNotNull(xml);
            Assert.AreSame(xml, httpContextItems[content.XmlContextContentItemKey]);
            var beforeXml      = xml;
            var beforeOuterXml = beforeXml.OuterXml;
            var item           = new Content("name", -1, contentType);

            Console.WriteLine("Xml Before:");
            Console.WriteLine(xml.OuterXml);

            var evented = 0;

            _onPublishedAssertAction = () =>
            {
                evented++;
                xml = content.Instance.XmlContent;
                Assert.IsNotNull(xml);
                Assert.AreNotSame(beforeXml, xml);
                Console.WriteLine("Xml Event:");
                Console.WriteLine(xml.OuterXml);
                var node = xml.GetElementById(item.Id.ToString());
                Assert.IsNotNull(node);
            };

            ContentService.Published += OnPublishedAssert;

            using (var scope = ApplicationContext.Current.ScopeProvider.CreateScope())
            {
                ApplicationContext.Services.ContentService.SaveAndPublishWithStatus(item); // should create an xml clone
                item.Name = "changed";
                ApplicationContext.Services.ContentService.SaveAndPublishWithStatus(item); // should re-use the xml clone

                // this should never change
                Assert.AreEqual(beforeOuterXml, beforeXml.OuterXml);

                // this does not change, other thread don't see the changes
                xml = content.Instance.XmlContentInternal;
                Assert.IsNotNull(xml);
                Assert.AreSame(beforeXml, xml);
                Console.WriteLine("XmlInternal During:");
                Console.WriteLine(xml.OuterXml);
                Assert.AreEqual(beforeOuterXml, xml.OuterXml);

                // this does not change during the scope (only in events)
                // because it is the events that trigger the changes
                xml = content.Instance.XmlContent;
                Assert.IsNotNull(xml);
                Assert.AreSame(beforeXml, xml);

                // note
                // this means that, as long as ppl don't create scopes, they'll see their
                // changes right after SaveAndPublishWithStatus, but if they create scopes,
                // they will have to wail until the scope is completed, ie wait until the
                // events trigger, to use eg GetUrl etc

                if (complete)
                {
                    scope.Complete();
                }
            }

            //The reason why there is only 1 event occuring is because we are publishing twice for the same event for the same
            //object and the scope deduplicates the events (uses the latest)
            Assert.AreEqual(complete ? 1 : 0, evented);

            // this should never change
            Assert.AreEqual(beforeOuterXml, beforeXml.OuterXml);

            xml = content.Instance.XmlContent;
            Assert.IsNotNull(xml);
            Console.WriteLine("Xml After:");
            Console.WriteLine(xml.OuterXml);
            if (complete)
            {
                var node = xml.GetElementById(item.Id.ToString());
                Assert.IsNotNull(node);
            }
            else
            {
                Assert.AreSame(beforeXml, xml);
                Assert.AreEqual(beforeOuterXml, xml.OuterXml); // nothing has changed!
            }
        }
        public override void Initialize()
        {
            base.Initialize();

            settings = SettingsForTests.GenerateMockSettings();
            SettingsForTests.ConfigureSettings(settings);

            var routeData = new RouteData();

            routeData.Values["controller"] = "DummyTestController";
            routeData.Values["action"]     = "Index";

            routingContext = GetRoutingContext("http://localhost", -1, routeData, umbracoSettings: settings);
            umbracoContext = routingContext.UmbracoContext;

            httpContext = umbracoContext.HttpContext;
            var httpContextMock = Mock.Get(httpContext);

            httpContextMock.Setup(x => x.Items).Returns(
                new ListDictionary()
            {
                { HttpContextExtensions.HttpContextItemName, umbracoContext }
            }
                );

            response     = httpContext.Response;
            responseMock = Mock.Get(response);
            responseMock.Setup(r => r.ContentType).Returns("text/html");
            responseMock.SetupProperty(r => r.Filter, Stream.Null);

            var experimentsPipeline = new ExperimentsPipeline();

            experimentsPipeline.OnApplicationStarted(null, ApplicationContext);

            var originalMock = new Mock <IPublishedContent>();

            originalMock.Setup(c => c.Properties).Returns(new List <IPublishedProperty>());
            experimentMock = new Mock <IExperiment>();
            experimentMock.Setup(e => e.Id).Returns("TESTPERIMENT");

            publishedContentVariationMock = new Mock <IPublishedContentVariation>();
            publishedContentVariationMock.SetupAllProperties();
            publishedContentVariationMock.SetupProperty(p => p.Content, originalMock.Object);

            variedContent = new VariedContent(originalMock.Object, new [] { publishedContentVariationMock.Object });

            var docRequest = new PublishedContentRequest(
                new Uri("/", UriKind.Relative),
                routingContext,
                settings.WebRouting,
                s => Enumerable.Empty <string>())
            {
                PublishedContent = variedContent
            };

            docRequest.SetIsInitialPublishedContent();

            umbracoContext.PublishedContentRequest = docRequest;

            var viewContext = new Mock <ViewContext>();

            viewContext.Setup(c => c.HttpContext).Returns(httpContext);

            actionExecutedMock = new Mock <ActionExecutedContext>(MockBehavior.Strict);
            actionExecutedMock.Setup(f => f.IsChildAction).Returns(false);
            actionExecutedMock.Setup(f => f.HttpContext).Returns(httpContext);

            resultExecutedMock = new Mock <ResultExecutedContext>(MockBehavior.Strict);
            resultExecutedMock.Setup(f => f.HttpContext).Returns(httpContext);

            htmlHelper = new HtmlHelper(viewContext.Object, Mock.Of <IViewDataContainer>());
        }