Пример #1
0
        public void Can_Perform_Update_On_ScriptRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = ScopeProvider.CreateScope())
            {
                IScriptRepository repository = CreateRepository();

                // Act
                var script = new Script("test-updated-script.js")
                {
                    Content = "/// <reference name=\"MicrosoftAjax.js\"/>"
                };
                repository.Save(script);

                script.Content = "/// <reference name=\"MicrosoftAjax-Updated.js\"/>";
                repository.Save(script);

                IScript scriptUpdated = repository.Get("test-updated-script.js");

                // Assert
                Assert.That(_fileSystem.FileExists("test-updated-script.js"), Is.True);
                Assert.That(scriptUpdated.Content, Is.EqualTo("/// <reference name=\"MicrosoftAjax-Updated.js\"/>"));
            }
        }
Пример #2
0
        public void Can_Perform_Update_On_DictionaryRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                IDictionaryRepository repository = CreateRepository();

                // Act
                IDictionaryItem item         = repository.Get(1);
                var             translations = item.Translations.ToList();
                translations[0].Value = "Read even more";
                item.Translations     = translations;

                repository.Save(item);

                IDictionaryItem dictionaryItem = repository.Get(1);

                // Assert
                Assert.That(dictionaryItem, Is.Not.Null);
                Assert.That(dictionaryItem.Translations.Count(), Is.EqualTo(2));
                Assert.That(dictionaryItem.Translations.FirstOrDefault().Value, Is.EqualTo("Read even more"));
            }
        }
Пример #3
0
        public void Getting_100_Uncached_Items()
        {
            // Arrange
            IContentType          contentType = ContentTypeService.Get(ContentType.Id);
            IEnumerable <Content> pages       = ContentBuilder.CreateTextpageContent(contentType, -1, 100);

            ContentService.Save(pages, 0);

            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                DocumentRepository repository = DocumentRepository;

                // Act
                var watch = Stopwatch.StartNew();
                IEnumerable <IContent> contents = repository.GetMany();
                watch.Stop();
                long elapsed = watch.ElapsedMilliseconds;

                Debug.Print("100 content items retrieved in {0} ms without caching", elapsed);

                // Assert
                Assert.That(contents.Any(x => x.HasIdentity == false), Is.False);
                Assert.That(contents.Any(x => x == null), Is.False);
            }
        }
Пример #4
0
        public void Can_Perform_Add_On_DictionaryRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                ILanguageRepository   languageRepository = GetRequiredService <ILanguageRepository>();
                IDictionaryRepository repository         = CreateRepository();

                ILanguage language = languageRepository.Get(1);

                var read         = new DictionaryItem("Read");
                var translations = new List <IDictionaryTranslation>
                {
                    new DictionaryTranslation(language, "Read")
                };
                read.Translations = translations;

                // Act
                repository.Save(read);

                bool exists = repository.Exists(read.Id);

                // Assert
                Assert.That(read.HasIdentity, Is.True);
                Assert.That(exists, Is.True);
            }
        }
Пример #5
0
        public void Can_Perform_Get_On_DictionaryRepository()
        {
            // Arrange
            ILocalizationService localizationService = GetRequiredService <ILocalizationService>();
            IScopeProvider       provider            = ScopeProvider;

            using (provider.CreateScope())
            {
                IDictionaryRepository repository = CreateRepository();
                var dictionaryItem = (IDictionaryItem) new DictionaryItem("Testing1235")
                {
                    Translations = new List <IDictionaryTranslation>
                    {
                        new DictionaryTranslation(localizationService.GetLanguageByIsoCode("en-US"), "Hello world")
                    }
                };

                repository.Save(dictionaryItem);

                // re-get
                dictionaryItem = repository.Get(dictionaryItem.Id);

                // Assert
                Assert.That(dictionaryItem, Is.Not.Null);
                Assert.That(dictionaryItem.ItemKey, Is.EqualTo("Testing1235"));
                Assert.That(dictionaryItem.Translations.Any(), Is.True);
                Assert.That(dictionaryItem.Translations.Any(x => x == null), Is.False);
                Assert.That(dictionaryItem.Translations.First().Value, Is.EqualTo("Hello world"));
            }
        }
