Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
53e8df9
fixed Error message of StringLengthRule
h0lg Mar 25, 2011
92741b5
renamed ConcernOfComparingComplexModelMetadata to ConcernOfComparingM…
h0lg Mar 29, 2011
bab4892
changed reference to System.Web.Mvc from relative HintPath to GAC pre…
h0lg Mar 29, 2011
aa44a44
fixing psake by running tests using xunit.console.clr4.exe
h0lg Apr 4, 2011
86dee29
skipping test requiring EF to be installed
h0lg Apr 4, 2011
bd9cf4b
remove unused variable
h0lg Apr 4, 2011
2353877
corrected ErrorMessageFormat of RangeRule and parameter order of exce…
h0lg Apr 18, 2011
4508bad
updated gitignore with UpgradeReport files & *.orig files from KDiff3…
h0lg Apr 18, 2011
9a36a8f
fixed ClassRuleModelValidator.Validate method to use Metadata.Model a…
h0lg Apr 19, 2011
9874f1a
fixed comments
h0lg Apr 23, 2011
3d71c46
added ConvertEmptyStringToNull property to Metadata
h0lg Mar 28, 2011
491810a
just clarified tasks
h0lg Mar 29, 2011
8e05e47
task for writing missing Metadata.CopyMetaDataFrom tests
h0lg Apr 4, 2011
06baf71
added Custom DataType to IAsProperty
h0lg Apr 4, 2011
895b232
refactored RangeRule to accept IComparables
h0lg Apr 18, 2011
6dcf254
made RangeRule accessible to configuration API via Range(min,max) on …
h0lg Apr 18, 2011
7f0a573
refactored duplicated StringLength information into Getter function o…
h0lg Apr 18, 2011
e903680
added support for minimum string length in rule & configuration API
h0lg Apr 18, 2011
34c1f14
made PropertyMustMatchRule available in API throgh Class.PropertiesSh…
h0lg Apr 18, 2011
83e5b05
added task for System.Web.Mvc.IClientValidatable support
h0lg Apr 18, 2011
99e72f6
commented untested property mappings in Metadata.CopyMetaDataFrom
h0lg Apr 23, 2011
17806f9
copying DataTypeName on CopyMetadataFrom
h0lg Apr 23, 2011
29ef2f8
copying Description on CopyMetadataFrom
h0lg Apr 23, 2011
b1bce04
copying DisplayFormat on CopyMetadataFrom
h0lg Apr 23, 2011
2ccb7bf
copying EditorFormat on CopyMetadataFrom
h0lg Apr 23, 2011
e6636ee
copying HideSurroundingHtml on CopyMetadataFrom
h0lg Apr 23, 2011
a64a170
copying Readonly on CopyMetadataFrom
h0lg Apr 23, 2011
8b748ac
copying NullDisplayText on CopyMetadataFrom
h0lg Apr 23, 2011
b7ac31b
copying ShowDisplay on CopyMetadataFrom
h0lg Apr 23, 2011
4008eb9
copying ShowEditor on CopyMetadataFrom
h0lg Apr 23, 2011
47f0104
copying TemplateHint on CopyMetadataFrom
h0lg Apr 23, 2011
35bde53
copying Watermark on CopyMetadataFrom
h0lg Apr 23, 2011
4f312d0
copying ConvertEmptyStringToNull on CopyMetadataFrom
h0lg Apr 23, 2011
96e77b7
copying Hidden on CopyMetadataFrom
h0lg Apr 23, 2011
42922a7
copying Rules on CopyMetadataFrom
h0lg Apr 23, 2011
3650e3a
added XML docs for Metadata.Hidden
h0lg Apr 23, 2011
7ff2971
updated tasks
h0lg Apr 23, 2011
48495b8
tested for ContainerType being correct on copied metadata
h0lg Apr 23, 2011
80f5ea5
deleted tasks for Metadata properties that don't need to be copied
h0lg Apr 23, 2011
f1d0d89
wrote task for mapping missing Metadata properties in FluentMetadata.…
h0lg Apr 25, 2011
c608d16
added tasks for mapping to ModelMetadata.Description in MVC3
h0lg Apr 25, 2011
c9ad039
DisplayFormat is copied to ModelMetadata
h0lg Apr 25, 2011
2bdf8cb
EditorFormat is copied to ModelMetadata
h0lg Apr 25, 2011
f86ccd6
fixed mapping of DataTypeName to ModelMetadata
h0lg Apr 25, 2011
2b79b63
HideSurroundingHtml is copied to ModelMetadata
h0lg Apr 25, 2011
73d99ca
Readonly is copied to ModelMetadata
h0lg Apr 25, 2011
9cbcacf
refactored validation tests to use ComplexModel
h0lg Apr 25, 2011
bedb704
removed unneeded tests
h0lg Apr 25, 2011
bb2801a
Required is copied to ModelMetadata
h0lg Apr 25, 2011
09b0927
added test for ModelType being correct on ModelMetadata
h0lg Apr 25, 2011
d1fdd8a
NullDisplayText is copied to ModelMetadata
h0lg Apr 25, 2011
6280e94
ShowDisplay is copied to ModelMetadata
h0lg Apr 25, 2011
751a93a
ShowEditor is copied to ModelMetadata
h0lg Apr 25, 2011
147605d
TemplateHint is copied to ModelMetadata respecting HiddenInput as well
h0lg Apr 25, 2011
97ec385
added task for mapping ModelMetadata.Watermark in MVC3
h0lg Apr 25, 2011
1ec6f9e
removing lib from gitignore because library package's lib folders are…
h0lg Apr 4, 2011
12fabf8
updated FluentNHibernate from 1.0.0.593 to 1.2.0.712 and installed FN…
h0lg Jul 7, 2011
0fe119c
added PropertyMustMatchRegexRule & spec null value is valid
h0lg Jul 10, 2011
ed01a25
added PropertyMustMatchRegexRule Spec a value matching the pattern is…
h0lg Jul 11, 2011
876b82f
added PropertyMustMatchRegexRule Spec a value not matching the patter…
h0lg Jul 11, 2011
285d7d0
added PropertyMustMatchRegexRule Spec an empty string value is valid
h0lg Jul 11, 2011
b910fc2
added PropertyMustNotMatchRegexRule as negative of PropertyMustMatchR…
h0lg Jul 11, 2011
0fe9fa5
made Regex rules available in API via <property>.Should(.Not).MatchRe…
h0lg Jul 11, 2011
7c329f7
fixed build script requiring commit message to contain an 'm'
h0lg Jul 11, 2011
44d3e87
result of annoying visual studio project conversion
h0lg Jul 19, 2011
f02a836
refactored QueryFluentMetadata superficially & fixed typo in exceptio…
h0lg Jul 19, 2011
adca1d4
added FluentMetadata.FluentNHibernate.Specs project with first spec f…
h0lg Jul 19, 2011
94817c2
added spec for FluentMetaDataConvention ensuring it AppliesNullToNonR…
h0lg Jul 19, 2011
7fd9cb1
added spec for FluentMetaDataConvention ensuring it AppliesMaximumStr…
h0lg Jul 19, 2011
205b0da
added spec for FluentMetaDataConvention ensuring it DoesNotThrowAnExc…
h0lg Jul 19, 2011
54f6bb4
updated FluentNHibernate from 1.2.0.712 to 1.3.0.717
h0lg Aug 16, 2011
1ca0fc3
implemented IReferenceConvention on FluentMetaDataConvention
h0lg Aug 16, 2011
6f0a5b2
added ability to set localized display name (e.g. from resources) met…
h0lg Aug 19, 2011
b241c2e
added xunit projects fro Debug & Release configs
h0lg Aug 19, 2011
42b45bc
refactored regex rule
h0lg Sep 28, 2011
6778507
formatted for better readability
h0lg Sep 28, 2011
7c4544d
removed unused methods & ctors
h0lg Sep 28, 2011
55987b1
removed empty file
h0lg Sep 29, 2011
3c86700
formatted, removed using
h0lg Sep 29, 2011
7f65946
rewrote fluent interface for PropertyMustMatchRule
h0lg Sep 29, 2011
dbb423b
added a generic class rule and made it available in the fluent syntax…
h0lg Sep 29, 2011
b675c8c
added a generic property rule and made it available in the fluent syn…
h0lg Sep 29, 2011
71eb1d7
added PropertyMustBeLessThanOtherRule and made it available via Class…
h0lg Sep 29, 2011
a9f6d6a
initial commit of CopyAutoMappedMetadata feature
h0lg Apr 1, 2011
d53d786
added test for projected properties, for which AutoMapper does not pr…
h0lg Apr 1, 2011
5edc4c4
added support for flattened properties
h0lg Apr 1, 2011
fc74823
refactored MemberMap, used strings instead of MemberInfos which is no…
h0lg Apr 4, 2011
c4ac89c
added test for destination property resolved from a source property, …
h0lg Apr 4, 2011
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

