public void Can_Update_MediaType_With_PropertyType_Removed()
        {
            // Arrange
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var repository = CreateRepository(provider);

                var mediaType = MockedContentTypes.CreateNewMediaType();
                repository.Save(mediaType);


                // Act
                var mediaTypeV2 = repository.Get(NodeDto.NodeIdSeed);
                mediaTypeV2.PropertyGroups["Media"].PropertyTypes.Remove("title");
                repository.Save(mediaTypeV2);


                var mediaTypeV3 = repository.Get(NodeDto.NodeIdSeed);

                // Assert
                Assert.That(mediaTypeV3.PropertyTypes.Any(x => x.Alias == "title"), Is.False);
                Assert.That(mediaTypeV2.PropertyGroups.Count, Is.EqualTo(mediaTypeV3.PropertyGroups.Count));
                Assert.That(mediaTypeV2.PropertyTypes.Count(), Is.EqualTo(mediaTypeV3.PropertyTypes.Count()));
            }
        }
        public void Can_Perform_Add_On_MediaTypeRepository()
        {
            // Arrange
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var repository = CreateRepository(provider);

                // Act
                var contentType = MockedContentTypes.CreateNewMediaType();
                repository.Save(contentType);


                var fetched = repository.Get(contentType.Id);

                // Assert
                Assert.That(contentType.HasIdentity, Is.True);
                Assert.That(contentType.PropertyGroups.All(x => x.HasIdentity), Is.True);
                Assert.That(contentType.Path.Contains(","), Is.True);
                Assert.That(contentType.SortOrder, Is.GreaterThan(0));

                TestHelper.AssertPropertyValuesAreEqual(contentType, fetched, "yyyy-MM-dd HH:mm:ss", ignoreProperties: new[] { "UpdateDate" });
            }
        }
        public void Can_Delete_Container_Containing_Media_Types()
        {
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var containerRepository = CreateContainerRepository(provider);
                var repository          = CreateRepository(provider);

                var container = new EntityContainer(Constants.ObjectTypes.MediaType)
                {
                    Name = "blah"
                };
                containerRepository.Save(container);


                IMediaType contentType = MockedContentTypes.CreateNewMediaType();
                contentType.ParentId = container.Id;
                repository.Save(contentType);


                // Act
                containerRepository.Delete(container);


                var found = containerRepository.Get(container.Id);
                Assert.IsNull(found);

                contentType = repository.Get(contentType.Id);
                Assert.IsNotNull(contentType);
                Assert.AreEqual(-1, contentType.ParentId);
            }
        }
        public void Cannot_Save_Media_With_Empty_Name()
        {
            // Arrange
            var mediaService = ServiceContext.MediaService;
            var mediaType    = MockedContentTypes.CreateNewMediaType();

            ServiceContext.MediaTypeService.Save(mediaType);
            var media = mediaService.CreateMedia(string.Empty, -1, "video");

            // Act & Assert
            Assert.Throws <ArgumentException>(() => mediaService.Save(media));
        }
        public void Can_Move()
        {
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var containerRepository = CreateContainerRepository(provider);
                var repository          = CreateRepository(provider);

                var container1 = new EntityContainer(Constants.ObjectTypes.MediaType)
                {
                    Name = "blah1"
                };
                containerRepository.Save(container1);


                var container2 = new EntityContainer(Constants.ObjectTypes.MediaType)
                {
                    Name = "blah2", ParentId = container1.Id
                };
                containerRepository.Save(container2);


                var contentType = (IMediaType)MockedContentTypes.CreateNewMediaType();
                contentType.ParentId = container2.Id;
                repository.Save(contentType);


                //create a
                var contentType2 = (IMediaType) new MediaType(contentType, "hello")
                {
                    Name = "Blahasdfsadf"
                };
                contentType.ParentId = contentType.Id;
                repository.Save(contentType2);


                var result = repository.Move(contentType, container1).ToArray();


                Assert.AreEqual(2, result.Length);

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

                Assert.AreEqual(container1.Id, contentType.ParentId);
                Assert.AreNotEqual(result.Single(x => x.Entity.Id == contentType.Id).OriginalPath, contentType.Path);
                Assert.AreNotEqual(result.Single(x => x.Entity.Id == contentType2.Id).OriginalPath, contentType2.Path);
            }
        }
        public void Ensure_Content_Xml_Created()
        {
            var mediaService = ServiceContext.MediaService;
            var mediaType    = MockedContentTypes.CreateNewMediaType();

            ServiceContext.MediaTypeService.Save(mediaType);
            var media = mediaService.CreateMedia("Test", -1, "video");

            mediaService.Save(media);

            using (var scope = ScopeProvider.CreateScope())
            {
                Assert.IsTrue(scope.Database.Exists <ContentXmlDto>(media.Id));
            }
        }
        public void Can_Verify_PropertyTypes_On_Video_MediaType()
        {
            // Arrange
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var repository = CreateRepository(provider);

                var mediaType = MockedContentTypes.CreateNewMediaType();
                repository.Save(mediaType);


                // Act
                var contentType = repository.Get(NodeDto.NodeIdSeed);

                // Assert
                Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(2));
                Assert.That(contentType.PropertyGroups.Count(), Is.EqualTo(1));
            }
        }
        public void Can_Perform_Update_On_MediaTypeRepository()
        {
            // Arrange
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var repository = CreateRepository(provider);

                var videoMediaType = MockedContentTypes.CreateNewMediaType();
                repository.Save(videoMediaType);


                // Act
                var mediaType = repository.Get(NodeDto.NodeIdSeed);

                mediaType.Thumbnail = "Doc2.png";
                mediaType.PropertyGroups["Media"].PropertyTypes.Add(new PropertyType("test", ValueStorageType.Ntext, "subtitle")
                {
                    Name        = "Subtitle",
                    Description = "Optional Subtitle",
                    Mandatory   = false,
                    SortOrder   = 1,
                    DataTypeId  = -88
                });
                repository.Save(mediaType);


                var dirty = ((MediaType)mediaType).IsDirty();

                // Assert
                Assert.That(mediaType.HasIdentity, Is.True);
                Assert.That(dirty, Is.False);
                Assert.That(mediaType.Thumbnail, Is.EqualTo("Doc2.png"));
                Assert.That(mediaType.PropertyTypes.Any(x => x.Alias == "subtitle"), Is.True);
            }
        }
        public void Can_Perform_Delete_On_MediaTypeRepository()
        {
            // Arrange
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var repository = CreateRepository(provider);

                // Act
                var mediaType = MockedContentTypes.CreateNewMediaType();
                repository.Save(mediaType);


                var contentType2 = repository.Get(mediaType.Id);
                repository.Delete(contentType2);


                var exists = repository.Exists(mediaType.Id);

                // Assert
                Assert.That(exists, Is.False);
            }
        }