Esempio n. 1
0
        public void MapToCms_SavingName_UpdatesTheItemName()
        {
            //Assign
            var type     = UmbracoInfoType.Name;
            var expected = "new name";

            var mapper = new UmbracoInfoMapper();
            var config = new UmbracoInfoConfiguration();

            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var contentService = new ContentService(_unitOfWork, _repoFactory);
            var content        = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}"));
            var oldName        = content.Name;

            Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists");

            var resolver = DependencyResolver.CreateStandardResolver();

            resolver.Container.Register(
                Component.For <Mapper.Config>().Instance(new Mapper.Config())
                );
            var context = Context.Create(resolver);

            var dataContext = new UmbracoDataMappingContext(null, content, new UmbracoService(contentService, context), false);

            dataContext.PropertyValue = expected;

            string actual = string.Empty;

            //Act
            mapper.MapToCms(dataContext);
            content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}"));
            actual  = content.Name;

            //Assert
            Assert.AreEqual(expected, actual);

            content.Name = oldName;
            contentService.Save(content);
        }
        public void MapToProperty_UmbracoInfoType_GetsExpectedValueFromUmbraco(
            [Values(
                 //UmbracoInfoType.Url,
                 UmbracoInfoType.ContentTypeAlias,
                 UmbracoInfoType.ContentTypeName,
                 UmbracoInfoType.Name,
                 UmbracoInfoType.Creator
                 )] UmbracoInfoType type,
            [Values(
                 //"target", //Url
                 "TestType",  //ContentTypeAlias
                 "Test Type", //ContentTypeName
                 "Target",    //Name
                 "admin"      //Creator
                 )] object expected
            )
        {
            //Assign
            var mapper = new UmbracoInfoMapper();
            var config = new UmbracoInfoConfiguration();

            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var contentService = new ContentService(_unitOfWork, _repoFactory);
            var content        = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}"));

            Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists");
            var dataContext = new UmbracoDataMappingContext(null, content, null);

            //Act
            var value = mapper.MapToProperty(dataContext);

            Console.WriteLine(type);

            //Assert
            Assert.AreEqual(expected, value);
        }
        public void MapToProperty_UmbracoInfoTypeNotSet_ThrowsException()
        {
            //Assign
            UmbracoInfoType type = UmbracoInfoType.NotSet;

            var mapper = new UmbracoInfoMapper();
            var config = new UmbracoInfoConfiguration();

            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var contentService = new ContentService(_unitOfWork, _repoFactory);
            var content        = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}"));

            Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists");
            var dataContext = new UmbracoDataMappingContext(null, content, null);

            //Act
            var value = mapper.MapToProperty(dataContext);

            //Assert
            //No asserts expect exception
        }
        public void MapToProperty_UmbracoInfoTypeUpdateDate_ReturnsUpdateDateAsDateTime()
        {
            //Assign
            var type = UmbracoInfoType.UpdateDate;

            var mapper = new UmbracoInfoMapper();
            var config = new UmbracoInfoConfiguration();

            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var contentService = new ContentService(_unitOfWork, _repoFactory);
            var content        = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}"));
            var expected       = content.UpdateDate;

            Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists");
            var dataContext = new UmbracoDataMappingContext(null, content, null);

            //Act
            var value = mapper.MapToProperty(dataContext);

            //Assert
            Assert.AreEqual(expected, value);
        }