*.user
*.obj
*.lib
*.suo
*.ncb
*.cache
*.gem
[Ll]ib
[Oo]bj
[Bb]in
[Bb]uild
Expand All @@ -14,4 +14,7 @@
_ReSharper*/
*.vs10x
Source/Gallio Reports
Source/TestResults
Source/TestResults
Source/_UpgradeReport_Files/
*.orig
Source/UpgradeLog*
10 changes: 10 additions & 0 deletions Source/Debug.xunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<xunit>
<assemblies>
<assembly filename="FluentMetadata.Core.Specs\bin\Debug\FluentMetadata.Core.Specs.dll" shadow-copy="true" />
<assembly filename="FluentMetadata.EntityFramework.Specs\bin\Debug\FluentMetadata.EntityFramework.Specs.dll" shadow-copy="true" />
<assembly filename="FluentMetadata.FluentNHibernate.Specs\bin\Debug\FluentMetadata.FluentNHibernate.Specs.dll" shadow-copy="true" />
<assembly filename="FluentMetadata.MVC.Specs\bin\Debug\FluentMetadata.MVC.Specs.dll" shadow-copy="true" />
<assembly filename="FluentMetadata.AutoMapper.Specs\bin\Debug\FluentMetadata.AutoMapper.Specs.dll" shadow-copy="true" />
</assemblies>
</xunit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{36BC8904-D8F8-4778-A5BB-F27F1346BAE9}</ProjectGuid>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FluentMetadata.AutoMapper.Specs</RootNamespace>
<AssemblyName>FluentMetadata.AutoMapper.Specs</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper">
<HintPath>..\packages\AutoMapper.1.1.0.118\lib\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="xunit, Version=1.6.0.1516, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\external\xUnit\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SystemUnderTest.cs" />
<Compile Include="When_copying_metadata_from_an_AutoMapped_Type.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FluentMetadata.AutoMapper\FluentMetadata.AutoMapper.csproj">
<Project>{3EA6A0AC-8377-4C2F-A0EA-61278245620E}</Project>
<Name>FluentMetadata.AutoMapper</Name>
</ProjectReference>
<ProjectReference Include="..\FluentMetadata.Core\FluentMetadata.Core.csproj">
<Project>{C73F37FA-D859-4714-8335-35069322176A}</Project>
<Name>FluentMetadata.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
35 changes: 35 additions & 0 deletions Source/FluentMetadata.AutoMapper.Specs/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("FluentMetadata.AutoMapper.Specs")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("FluentMetadata.AutoMapper.Specs")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("10e83014-1379-41a6-821d-50d5a1317676")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
64 changes: 64 additions & 0 deletions Source/FluentMetadata.AutoMapper.Specs/SystemUnderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using AutoMapper;
namespace FluentMetadata.AutoMapper.Specs
{
class Source
{
public string MyProperty { get; set; }
public int Named { get; set; }
public Nested Nested { get; set; }
public string StringField { get; set; }
}

class Nested
{
public FurtherNested FurtherNested { get; set; }
}

class FurtherNested
{
public int Id { get; set; }
}

class Destination
{
public string MyProperty { get; set; }
public int Renamed { get; set; }
public int NestedFurtherNestedId { get; set; }
public int IntProperty { get; set; }
}

class FakeResolver : ValueResolver<string, int>
{
protected override int ResolveCore(string source)
{
return default(int);
}
}

class SourceMetaData : ClassMetadata<Source>
{
public SourceMetaData()
{
Class.Display.Name("rzjsfghgafsdfh");
Property(x => x.MyProperty).Display.Name("pockänsdfsdf");
Property(x => x.Named).Description("adföoiulkanhsda");
Property(x => x.StringField).UIHint("üoicvnqwnb");
}
}

class FurtherNestedMetaData : ClassMetadata<FurtherNested>
{
public FurtherNestedMetaData()
{
Property(x => x.Id).Is.Required();
}
}

class TargetMetaData : ClassMetadata<Destination>
{
public TargetMetaData()
{
this.CopyAutoMappedMetadataFrom(typeof(Source));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Linq;
using AutoMapper;
using Xunit;

namespace FluentMetadata.AutoMapper.Specs
{
public class When_copying_metadata_from_an_AutoMapped_Type : IDisposable
{
Metadata destinationMetadata,
destinationMyPropertyMetadata,
destinationRenamedMetadata,
destinationNestedFurtherNestedIdMetadata,
destinationIntPropertyMetadata;

public When_copying_metadata_from_an_AutoMapped_Type()
{
Mapper.CreateMap<Source, Destination>()
.ForMember(d => d.Renamed, o => o.MapFrom(s => s.Named))
.ForMember(d => d.IntProperty, o => o.ResolveUsing<FakeResolver>().FromMember(s => s.StringField));
Mapper.AssertConfigurationIsValid();

FluentMetadataBuilder.ForAssemblyOfType<Source>();

var query = new QueryFluentMetadata();
destinationMetadata = query.GetMetadataFor(typeof(Destination));
destinationMyPropertyMetadata = destinationMetadata.Properties
.Single(m => m.ModelName == "MyProperty");
destinationRenamedMetadata = destinationMetadata.Properties
.Single(m => m.ModelName == "Renamed");
destinationNestedFurtherNestedIdMetadata = destinationMetadata.Properties
.Single(m => m.ModelName == "NestedFurtherNestedId");
destinationIntPropertyMetadata = destinationMetadata.Properties
.Single(m => m.ModelName == "IntProperty");
}

[Fact]
public void a_destination_property_should_have_metadata_from_the_source_property_it_is_mapped_to()
{
Assert.Equal("pockänsdfsdf", destinationMyPropertyMetadata.GetDisplayName());
}

[Fact]
public void the_destination_type_should_have_metadata_from_the_source_type_it_is_mapped_to()
{
Assert.Equal("rzjsfghgafsdfh", destinationMetadata.GetDisplayName());
}

//TODO [on AutoMapper update] check if AutoMapper makes projected source property accessible
[Fact(Skip = "unsupported until AutoMapper makes projected source property accessible")]
public void a_projected_destination_property_should_have_metadata_from_the_source_property_it_is_mapped_to()
{
Assert.Equal("adföoiulkanhsda", destinationRenamedMetadata.Description);
}

[Fact]
public void a_flattened_destination_property_should_have_metadata_from_the_source_property_it_is_mapped_to()
{
Assert.Equal(true, destinationNestedFurtherNestedIdMetadata.Required);
}

//TODO [on AutoMapper update] check if AutoMapper makes source property that destination property is resolved from accessible
[Fact(Skip = "unsupported until AutoMapper makes the source property the destination property is resolved from accessible")]
public void a_destination_property_resolved_from_a_source_property_should_have_metadata_from_the_source_property()
{
Assert.Equal("üoicvnqwnb", destinationIntPropertyMetadata.TemplateHint);
}

public void Dispose()
{
FluentMetadataBuilder.Reset();
Mapper.Reset();
}
}
}
4 changes: 4 additions & 0 deletions Source/FluentMetadata.AutoMapper.Specs/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="1.1.0.118" />
</packages>
61 changes: 61 additions & 0 deletions Source/FluentMetadata.AutoMapper/AutoMapperHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using AutoMapper;

namespace FluentMetadata.AutoMapper
{
internal class AutoMapperHelper
{
/// <summary>
/// Gets the mapped members for a source/destination type pair.
/// </summary>
/// <param name="source">The source Type.</param>
/// <param name="destination">The destination Type.</param>
/// <returns></returns>
internal static IEnumerable<MemberMap> GetMemberMapsOf(Type source, Type destination)
{
var maps = new Collection<MemberMap>();

foreach (var propertyMap in GetRelevantMappedMembersOf(source, destination))
{
// get the source property of the PropertyMap
var sourceValueResolvers = propertyMap.GetSourceValueResolvers()
// just plain property maps, there's no interesting metadata on a custom mapping function
.OfType<IMemberGetter>();
var sourceProperty = sourceValueResolvers
// "There can be only one"
.SingleOrDefault(svr => svr.MemberType == propertyMap.DestinationProperty.MemberType);

if (sourceProperty != null)
{
maps.Add(new MemberMap
{
SourceName = sourceValueResolvers.Aggregate(string.Empty, (result, svr) => result + svr.Name),
DestinationName = propertyMap.DestinationProperty.Name
});
}
}

return maps;
}

/// <summary>
/// Gets the mapped members for a source/destination type pair
/// leaving out mapped members that are irrelevant.
/// </summary>
/// <param name="source">The source type.</param>
/// <param name="destination">The destination type.</param>
/// <returns></returns>
static IEnumerable<PropertyMap> GetRelevantMappedMembersOf(Type source, Type destination)
{
var typeMap = Mapper.FindTypeMapFor(source, destination);
return
typeMap != null ?
// filter by non-ignored PropertyMaps
typeMap.GetPropertyMaps().Where(m => m.IsIgnored() == false) :
Enumerable.Empty<PropertyMap>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;

namespace FluentMetadata.AutoMapper
{
/// <summary>
/// AutoMapper extensions to <see cref="FluentMetadata.ClassMetadata<T>"/>
/// </summary>
public static class ClassMetadataAutoMapperExtensions
{
/// <summary>
/// Copies the the source type's metadata to the destination type's metadata
/// using the mapping information provided by AutoMapper.
/// </summary>
/// <typeparam name="TDestination">The type of the destination.</typeparam>
/// <param name="to">The destination metadata.</param>
/// <param name="from">The source type.</param>
public static void CopyAutoMappedMetadataFrom<TDestination>(this ClassMetadata<TDestination> to, Type from)
{
var destinationType = typeof(TDestination);
MetadataHelper.CopyMappedMetadata(
from,
destinationType,
AutoMapperHelper.GetMemberMapsOf(from, destinationType)
);
}
}
}
Loading