Пример #6
0
        public void Can_Perform_Update_WithNewTranslation_On_DictionaryRepository()
        {
            // Arrange
            ILocalizationService localizationService = GetRequiredService <ILocalizationService>();
            IScopeProvider       provider            = ScopeProvider;

            using (provider.CreateScope())
            {
                IDictionaryRepository repository = CreateRepository();

                var languageNo = new Language("nb-NO", "Norwegian Bokmål (Norway)");
                localizationService.Save(languageNo);

                // Act
                IDictionaryItem item         = repository.Get(1);
                var             translations = item.Translations.ToList();
                translations.Add(new DictionaryTranslation(languageNo, "Les mer"));
                item.Translations = translations;

                repository.Save(item);

                var dictionaryItem = (DictionaryItem)repository.Get(1);

                // Assert
                Assert.That(dictionaryItem, Is.Not.Null);
                Assert.That(dictionaryItem.Translations.Count(), Is.EqualTo(3));
                Assert.That(dictionaryItem.Translations.Single(t => t.LanguageId == languageNo.Id).Value, Is.EqualTo("Les mer"));
            }
        }
        public void WriteLockExisting()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                scope.EagerWriteLock(Constants.Locks.Servers);
                scope.Complete();
            }
        }
        public void WriteLockNonExisting()
        {
            IScopeProvider provider = ScopeProvider;

            Assert.Throws <ArgumentException>(() =>
            {
                using (IScope scope = provider.CreateScope())
                {
                    scope.EagerWriteLock(-666);
                    scope.Complete();
                }
            });
        }
Пример #9
0
        public void Can_Instantiate_Repository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = ScopeProvider.CreateScope())
            {
                // Act
                IScriptRepository repository = CreateRepository();

                // Assert
                Assert.That(repository, Is.Not.Null);
            }
        }
Пример #10
0
        public void Can_Perform_Exists_On_DictionaryRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                IDictionaryRepository repository = CreateRepository();

                // Act
                bool exists = repository.Exists(1);

                // Assert
                Assert.That(exists, Is.True);
            }
        }
Пример #11
0
        public void Can_Perform_Count_On_DictionaryRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                IDictionaryRepository repository = CreateRepository();

                // Act
                IQuery <IDictionaryItem> query = provider.CreateQuery <IDictionaryItem>().Where(x => x.ItemKey.StartsWith("Read"));
                int result = repository.Count(query);

                // Assert
                Assert.That(result, Is.EqualTo(1));
            }
        }
Пример #12
0
        public void Get_Paged_Children_With_Media_Type_Filter()
        {
            MediaType mediaType1 = MediaTypeBuilder.CreateImageMediaType("Image2");

            MediaTypeService.Save(mediaType1);
            MediaType mediaType2 = MediaTypeBuilder.CreateImageMediaType("Image3");

            MediaTypeService.Save(mediaType2);

            for (int i = 0; i < 10; i++)
            {
                Media m1 = MediaBuilder.CreateMediaImage(mediaType1, -1);
                MediaService.Save(m1);
                Media m2 = MediaBuilder.CreateMediaImage(mediaType2, -1);
                MediaService.Save(m2);
            }

            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                IEnumerable <IMedia> result = MediaService.GetPagedChildren(
                    -1,
                    0,
                    11,
                    out long total,
                    provider.CreateQuery <IMedia>()
                    .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)),
                    Ordering.By("SortOrder", Direction.Ascending));
                Assert.AreEqual(11, result.Count());
                Assert.AreEqual(20, total);

                result = MediaService.GetPagedChildren(
                    -1,
                    1,
                    11,
                    out total,
                    provider.CreateQuery <IMedia>()
                    .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)),
                    Ordering.By("SortOrder", Direction.Ascending));
                Assert.AreEqual(9, result.Count());
                Assert.AreEqual(20, total);
            }
        }
