Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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));
            }
        }
Ejemplo n.º 3
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"));
            }
        }