Exemplo n.º 1
0
        public void TestGetLinkedEntitiesWithValue()
        {
            // arrange
            var parser = new ContentPickerParser();

            var propertyType = new PropertyType(
                global::Umbraco.Core.Constants.PropertyEditors.ContentPickerAlias,
                DataTypeDatabaseType.Integer,
                "cp1");

            var property = new Property(propertyType, 1500);

            // act
            var result = parser.GetLinkedEntities(property.Value);

            // verify
            Assert.IsNotNull(result);
            var entities = result.ToList();

            Assert.AreEqual(1, entities.Count());

            var entity = entities.First();

            Assert.AreEqual(LinkedEntityType.Document, entity.LinkedEntityType);
            Assert.AreEqual(1500, entity.Id);
        }
Exemplo n.º 2
0
        public void TestGetLinkedEntitiesWithValueV76()
        {
            // arrange
            var contentServiceMock = new Mock <IContentService>();

            var cacheProviderMock = new Mock <ICacheProvider>();

            cacheProviderMock.Setup(x => x.GetCacheItem(It.IsAny <string>(), It.IsAny <Func <object> >()))
            .Returns((string k, Func <object> action) => action());

            var key  = "84ccc854d4bf47d8a2d6833c9fd5fed7";
            var guid = Guid.Parse(key);

            var contentMock = new Mock <IContent>();

            contentMock.SetupGet(x => x.Id).Returns(1500);

            contentServiceMock.Setup(x => x.GetById(guid)).Returns(contentMock.Object);

            var parser = new ContentPickerParser(contentServiceMock.Object, cacheProviderMock.Object);

            var propertyType = new PropertyType(
                "Umbraco.ContentPicker2",
                DataTypeDatabaseType.Nvarchar,
                "cp1");

            var property = new Property(propertyType, $"umb://document/{key}");

            // act
            var result = parser.GetLinkedEntities(property.Value);

            // verify
            contentServiceMock.Verify(x => x.GetById(guid), Times.Once);

            Assert.IsNotNull(result);
            var entities = result.ToList();

            Assert.AreEqual(1, entities.Count());

            var entity = entities.First();

            Assert.AreEqual(LinkedEntityType.Document, entity.LinkedEntityType);
            Assert.AreEqual(1500, entity.Id);
        }