Пример #13
0
        public void Can_Perform_GetDictionaryItemKeyMap_On_DictionaryRepository()
        {
            Dictionary <string, Guid> keyMap;

            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                IDictionaryRepository repository = CreateRepository();
                keyMap = repository.GetDictionaryItemKeyMap();
            }

            Assert.IsNotNull(keyMap);
            Assert.IsNotEmpty(keyMap);
            foreach (KeyValuePair <string, Guid> kvp in keyMap)
            {
                Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value);
            }
        }
Пример #14
0
        public void Can_Perform_Delete_On_DictionaryRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                IDictionaryRepository repository = CreateRepository();

                // Act
                IDictionaryItem item = repository.Get(1);
                repository.Delete(item);

                bool exists = repository.Exists(1);

                // Assert
                Assert.That(exists, Is.False);
            }
        }
Пример #15
0
        public void Can_Perform_GetAll_With_Params_On_DictionaryRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                IDictionaryRepository repository = CreateRepository();

                // Act
                IEnumerable <IDictionaryItem> dictionaryItems = repository.GetMany(1, 2);

                // Assert
                Assert.That(dictionaryItems, Is.Not.Null);
                Assert.That(dictionaryItems.Any(), Is.True);
                Assert.That(dictionaryItems.Any(x => x == null), Is.False);
                Assert.That(dictionaryItems.Count(), Is.EqualTo(2));
            }
        }
Пример #16
0
        public void Can_Perform_GetByQuery_On_DictionaryRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                IDictionaryRepository repository = CreateRepository();

                // Act
                IQuery <IDictionaryItem>      query  = provider.CreateQuery <IDictionaryItem>().Where(x => x.ItemKey == "Article");
                IEnumerable <IDictionaryItem> result = repository.Get(query);

                // Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result.Any(), Is.True);
                Assert.That(result.FirstOrDefault().ItemKey, Is.EqualTo("Article"));
            }
        }
Пример #17
0
        public void ReadLockNonExisting()
        {
            var lockingMechanism = GetRequiredService <IDistributedLockingMechanismFactory>().DistributedLockingMechanism;

            if (lockingMechanism is SqliteDistributedLockingMechanism)
            {
                Assert.Ignore("SqliteDistributedLockingMechanism doesn't query the umbracoLock table for read locks.");
            }

            IScopeProvider provider = ScopeProvider;

            Assert.Throws <ArgumentException>(() =>
            {
                using (IScope scope = provider.CreateScope())
                {
                    scope.EagerReadLock(-666);
                    scope.Complete();
                }
            });
        }
Пример #18
0
        public void Can_Perform_Add_On_ScriptRepository()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = ScopeProvider.CreateScope())
            {
                IScriptRepository repository = CreateRepository();

                // Act
                var script = new Script("test-add-script.js")
                {
                    Content = "/// <reference name=\"MicrosoftAjax.js\"/>"
                };
                repository.Save(script);

                // Assert
                Assert.That(_fileSystem.FileExists("test-add-script.js"), Is.True);
            }
        }
Пример #19
0
        public void Can_Perform_Get_On_DictionaryRepository_When_No_Language_Assigned()
        {
            // Arrange
            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                IDictionaryRepository repository = CreateRepository();
                var dictionaryItem = (IDictionaryItem) new DictionaryItem("Testing1235");

                repository.Save(dictionaryItem);

                // re-get
                dictionaryItem = repository.Get(dictionaryItem.Id);

                // Assert
                Assert.That(dictionaryItem, Is.Not.Null);
                Assert.That(dictionaryItem.ItemKey, Is.EqualTo("Testing1235"));
                Assert.That(dictionaryItem.Translations.Any(), Is.False);
            }
        }
