public void UmbracoMapper_MapFromIPublishedContent_MapsWithStringDefaultValue() { // Using a shim of umbraco.dll using (ShimsContext.Create()) { // Arrange var model = new SimpleViewModel3(); var mapper = GetMapper(); var content = new StubPublishedContent(); // - shim GetPropertyValue (an extension method on IPublishedContent so can't be mocked) Umbraco.Web.Fakes.ShimPublishedContentExtensions.GetPropertyValueIPublishedContentStringBoolean = (doc, alias, recursive) => { switch (alias) { case "bodyText": return null; case "bodyText2": return string.Empty; default: return string.Empty; } }; // Act mapper.Map(content, model, new Dictionary<string, PropertyMapping> { { "BodyText", new PropertyMapping { DefaultValue = "Default body text", } }, { "BodyText2", new PropertyMapping { DefaultValue = "Default body text 2", } } }); // Assert Assert.AreEqual("Default body text", model.BodyText); Assert.AreEqual("Default body text 2", model.BodyText2); } }
public void UmbracoMapper_MapFromIPublishedContent_MapsOnlyCustomProperties() { // Using a shim of umbraco.dll using (ShimsContext.Create()) { // Arrange var model = new SimpleViewModel3(); var mapper = GetMapper(); var content = new StubPublishedContent(); // - shim GetPropertyValue (an extension method on IPublishedContent so can't be mocked) Umbraco.Web.Fakes.ShimPublishedContentExtensions.GetPropertyValueIPublishedContentStringBoolean = (doc, alias, recursive) => { switch (alias) { case "bodyText": return "This is the body text"; default: return string.Empty; } }; // Act mapper.Map(content, model, propertySet: PropertySet.Custom); // Assert Assert.AreEqual(0, model.Id); Assert.IsNull(model.Name); Assert.AreEqual("This is the body text", model.BodyText); } }
public void UmbracoMapper_MapFromIPublishedContent_MapsCustomPropertiesWithNonMatchingCondition() { // Using a shim of umbraco.dll using (ShimsContext.Create()) { // Arrange var model = new SimpleViewModel3(); var mapper = GetMapper(); var content = new StubPublishedContent(); // - shim GetPropertyValue (an extension method on IPublishedContent so can't be mocked) Umbraco.Web.Fakes.ShimPublishedContentExtensions.GetPropertyValueIPublishedContentStringBoolean = (doc, alias, recursive) => { switch (alias) { case "summaryText": return "Another value"; case "bodyText": return "This is the body text"; default: return string.Empty; } }; // Act mapper.Map(content, model, new Dictionary<string, PropertyMapping> { { "BodyText", new PropertyMapping { MapIfPropertyMatches = new KeyValuePair<string, string>("summaryText", "Test value") } } }); // Assert Assert.IsNull(model.BodyText); } }
public void UmbracoMapper_MapFromIPublishedContent_DoesNotMapIgnoredCustomPropertiesUsingDictionary() { // Using a shim of umbraco.dll using (ShimsContext.Create()) { // Arrange var model = new SimpleViewModel3(); var mapper = GetMapper(); var content = new StubPublishedContent(); // - shim GetPropertyValue (an extension method on IPublishedContent so can't be mocked) Umbraco.Web.Fakes.ShimPublishedContentExtensions.GetPropertyValueIPublishedContentStringBoolean = (doc, alias, recursive) => { switch (alias) { case "bodyText": return "This is the body text"; default: return string.Empty; } }; // Act mapper.Map(content, model, new Dictionary<string, PropertyMapping> { { "BodyText", new PropertyMapping { Ignore = true, } } }); // Assert Assert.AreEqual(1000, model.Id); Assert.AreEqual("Test content", model.Name); Assert.IsNull(model.BodyText); } }
public void UmbracoMapper_MapFromIPublishedContent_MapsCustomPropertiesWithStringFormatter() { // Using a shim of umbraco.dll using (ShimsContext.Create()) { // Arrange var model = new SimpleViewModel3(); var mapper = GetMapper(); var content = new StubPublishedContent(); // - shim GetPropertyValue (an extension method on IPublishedContent so can't be mocked) Umbraco.Web.Fakes.ShimPublishedContentExtensions.GetPropertyValueIPublishedContentStringBoolean = (doc, alias, recursive) => { switch (alias) { case "bodyText": return "This is the body text"; default: return string.Empty; } }; // Act mapper.Map(content, model, new Dictionary<string, PropertyMapping> { { "BodyText", new PropertyMapping { StringValueFormatter = x => { return x.ToUpper(); } } } }); // Assert Assert.AreEqual("THIS IS THE BODY TEXT", model.BodyText); } }
public void UmbracoMapper_MapFromIPublishedContent_MapsWithIntegerDefaultValue() { // Using a shim of umbraco.dll using (ShimsContext.Create()) { // Arrange var model = new SimpleViewModel3(); var mapper = GetMapper(); var content = new StubPublishedContent(); // - shim GetPropertyValue (an extension method on IPublishedContent so can't be mocked) Umbraco.Web.Fakes.ShimPublishedContentExtensions.GetPropertyValueIPublishedContentStringBoolean = (doc, alias, recursive) => { return string.Empty; }; // Act mapper.Map(content, model, new Dictionary<string, PropertyMapping> { { "NonMapped", new PropertyMapping { DefaultValue = 99, } } }); // Assert Assert.AreEqual(99, model.NonMapped); } }