public void UmbracoMapper_MapFromIPublishedContent_MapsUsingCustomMappingWithNonMatchingPropertyCondition() { // Using a shim of umbraco.dll using (ShimsContext.Create()) { // Arrange var model = new SimpleViewModel8(); var content = new StubPublishedContent(); var mapper = GetMapper(); mapper.AddCustomMapping(typeof(GeoCoordinate).FullName, MapGeoCoordinate, "AnotherProperty"); // - shim GetPropertyValue (an extension method on IPublishedContent so can't be mocked) Umbraco.Web.Fakes.ShimPublishedContentExtensions.GetPropertyValueIPublishedContentStringBoolean = (doc, alias, recursive) => { switch (alias) { case "geoCoordinate": return "5.5,10.5,7"; default: return string.Empty; } }; // Act mapper.Map(content, model); // Assert Assert.IsNull(model.GeoCoordinate); } }
public void UmbracoMapper_MapFromDictionaryWithCustomMapping_MapsPropertiesWithMatchingNames() { // Arrange var model = new SimpleViewModel8(); var dictionary = GetDictionaryForSingle(); var mapper = GetMapper(); mapper.AddCustomMapping(typeof(GeoCoordinate).FullName, MapGeoCoordinateFromObject); // Act mapper.Map(dictionary, model); // Assert Assert.IsNotNull(model.GeoCoordinate); Assert.AreEqual((decimal)5.5, model.GeoCoordinate.Latitude); Assert.AreEqual((decimal)10.5, model.GeoCoordinate.Longitude); Assert.AreEqual(7, model.GeoCoordinate.Zoom); }