Пример #20
0
        public void PathTests()
        {
            // unless noted otherwise, no changes / 7.2.8
            FileSystems fileSystems = FileSystemsCreator.CreateTestFileSystems(LoggerFactory, IOHelper,
                                                                               GetRequiredService <IOptions <GlobalSettings> >(), HostingEnvironment,
                                                                               null, _fileSystem, null, null, null);

            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                var repository = new PartialViewRepository(fileSystems);

                IPartialView partialView = new PartialView(PartialViewType.PartialView, "test-path-1.cshtml")
                {
                    Content = "// partialView"
                };
                repository.Save(partialView);
                Assert.IsTrue(_fileSystem.FileExists("test-path-1.cshtml"));
                Assert.AreEqual("test-path-1.cshtml", partialView.Path);
                Assert.AreEqual("/Views/Partials/test-path-1.cshtml", partialView.VirtualPath);

                partialView = new PartialView(PartialViewType.PartialView, "path-2/test-path-2.cshtml")
                {
                    Content = "// partialView"
                };
                repository.Save(partialView);
                Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-2.cshtml"));
                Assert.AreEqual("path-2\\test-path-2.cshtml".Replace("\\", $"{Path.DirectorySeparatorChar}"), partialView.Path);
                Assert.AreEqual("/Views/Partials/path-2/test-path-2.cshtml", partialView.VirtualPath);

                partialView = repository.Get("path-2/test-path-2.cshtml");
                Assert.IsNotNull(partialView);
                Assert.AreEqual("path-2\\test-path-2.cshtml".Replace("\\", $"{Path.DirectorySeparatorChar}"), partialView.Path);
                Assert.AreEqual("/Views/Partials/path-2/test-path-2.cshtml", partialView.VirtualPath);

                partialView = new PartialView(PartialViewType.PartialView, "path-2\\test-path-3.cshtml")
                {
                    Content = "// partialView"
                };
                repository.Save(partialView);
                Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-3.cshtml"));
                Assert.AreEqual("path-2\\test-path-3.cshtml".Replace("\\", $"{Path.DirectorySeparatorChar}"), partialView.Path);
                Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath);

                partialView = repository.Get("path-2/test-path-3.cshtml");
                Assert.IsNotNull(partialView);
                Assert.AreEqual("path-2\\test-path-3.cshtml".Replace("\\", $"{Path.DirectorySeparatorChar}"), partialView.Path);
                Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath);

                partialView = repository.Get("path-2\\test-path-3.cshtml");
                Assert.IsNotNull(partialView);
                Assert.AreEqual("path-2\\test-path-3.cshtml".Replace("\\", $"{Path.DirectorySeparatorChar}"), partialView.Path);
                Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath);

                partialView = new PartialView(PartialViewType.PartialView, "..\\test-path-4.cshtml")
                {
                    Content = "// partialView"
                };
                Assert.Throws <UnauthorizedAccessException>(() =>
                                                            repository.Save(partialView));

                partialView = new PartialView(PartialViewType.PartialView, "\\test-path-5.cshtml")
                {
                    Content = "// partialView"
                };
                repository.Save(partialView);

                partialView = repository.Get("\\test-path-5.cshtml");
                Assert.IsNotNull(partialView);
                Assert.AreEqual("test-path-5.cshtml", partialView.Path);
                Assert.AreEqual("/Views/Partials/test-path-5.cshtml", partialView.VirtualPath);

                partialView = repository.Get("missing.cshtml");
                Assert.IsNull(partialView);

                Assert.Throws <UnauthorizedAccessException>(() => partialView = repository.Get("..\\test-path-4.cshtml"));
                Assert.Throws <UnauthorizedAccessException>(() => partialView = repository.Get("../../packages.config"));
            }
        }