Changeset 429

Show
Ignore:
Timestamp:
02/09/10 00:27:11 (6 months ago)
Author:
serialseb
Message:

Merging RC changes

Location:
trunk/src/core
Files:
4 removed
80 modified
34 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/core/OpenRasta

  • trunk/src/core/OpenRasta.Client

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/src/core/OpenRasta.Net30

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/src/core/OpenRasta.Net35

  • trunk/src/core/OpenRasta.Testing

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/src/core/OpenRasta.Tests.Integration

  • trunk/src/core/OpenRasta.Tests.Integration/OpenRasta.Tests.Integration.csproj

    r421 r429  
    6363      <Link>Properties\CommonInfo.cs</Link> 
    6464    </Compile> 
     65    <Compile Include="Binding\CustomSurrogates.cs" /> 
    6566    <Compile Include="Regressions\92.cs" /> 
    6667    <Compile Include="Codecs\HtmlForm_Specification.cs" /> 
     
    9091    </ProjectReference> 
    9192  </ItemGroup> 
    92   <ItemGroup> 
    93     <Folder Include="Binding\" /> 
    94   </ItemGroup> 
    9593  <Import Project="..\..\..\build\defaults.targets" /> 
    9694  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 
  • trunk/src/core/OpenRasta.Tests.Integration/Security/DigestAuthentication_Specification.cs

    r420 r429  
    1212namespace DigestAuthentication_Specification 
    1313{ 
    14     public class when_using_the_correct_credentials : server_context 
     14    public class when_using_the_correct_credentials : context.http_digest_context 
    1515    { 
    1616        public when_using_the_correct_credentials() 
     
    4040 
    4141        [Test] 
    42         public void an_unprotected_resource_returns_200_even_with_invalid_credentials() 
    43         { 
    44             given_client_credentials("username", "wrongpassword"); 
    45             given_request("GET", "/unprotected"); 
    46  
    47             when_reading_response_as_a_string(Encoding.ASCII); 
    48  
    49             TheResponse.StatusCode.ShouldBe(HttpStatusCode.OK); 
    50         } 
    51  
    52         [Test] 
    5342        public void the_user_authentication_is_successfull_on_URIs_with_encoded_characters() 
    5443        { 
     
    7059        } 
    7160    } 
     61    public class when_using_incorrect_credentials : context.http_digest_context 
     62    { 
     63        [Test] 
     64        public void a_request_for_a_protected_resource_fails_with_401_response() 
     65        { 
     66            given_client_credentials("username", "wrongpassword"); 
     67            given_request("GET", "/home"); 
    7268 
     69            when_reading_response(); 
     70 
     71            TheResponse.StatusCode.ShouldBe(HttpStatusCode.Unauthorized); 
     72 
     73            when_reading_response(); 
     74 
     75            TheResponse.StatusCode.ShouldBe(HttpStatusCode.Unauthorized); 
     76        } 
     77        [Test] 
     78        public void an_unprotected_resource_returns_200_even_with_invalid_credentials() 
     79        { 
     80            given_client_credentials("username", "wrongpassword"); 
     81            given_request("GET", "/unprotected"); 
     82 
     83            when_reading_response_as_a_string(Encoding.ASCII); 
     84 
     85            TheResponse.StatusCode.ShouldBe(HttpStatusCode.OK); 
     86        } 
     87 
     88    } 
     89    namespace context 
     90    { 
     91        public class http_digest_context : server_context 
     92        { 
     93 
     94            public http_digest_context() 
     95        { 
     96            ConfigureServer(() => 
     97            { 
     98                DependencyManager.GetService<IDependencyResolver>() 
     99                    .AddDependency<IAuthenticationProvider, FakeAuthProvider>(); 
     100 
     101                ResourceSpace.Has.ResourcesOfType<Customer>() 
     102                    .AtUri("/{somewhere}") 
     103                    .AndAt("/unprotected").Named("unprotected") 
     104                    .HandledBy<ProtectedCustomerHandler>(); 
     105            }); 
     106        } 
     107        } 
     108    } 
    73109    public class FakeAuthProvider : IAuthenticationProvider 
    74110    { 
    75         public Credentials GetByUsername(string p) 
     111        public Credentials GetByUsername(string username) 
    76112        { 
    77             return new Credentials { Username = p, Password = "password" }; 
     113            return new Credentials { Username = username, Password = "password" }; 
    78114        } 
    79115    } 
    80  
     116     
    81117    public class ProtectedCustomerHandler 
    82118    { 
  • trunk/src/core/OpenRasta.Tests.Unit

  • trunk/src/core/OpenRasta.Tests.Unit/Binding/DefaultBinderLocator_Specification.cs

    r314 r429  
    1818        public void the_binder_is_created_correctly() 
    1919        { 
    20             var type = new ReflectionBasedTypeSystem().FromClr(typeof(ClassWithStaticBinder)); 
     20            var type = TypeSystems.Default.FromClr(typeof(ClassWithStaticBinder)); 
    2121            var binderLocator = new DefaultObjectBinderLocator(); 
    2222 
  • trunk/src/core/OpenRasta.Tests.Unit/Binding/KeyedValuesBinder_Specification.cs

    r414 r429  
    123123        } 
    124124        [Test] 
     125        public void multiple_values_with_the_same_name_for_an_icollection_appends_to_the_collection() 
     126        { 
     127            var binder = new KeyedValuesBinder(TypeOf<Customer>(), "firstname"); 
     128            ValueConverter<string> valueConverter = (str, type) => BindingResult.Success(type.CreateInstanceFrom(str)); 
     129            binder.SetProperty("Attributes", new[] { "blue eyes" }, valueConverter) 
     130                .ShouldBeTrue(); 
     131            binder.SetProperty("Attributes", new[] { "green eyes" }, valueConverter) 
     132                .ShouldBeTrue(); 
     133 
     134            var customer = binder.BuildObject().Instance as Customer; 
     135            customer.Attributes.Count().ShouldBe(2); 
     136            customer.Attributes.First().ShouldBe("blue eyes"); 
     137            customer.Attributes.Skip(1).First().ShouldBe("green eyes"); 
     138        } 
     139 [Test] 
    125140        public void can_build_nested_dictionaries() 
    126141        { 
     
    137152        protected IType TypeOf<T>() 
    138153        { 
    139             return new ReflectionBasedTypeSystem().FromClr(typeof(T)); 
     154            return TypeSystems.Default.FromClr(typeof(T)); 
    140155        } 
    141156    } 
  • trunk/src/core/OpenRasta.Tests.Unit/Codecs/ApplicationXWwwUrlformEncodedCodec_Specification.cs

    r369 r429  
    161161                    .ShouldBe("John"); 
    162162            customer.LastName 
    163                     .ShouldBe("Doe"); 
     163                      .ShouldBe("Doe"); 
    164164 
    165165            customer.DateOfBirth.Day 
    166166                    .ShouldBe(10); 
     167        } 
     168        [Test] 
     169        public void indexers_are_supported_when_encoded() 
     170        { 
     171            given_context(); 
     172            given_request_stream("Customer.Attributes%3A1=blue&Customer.Attributes%3A2=red"); 
     173 
     174            when_decoding<Customer>(); 
     175 
     176            then_decoding_result<Customer>() 
     177                .Attributes.Count().ShouldBe(2); 
    167178        } 
    168179 
     
    183194        public string FirstName { get; set; } 
    184195        public string LastName { get; set; } 
     196        public IEnumerable<string> Attributes { get; set; } 
    185197        public DateTime DateOfBirth { get; set; } 
    186198        public Address Address { get; set; } 
  • trunk/src/core/OpenRasta.Tests.Unit/Codecs/CodecMatch_Specification.cs

    r314 r429  
    6969                    new CodecRegistration( 
    7070                        typeof (string),  
    71                         new ReflectionBasedTypeSystem().FromClr(typeof (object)), new MediaType(mediaType)), score, matchingParameters); 
     71                        TypeSystems.Default.FromClr(typeof (object)), new MediaType(mediaType)), score, matchingParameters); 
    7272        } 
    7373    } 
  • trunk/src/core/OpenRasta.Tests.Unit/Codecs/CodecRepository_Specification.cs

    r348 r429  
    152152    public class when_searching_for_content_type_writers_for_a_media_type : codec_repository_context 
    153153    { 
    154         readonly ITypeSystem typeSystem = new ReflectionBasedTypeSystem(); 
     154        readonly ITypeSystem typeSystem = TypeSystems.Default; 
    155155        new IList<CodecRegistration> ThenTheResult; 
    156156 
     
    264264        public CodecRegistration ThenTheResult; 
    265265        public CodecMatch ThenTheResultScoring; 
    266         public ITypeSystem TypeSystem = new ReflectionBasedTypeSystem(); 
     266        public ITypeSystem TypeSystem = TypeSystems.Default; 
    267267 
    268268        [SetUp] 
     
    286286                Codecs.Add(CodecRegistration.FromResourceType(resourceType, 
    287287                                                         typeof(TCodec), 
    288                                                          new ReflectionBasedTypeSystem(), 
     288                                                         TypeSystems.Default, 
    289289                                                         mediaType, 
    290290                                                         null, 
  • trunk/src/core/OpenRasta.Tests.Unit/Codecs/MultipartFormDataCodec_Specification.cs

    r426 r429  
    303303                                                    DependencyManager.Codecs, 
    304304                                                    DependencyManager.GetService<IDependencyResolver>(), 
    305                                                     new ReflectionBasedTypeSystem(), 
     305                                                    TypeSystems.Default, 
    306306                                                    new DefaultObjectBinderLocator()); 
    307307        } 
  • trunk/src/core/OpenRasta.Tests.Unit/Codecs/media_type_reader_context.cs

    r369 r429  
    7979            var codec = codecInstance as IMediaTypeReader; 
    8080            if (codec != null) 
    81                 _theResult = codec.ReadFrom(Context.Request.Entity, new ReflectionBasedTypeSystem().FromClr(typeof(T)), paramName); 
     81                _theResult = codec.ReadFrom(Context.Request.Entity,TypeSystems.Default.FromClr(typeof(T)), paramName); 
    8282            else 
    8383            { 
  • trunk/src/core/OpenRasta.Tests.Unit/Configuration/LegacyManualConfiguration_Specification.cs

    r420 r429  
    3333            match.ShouldNotBeNull(); 
    3434            match.UriCulture.ShouldBe(language); 
    35             match.ResourceKey.ShouldBe(new ReflectionBasedTypeSystem().FromClr(typeof(TResource))); 
     35            match.ResourceKey.ShouldBe(TypeSystems.Default.FromClr(typeof(TResource))); 
    3636            match.UriName.ShouldBe(name); 
    3737        } 
     
    7777        { 
    7878            return 
    79                 DependencyManager.Codecs.Where(codec => codec.ResourceType.CompareTo(new ReflectionBasedTypeSystem().FromClr(typeof (TResource)))==0 && codec.CodecType == typeof (TCodec) && codec.MediaType.MediaType == mediaType). 
     79                DependencyManager.Codecs.Where(codec => codec.ResourceType.CompareTo(TypeSystems.Default.FromClr(typeof (TResource)))==0 && codec.CodecType == typeof (TCodec) && codec.MediaType.MediaType == mediaType). 
    8080                    Distinct().SingleOrDefault(); 
    8181        } 
     
    179179            var handlerMatch = DependencyManager.Handlers.GetHandlerTypesFor(urimatch.ResourceKey).FirstOrDefault(); 
    180180            handlerMatch.ShouldNotBeNull(); 
    181             handlerMatch.ShouldBe(new ReflectionBasedTypeSystem().FromClr(typeof(THandler))); 
     181            handlerMatch.ShouldBe(TypeSystems.Default.FromClr(typeof(THandler))); 
    182182            return handlerMatch; 
    183183        } 
  • trunk/src/core/OpenRasta.Tests.Unit/Configuration/MetaModelHandler_Specification.cs

    r362 r429  
    136136 
    137137            Handler.Process(MetaModel); 
    138             var typeSystem = new ReflectionBasedTypeSystem().FromClr(typeof(Customer)); 
     138            var typeSystem = TypeSystems.Default.FromClr(typeof(Customer)); 
    139139            var registeredHandlers = HandlerRepository.GetHandlerTypesFor(typeSystem); 
    140140 
     
    146146        void given_handler_registration() 
    147147        { 
    148             var typeSystem = new ReflectionBasedTypeSystem(); 
     148            var typeSystem = TypeSystems.Default; 
    149149            MetaModel.ResourceRegistrations.Add(new ResourceModel 
    150150            { 
     
    160160    public class when_registering_non_IType_resource_keys : metamodelhandler_context<TypeRewriterMetaModelHandler> 
    161161    { 
    162         ReflectionBasedTypeSystem TypeSystem; 
    163  
    164         protected override void SetUp() 
    165         { 
    166             base.SetUp(); 
    167             TypeSystem = new ReflectionBasedTypeSystem(); 
     162        ITypeSystem TypeSystem; 
     163 
     164        protected override void SetUp() 
     165        { 
     166            base.SetUp(); 
     167            TypeSystem = TypeSystems.Default; 
    168168            Handler = new TypeRewriterMetaModelHandler(TypeSystem); 
    169169        } 
     
    238238        void given_unknown_type_registered_as_codec() 
    239239        { 
    240             var typeSystem = new ReflectionBasedTypeSystem(); 
     240            var typeSystem = TypeSystems.Default; 
    241241            MetaModel.ResourceRegistrations.Add(new ResourceModel 
    242242            { 
     
    251251        void given_codec_registration() 
    252252        { 
    253             var typeSystem = new ReflectionBasedTypeSystem(); 
     253            var typeSystem = TypeSystems.Default; 
    254254            MetaModel.ResourceRegistrations.Add(new ResourceModel 
    255255            { 
  • trunk/src/core/OpenRasta.Tests.Unit/Configuration/MetaModel_Specification.cs

    r381 r429  
    8989        public void a_resource_with_IType_is_registered() 
    9090        { 
    91             ResourceSpaceHas.ResourcesOfType(new ReflectionBasedTypeSystem().FromClr(typeof(Customer))); 
     91            ResourceSpaceHas.ResourcesOfType(TypeSystems.Default.FromClr(typeof(Customer))); 
    9292 
    9393            MetaModel.ResourceRegistrations[0].ResourceKey.ShouldBeOfType<IType>().Name.ShouldBe("Customer"); 
     
    209209        { 
    210210            ResourceSpaceHas.ResourcesOfType(typeof(Frodo)).AtUri("/theshrine") 
    211                 .HandledBy(new ReflectionBasedTypeSystem().FromClr(typeof(CustomerHandler))); 
     211                .HandledBy(TypeSystems.Default.FromClr(typeof(CustomerHandler))); 
    212212            FirstRegistration.Handlers[0].Name.ShouldBe("CustomerHandler"); 
    213213        } 
  • trunk/src/core/OpenRasta.Tests.Unit/Fakes/Customer.cs

    r300 r429  
    2525    { 
    2626        public List<Order> Orders { get; set; } 
     27        public ICollection<string> Attributes { get; set; } 
    2728    } 
    2829 
  • trunk/src/core/OpenRasta.Tests.Unit/OpenRasta.Tests.Unit.csproj

    r426 r429  
    121121    <Compile Include="TypeSystem\PropertyPathManager_Specification.cs" /> 
    122122    <Compile Include="TypeSystem\ReflectionExtensions_Specification.cs" /> 
     123    <Compile Include="TypeSystem\Surrogate2_Specification.cs" /> 
    123124    <Compile Include="TypeSystem\Surrogates_Specification.cs" /> 
    124125    <Compile Include="Text\Rfc2047Encoding_Specification.cs" /> 
  • trunk/src/core/OpenRasta.Tests.Unit/OperationModel/CodecSelectors/RequestCodecSelector_Specification.cs

    r317 r429  
    44using System.Runtime.InteropServices; 
    55using NUnit.Framework; 
     6using OpenRasta.Binding; 
    67using OpenRasta.Codecs; 
    78using OpenRasta.OperationModel; 
     
    910using OpenRasta.OperationModel.Hydrators; 
    1011using OpenRasta.Testing; 
     12using OpenRasta.Tests.Unit.Fakes; 
    1113using OpenRasta.Tests.Unit.OperationModel.Filters; 
    1214using OpenRasta.Web; 
     
    7678            FilteredOperations.First(x => x.Name == "Get").GetRequestCodec().ShouldBeNull();    
    7779        } 
     80        [Test] 
     81        public void operations_with_partially_filled_members_still_get_codec_assigned() 
     82        { 
     83            given_filter(); 
     84            given_operations(); 
     85            given_request_header_content_type(MediaType.ApplicationXWwwFormUrlencoded); 
     86 
     87            given_registration_codec<ApplicationXWwwFormUrlencodedKeyedValuesCodec>(); 
     88            given_request_entity_body("firstname=Frodo"); 
     89 
     90            given_operation_property(x => x.Name == "GetFrodo", "lastname", "baggins"); 
     91 
     92            when_filtering_operations(); 
     93 
     94            FilteredOperations.First(x => x.Name == "GetFrodo").GetRequestCodec() 
     95                .ShouldNotBeNull() 
     96                .CodecRegistration.CodecType 
     97                    .ShouldBe<ApplicationXWwwFormUrlencodedKeyedValuesCodec>(); 
     98        } 
     99 
     100        void given_operation_property(Func<IOperation, bool> predicate, string propertyName, string propertyValue) 
     101        { 
     102            Operations.First(predicate).Inputs.First().Binder.SetProperty( 
     103                propertyName,  
     104                new object[]{propertyValue}, 
     105                (v,t)=>BindingResult.Success(v)); 
     106        } 
    78107    } 
    79108    public class when_a_codec_is_not_found : requestcodecselector_context 
     
    117146        } 
    118147        public void GetWithOptionalValue([Optional]int optionalIndex){} 
     148 
     149        public void GetFrodo(Frodo frodo) 
     150        { 
     151             
     152        } 
    119153    } 
    120154} 
  • trunk/src/core/OpenRasta.Tests.Unit/Settings.StyleCop

    r300 r429  
    5353          </RuleSettings> 
    5454        </Rule> 
    55         <Rule Name="ElementsMustBeSeparatedByBlankLine"> 
    56           <RuleSettings> 
    57             <BooleanProperty Name="Enabled">False</BooleanProperty> 
    58           </RuleSettings> 
    59         </Rule> 
    6055      </Rules> 
    6156      <AnalyzerSettings /> 
     
    163158          </RuleSettings> 
    164159        </Rule> 
    165         <Rule Name="FieldNamesMustNotContainUnderscore"> 
    166           <RuleSettings> 
    167             <BooleanProperty Name="Enabled">False</BooleanProperty> 
    168           </RuleSettings> 
    169         </Rule> 
    170160      </Rules> 
    171161      <AnalyzerSettings /> 
     
    278268          </RuleSettings> 
    279269        </Rule> 
    280         <Rule Name="SplitParametersMustStartOnLineAfterDeclaration"> 
    281           <RuleSettings> 
    282             <BooleanProperty Name="Enabled">False</BooleanProperty> 
    283           </RuleSettings> 
    284         </Rule> 
    285270        <Rule Name="ParametersMustBeOnSameLineOrSeparateLines"> 
    286           <RuleSettings> 
    287             <BooleanProperty Name="Enabled">False</BooleanProperty> 
    288           </RuleSettings> 
    289         </Rule> 
    290         <Rule Name="ParameterMustNotSpanMultipleLines"> 
    291271          <RuleSettings> 
    292272            <BooleanProperty Name="Enabled">False</BooleanProperty> 
  • trunk/src/core/OpenRasta.Tests.Unit/TypeSystem/Instances_Specification.cs

    r314 r429  
    1616using OpenRasta.Testing; 
    1717using OpenRasta.Tests.Unit.Fakes; 
     18 
    1819using OpenRasta.TypeSystem; 
    1920using OpenRasta.TypeSystem.ReflectionBased; 
     21using Frodo=OpenRasta.Tests.Unit.Fakes.Frodo; 
    2022 
    2123namespace Instances_Specification 
     
    2628        public void cannot_assign_properties_to_a_null_object() 
    2729        { 
    28             GivenTypeInstance<Customer>(); 
    29  
    30             Executing(() => ThenTypeBuilder.Apply(null)).ShouldThrow<ArgumentNullException>(); 
     30            given_builder_for<Customer>(); 
     31 
     32            Executing(() => TypeBuilder.Update(null)).ShouldThrow<ArgumentNullException>(); 
    3133        } 
    3234 
     
    3436        public void the_properties_are_assigned() 
    3537        { 
    36             GivenTypeInstance<Customer>(); 
    37             GivenProperty("username", "johndoe"); 
     38            given_builder_for<Customer>(); 
     39            given_property("username", "johndoe"); 
    3840 
    3941            var newCustomer = new Customer {FirstName = "John"}; 
    4042 
    41             ThenTypeBuilder.Apply(newCustomer); 
     43            TypeBuilder.Update(newCustomer); 
    4244 
    4345            newCustomer.Username.ShouldBe("johndoe"); 
    4446            newCustomer.FirstName.ShouldBe("John"); 
    4547 
    46             GivenProperty("lastname", "doe"); 
     48            given_property("lastname", "doe"); 
    4749            newCustomer = new Customer {FirstName = "John"}; 
    48             ThenTypeBuilder.Apply(newCustomer); 
     50            TypeBuilder.Update(newCustomer); 
    4951 
    5052            newCustomer.Username.ShouldBe("johndoe"); 
     
    5961        public void a_property_retrieved_twice_retrieves_the_same_object() 
    6062        { 
    61             GivenTypeInstance<string>(); 
    62  
    63             ThenTypeBuilder.GetProperty("Length").ShouldBeTheSameInstanceAs(ThenTypeBuilder.GetProperty("Length")); 
     63            given_builder_for<string>(); 
     64 
     65            TypeBuilder.GetProperty("Length").ShouldBeTheSameInstanceAs(TypeBuilder.GetProperty("Length")); 
    6466        } 
    6567 
     
    6769        public void a_readonly_property_is_returned_as_non_writable() 
    6870        { 
    69             GivenTypeInstance<string>(); 
    70  
    71             ThenTypeBuilder.GetProperty("Length").CanWrite.ShouldBeFalse(); 
     71            given_builder_for<string>(); 
     72 
     73            TypeBuilder.GetProperty("Length").CanWrite.ShouldBeFalse(); 
    7274        } 
    7375 
     
    7577        public void an_unknown_property_returns_null() 
    7678        { 
    77             GivenTypeInstance<string>(); 
    78  
    79             ThenTypeBuilder.GetProperty("unknown").ShouldBeNull(); 
     79            given_builder_for<string>(); 
     80 
     81            TypeBuilder.GetProperty("unknown").ShouldBeNull(); 
    8082        } 
    8183    } 
     
    8688        public void a_property_retrieved_but_wihtout_a_value_is_not_present_in_the_changes() 
    8789        { 
    88             GivenTypeInstance<Customer>(); 
    89  
    90             ThenTypeBuilder.GetProperty("FirstName") 
     90            given_builder_for<Customer>(); 
     91 
     92            TypeBuilder.GetProperty("FirstName") 
    9193                .TrySetValue(2).ShouldBeFalse(); 
    9294 
    93             ThenTypeBuilder.Changes.Count.ShouldBe(0); 
     95            TypeBuilder.Changes.Count.ShouldBe(0); 
    9496        } 
    9597 
     
    9799        public void a_successfully_assigned_property_is_present_in_the_list_of_changes() 
    98100        { 
    99             GivenTypeInstance<Customer>(); 
    100  
    101             ThenTypeBuilder.GetProperty("FirstName").TrySetValue("Frodo"); 
    102  
    103             ThenTypeBuilder.Changes.Count.ShouldBe(1); 
    104             ThenTypeBuilder.Changes.ContainsKey("FirstName").ShouldBeTrue(); 
     101            given_builder_for<Customer>(); 
     102 
     103            TypeBuilder.GetProperty("FirstName").TrySetValue("Frodo"); 
     104 
     105            TypeBuilder.Changes.Count.ShouldBe(1); 
     106            TypeBuilder.Changes.ContainsKey("FirstName").ShouldBeTrue(); 
    105107        } 
    106108 
     
    108110        public void accessing_the_indexer_with_an_unknown_key_throws() 
    109111        { 
    110             GivenTypeInstance<Customer>(); 
    111             Executing(() => { IPropertyBuilder value = ThenTypeBuilder.Changes["firstname"]; }) 
     112            given_builder_for<Customer>(); 
     113            Executing(() => { IPropertyBuilder value = TypeBuilder.Changes["firstname"]; }) 
    112114                .ShouldThrow<ArgumentOutOfRangeException>(); 
    113115        } 
     
    116118        public void the_change_list_is_readonly() 
    117119        { 
    118             GivenTypeInstance<Customer>(); 
    119  
    120             ThenTypeBuilder.Changes.IsReadOnly.ShouldBeTrue(); 
    121             Executing(() => ThenTypeBuilder.Changes.Add(null, null)) 
     120            given_builder_for<Customer>(); 
     121 
     122            TypeBuilder.Changes.IsReadOnly.ShouldBeTrue(); 
     123            Executing(() => TypeBuilder.Changes.Add(null, null)) 
    122124                .ShouldThrow<NotSupportedException>(); 
    123125 
    124             Executing(() => ThenTypeBuilder.Changes.Remove(null)) 
     126            Executing(() => TypeBuilder.Changes.Remove(null)) 
    125127                .ShouldThrow<NotSupportedException>(); 
    126128 
    127             Executing(() => ThenTypeBuilder.Changes["bla"] = null) 
     129            Executing(() => TypeBuilder.Changes["bla"] = null) 
    128130                .ShouldThrow<NotSupportedException>(); 
    129131        } 
     
    132134        public void the_keys_are_case_insensitive() 
    133135        { 
    134             GivenTypeInstance<Customer>(); 
    135             ThenTypeBuilder.GetProperty("FirstName") 
     136            given_builder_for<Customer>(); 
     137            TypeBuilder.GetProperty("FirstName") 
    136138                .TrySetValue("Frodo"); 
    137             ThenTypeBuilder.Changes["firstname"].Value.ShouldBe("Frodo"); 
     139            TypeBuilder.Changes["firstname"].Value.ShouldBe("Frodo"); 
    138140        } 
    139141    } 
     
    144146        public void a_property_is_not_set_when_the_type_is_incompatible() 
    145147        { 
    146             GivenTypeInstance<Customer>(); 
    147  
    148             ThenTypeBuilder.GetProperty("Username").TrySetValue(3).ShouldBeFalse(); 
     148            given_builder_for<Customer>(); 
     149 
     150            TypeBuilder.GetProperty("Username").TrySetValue(3).ShouldBeFalse(); 
    149151        } 
    150152 
     
    152154        public void a_writable_property_is_set_and_its_value_can_be_retrieved() 
    153155        { 
    154             GivenTypeInstance<Customer>(); 
    155  
    156             ThenTypeBuilder.GetProperty("Username").TrySetValue("hello") 
     156            given_builder_for<Customer>(); 
     157 
     158            TypeBuilder.GetProperty("Username").TrySetValue("hello") 
    157159                .ShouldBeTrue(); 
    158160 
    159             ThenTypeBuilder.GetProperty("Username") 
     161            TypeBuilder.GetProperty("Username") 
    160162                .Value.ShouldBe("hello"); 
    161163        } 
     
    172174        public void a_new_instance_is_created_when_using_create() 
    173175        { 
    174             GivenTypeInstance<Customer>(); 
    175             Customer customer = ThenTypeBuilder.Create().ShouldBeOfType<Customer>().ShouldNotBeNull(); 
    176  
    177             ThenTypeBuilder.GetProperty("FirstName").TrySetValue("Frodo") 
     176            given_builder_for<Customer>(); 
     177            Customer customer = TypeBuilder.Create().ShouldBeOfType<Customer>().ShouldNotBeNull(); 
     178 
     179            TypeBuilder.GetProperty("FirstName").TrySetValue("Frodo") 
    178180                .ShouldBeTrue(); 
    179181 
    180182            customer.LastName = "Baggins"; 
    181             customer = ThenTypeBuilder.Create() as Customer; 
     183            customer = TypeBuilder.Create() as Customer; 
    182184 
    183185            customer.FirstName.ShouldBe("Frodo"); 
     
    188190        public void assigning_properties_after_the_property_got_assigned_a_parent_updates_the_parent() 
    189191        { 
    190             GivenTypeInstance<Customer>(); 
     192            given_builder_for<Customer>(); 
     193 
    191194            var customerInstance = new Customer(); 
    192             ThenTypeBuilder.TrySetValue(customerInstance); 
    193  
    194             IPropertyBuilder firstName = ThenTypeBuilder.GetProperty("FirstName"); 
    195             firstName.SetOwner(ThenTypeBuilder); 
     195            TypeBuilder.TrySetValue(customerInstance); 
     196 
     197            IPropertyBuilder firstName = TypeBuilder.GetProperty("FirstName"); 
     198            //firstName.SetOwner(TypeBuilder); 
    196199 
    197200            firstName.TrySetValue(new[] {"Smeagol"}, IdentityConverter); 
    198201 
     202            TypeBuilder.Update(customerInstance); 
    199203            customerInstance.FirstName.ShouldBe("Smeagol"); 
    200204        } 
    201205 
    202206        [Test] 
    203         public void cannot_assign_a_null_parent_to_a_property() 
    204         { 
    205             GivenTypeInstance<Customer>(); 
    206             Executing(() => ThenTypeBuilder.GetProperty("FirstName").SetOwner(null)) 
    207                 .ShouldThrow<ArgumentNullException>(); 
    208         } 
    209  
    210         [Test] 
    211         public void cannot_assign_a_parent_twice() 
    212         { 
    213             GivenTypeInstance<Customer>(); 
    214             ThenTypeBuilder.GetProperty("FirstName").SetOwner(ThenTypeBuilder); 
    215             ITypeBuilder newBuilder = new ReflectionBasedType(typeof(Customer)).CreateBuilder(); 
    216             Executing(() => ThenTypeBuilder.GetProperty("FirstName").SetOwner(newBuilder)) 
    217                 .ShouldThrow<InvalidOperationException>(); 
    218         } 
    219  
    220         [Test] 
    221207        public void no_reference_is_kept_after_a_call_to_apply() 
    222208        { 
    223             GivenTypeInstance<Customer>(); 
     209            given_builder_for<Customer>(); 
    224210            var customer = new Customer(); 
    225             ThenTypeBuilder.Apply(customer); 
    226  
    227             ThenTypeBuilder.GetProperty("FirstName").TrySetValue("Frodo") 
     211            TypeBuilder.Update(customer); 
     212 
     213            TypeBuilder.GetProperty("FirstName").TrySetValue("Frodo") 
    228214                .ShouldBeTrue(); 
    229215 
    230             object newCustomer = ThenTypeBuilder.Create(); 
     216            object newCustomer = TypeBuilder.Create(); 
    231217            newCustomer.ShouldNotBeTheSameInstanceAs(customer); 
    232218            customer.FirstName.ShouldBe(null); 
     
    245231        void WhenCreatingTheObject() 
    246232        { 
    247             _result = ThenTypeBuilder.Create(); 
     233            _result = TypeBuilder.Create(); 
    248234        } 
    249235 
     
    251237        public void a_type_instance_can_be_applied_twice() 
    252238        { 
    253             GivenTypeInstance<Customer>(); 
    254             GivenProperty("Username", "johndoe"); 
    255  
    256             WhenCreatingTheObject(); 
    257  
    258             GivenProperty("FirstName", "John"); 
     239            given_builder_for<Customer>(); 
     240            given_property("Username", "johndoe"); 
     241 
     242            WhenCreatingTheObject(); 
     243 
     244            given_property("FirstName", "John"); 
    259245            WhenCreatingTheObject(); 
    260246 
     
    266252        public void a_value_can_be_assigned_to_the_type_instance() 
    267253        { 
    268             GivenTypeInstance<int>(); 
    269  
    270             ThenTypeBuilder.TrySetValue(3) 
     254            given_builder_for<int>(); 
     255 
     256            TypeBuilder.TrySetValue(3) 
    271257                .ShouldBeTrue(); 
    272             ThenTypeBuilder.HasValue.ShouldBeTrue(); 
    273             ThenTypeBuilder.Value.ShouldBe(3); 
     258            TypeBuilder.HasValue.ShouldBeTrue(); 
     259            TypeBuilder.Value.ShouldBe(3); 
    274260        } 
    275261 
     
    277263        public void a_value_of_the_incorrect_type_cannot_be_assinged() 
    278264        { 
    279             GivenTypeInstance<int>(); 
    280  
    281             ThenTypeBuilder.TrySetValue("hello") 
     265            given_builder_for<int>(); 
     266 
     267            TypeBuilder.TrySetValue("hello") 
    282268                .ShouldBeFalse(); 
    283269 
    284             ThenTypeBuilder.HasValue.ShouldBeFalse(); 
    285         } 
    286  
    287         [Test] 
    288         public void creating_an_object_twice_returns_the_same_object() 
    289         { 
    290             GivenTypeInstance<Customer>(); 
    291             ThenTypeBuilder.Create().ShouldBeTheSameInstanceAs(ThenTypeBuilder.Create()); 
    292         } 
    293  
     270            TypeBuilder.HasValue.ShouldBeFalse(); 
     271        } 
    294272        [Test] 
    295273        public void nested_properties_are_assigned() 
    296274        { 
    297             GivenTypeInstance<Customer>(); 
    298             GivenProperty("Address.Line1", "Cadbury Street"); 
    299             GivenProperty("Address.City", "London"); 
     275            given_builder_for<Customer>(); 
     276            given_property("Address.Line1", "Cadbury Street"); 
     277            given_property("Address.City", "London"); 
    300278 
    301279            WhenCreatingTheObject(); 
     
    308286        public void setting_properties_on_children_of_indexers_works_as_expected() 
    309287        { 
    310             GivenTypeInstance<House>(); 
    311  
    312             GivenProperty("CustomersByName:john.FirstName", "John"); 
    313             GivenProperty("CustomersByName:john.LastName", "Doe"); 
     288            given_builder_for<House>(); 
     289 
     290            given_property("CustomersByName:john.FirstName", "John"); 
     291            given_property("CustomersByName:john.LastName", "Doe"); 
    314292            WhenCreatingTheObject(); 
    315293            ThenTheObject<House>().CustomersByName["john"].FirstName.ShouldBe("John"); 
     
    320298        public void the_properties_are_assigned() 
    321299        { 
    322             GivenTypeInstance<Customer>(); 
    323             GivenProperty("Username", "johndoe"); 
    324             GivenProperty("FirstName", "john"); 
     300            given_builder_for<Customer>(); 
     301            given_property("Username", "johndoe"); 
     302            given_property("FirstName", "john"); 
    325303 
    326304            WhenCreatingTheObject(); 
     
    330308    } 
    331309 
    332     public class when_assigning_a_value_to_a_parameter_binder : parameter_instance_context 
    333     { 
    334         [Test] 
    335         public void the_parameter_has_a_value() 
    336         { 
    337             GivenParameterInstance((int a) => { }); 
    338             GivenBinderKey("a", 1); 
    339  
    340             TheParameter.IsReadyForAssignment.ShouldBeTrue(); 
    341         } 
    342     } 
    343  
    344     public class when_not_assigning_a_value_to_a_parameter : parameter_instance_context 
    345     { 
    346         public void MethodWithOptional([Optional] int a) 
    347         { 
    348         } 
    349  
    350         [Test] 
    351         public void an_optional_value_gives_the_parameter_a_value() 
    352         { 
    353             GivenParameterInstance<int>(MethodWithOptional); 
    354  
    355             TheParameter.IsReadyForAssignment.ShouldBeTrue(); 
    356         } 
    357  
    358         [Test] 
    359         public void an_unfilled_parameter_doesnt_have_value() 
    360         { 
    361             GivenParameterInstance((int a) => { }); 
    362  
    363             TheParameter.IsReadyForAssignment.ShouldBeFalse(); 
    364         } 
    365     } 
    366  
    367     public class parameter_instance_context : instance_context 
    368     { 
    369         protected ParameterInstance TheParameter; 
    370  
    371         protected void GivenBinderKey<TValue>(string key, TValue value) 
    372         { 
    373             TheParameter.Binder.SetProperty(key, new[] {value}, (src, output) => BindingResult.Success(src)) 
    374                 .ShouldBeTrue(); 
    375         } 
    376  
    377         protected void GivenParameterInstance<T>(Action<T> action) 
    378         { 
    379             var parameterType = new ReflectionBasedTypeSystem().FromClr(action.Method.GetParameters()[0].ParameterType); 
    380             TheParameter = new ParameterInstance(new ReflectionParameter(action.Method.GetParameters()[0]), 
    381                                                  new KeyedValuesBinder( 
    382                                                      parameterType, 
    383                                                      action.Method.GetParameters()[0].Name)); 
    384         } 
    385     } 
    386  
    387     public class instance_context : context 
    388     { 
     310 
     311    public abstract class instance_context : context 
     312    { 
     313        protected static ITypeSystem _ts = TypeSystems.Default; 
     314        public instance_context() 
     315        { 
     316        } 
    389317        // ITypeSystem _typeSystem = new  
    390         public void GivenTypeInstance<T1>() 
    391         { 
    392             ThenTypeBuilder = new ReflectionBasedTypeSystem().FromClr(typeof(T1)).CreateBuilder(); 
    393         } 
    394  
    395         protected ITypeBuilder ThenTypeBuilder; 
    396  
    397         protected void GivenProperty(string prop, object value) 
    398         { 
    399             ThenTypeBuilder.GetProperty(prop).TrySetValue(value).ShouldBeTrue(); 
     318        public void given_builder_for<T1>() 
     319        { 
     320            TypeBuilder = _ts.FromClr(typeof(T1)).CreateBuilder(); 
     321        } 
     322 
     323        protected ITypeBuilder TypeBuilder; 
     324 
     325        protected void given_property(string prop, object value) 
     326        { 
     327            TypeBuilder.GetProperty(prop).TrySetValue(value).ShouldBeTrue(); 
    400328        } 
    401329    } 
  • trunk/src/core/OpenRasta.Tests.Unit/TypeSystem/Members_Specification.cs

    r362 r429  
    2020using OpenRasta.TypeSystem; 
    2121using OpenRasta.TypeSystem.ReflectionBased; 
    22 using OpenRasta.TypeSystem.ReflectionBased.Surrogates; 
    2322 
    2423namespace Accessors_Specification 
     
    2928        public void a_reference_type_can_be_assigned_a_null_value() 
    3029        { 
    31             new ReflectionBasedType(typeof(string)).CanSetValue(null) 
     30            new ReflectionBasedType(_typeSystem,typeof(string)).CanSetValue(null) 
    3231                .ShouldBe(true); 
    3332        } 
     
    3635        public void a_reflection_type_cannot_be_equal_to_null() 
    3736        { 
    38             new ReflectionBasedType(typeof(string)).Equals(null) 
     37            new ReflectionBasedType(_typeSystem,typeof(string)).Equals(null) 
    3938                .ShouldBeFalse(); 
    4039        } 
     
    4443        { 
    4544            object result; 
    46             new ReflectionBasedType(typeof(string)).TryCreateInstance(new[] { "value" }, (str, type) => BindingResult.Success(str), out result) 
     45            new ReflectionBasedType(_typeSystem,typeof(string)).TryCreateInstance(new[] { "value" }, (str, type) => BindingResult.Success(str), out result) 
    4746                .ShouldBeTrue(); 
    4847            result.ShouldBe("value"); 
     
    5352        { 
    5453            object result; 
    55             new ReflectionBasedType(typeof(string)).TryCreateInstance(new[] { "value" }, (str, type) => BindingResult.Failure(), out result) 
     54            new ReflectionBasedType(_typeSystem,typeof(string)).TryCreateInstance(new[] { "value" }, (str, type) => BindingResult.Failure(), out result) 
    5655                .ShouldBeFalse(); 
    5756        } 
     
    6059        public void a_value_type_cannot_be_assigned_a_null_value() 
    6160        { 
    62             new ReflectionBasedType(typeof(int)).CanSetValue(null) 
     61            new ReflectionBasedType(_typeSystem,typeof(int)).CanSetValue(null) 
    6362                .ShouldBeFalse(); 
    6463        } 
     
    6766        public void an_incorrect_type_cannot_be_assigned() 
    6867        { 
    69             new ReflectionBasedType(typeof(int)).CanSetValue("hello") 
     68            new ReflectionBasedType(_typeSystem,typeof(int)).CanSetValue("hello") 
    7069                .ShouldBeFalse(); 
    7170        } 
     
    8180        public void the_name_is_the_type_name() 
    8281        { 
    83             new ReflectionBasedType(typeof(string)).Name 
     82            new ReflectionBasedType(_typeSystem,typeof(string)).Name 
    8483                .ShouldBe("String"); 
    8584        } 
     
    8887        public void two_reflection_based_types_are_equal_if_built_from_the_same_native_type() 
    8988        { 
    90             var type1 = new ReflectionBasedType(typeof(string)); 
    91             var type2 = new ReflectionBasedType(typeof(string)); 
     89            var type1 = new ReflectionBasedType(_typeSystem,typeof(string)); 
     90            var type2 = new ReflectionBasedType(_typeSystem,typeof(string)); 
    9291            type1.Equals(type2).ShouldBeTrue(); 
    9392            type1.GetHashCode().ShouldBe(type2.GetHashCode()); 
     
    9796        public void two_reflection_based_types_are_not_equal_if_built_from_different_native_types() 
    9897        { 
    99             var type1 = new ReflectionBasedType(typeof(string)); 
    100             var type2 = new ReflectionBasedType(typeof(object)); 
     98            var type1 = new ReflectionBasedType(_typeSystem,typeof(string)); 
     99            var type2 = new ReflectionBasedType(_typeSystem,typeof(object)); 
    101100            type1.Equals(type2).ShouldBeFalse(); 
    102101            type1.GetHashCode().ShouldNotBe(type2.GetHashCode()); 
     
    109108        public void a_type_compared_to_a_null_results_in_minus_one() 
    110109        { 
    111             new ReflectionBasedType(typeof(int)).CompareTo(null) 
     110            new ReflectionBasedType(_typeSystem,typeof(int)).CompareTo(null) 
    112111                .ShouldBe(-1); 
    113112        } 
     
    116115        public void two_types_not_in_an_inheritance_hierarchy_compare_to_minus_one() 
    117116        { 
    118             new ReflectionBasedType(typeof(int)).CompareTo(new ReflectionBasedType(typeof(string))) 
     117            new ReflectionBasedType(_typeSystem,typeof(int)).CompareTo(new ReflectionBasedType(_typeSystem,typeof(string))) 
    119118                .ShouldBe(-1); 
    120119        } 
     
    144143        { 
    145144            GivenTypeFor<Type>(); 
    146             ThenTheProperty("Namespace.Length").TargetType.ShouldBe<int>(); 
     145            ThenTheProperty("Namespace.Length").Type.Equals<int>().ShouldBeTrue(); 
    147146        } 
    148147 
     
    152151            GivenTypeFor<string>(); 
    153152 
    154             ThenTheProperty("Length").TargetType.ShouldBe<int>(); 
     153            ThenTheProperty("Length").Type.Equals<int>().ShouldBeTrue(); 
    155154        } 
    156155 
     
    159158        { 
    160159            GivenTypeFor<House>(); 
    161             ThenTheProperty("Customers:0.FirstName").TargetType.ShouldBe<string>(); 
     160            ThenTheProperty("Customers:0.FirstName").Type.Equals<string>().ShouldBeTrue(); 
    162161        } 
    163162 
     
    180179        { 
    181180            GivenTypeFor<House>(); 
    182             ThenTheProperty("Customers:0").TargetType.ShouldBe<Customer>(); 
     181            ThenTheProperty("Customers:0").Type.Equals<Customer>().ShouldBeTrue(); 
    183182        } 
    184183 
     
    232231        } 
    233232 
    234         ReflectionBasedProperty ThenTheProperty(string propertyName) 
    235         { 
    236             return ThenTheType.GetProperty(propertyName) as ReflectionBasedProperty; 
     233        IProperty ThenTheProperty(string propertyName) 
     234        { 
     235            return Type.FindPropertyByPath(propertyName); 
    237236        } 
    238237    } 
     
    257256            GivenTypeFor<RingOfPower>(); 
    258257 
    259             var wornByMethod = ThenTheType.GetMethod("WornBy"); 
     258            var wornByMethod = Type.GetMethod("WornBy"); 
    260259            wornByMethod 
    261260                .ShouldNotBeNull() 
     
    271270            GivenTypeFor<RingOfPower>(); 
    272271 
    273             ThenTheType.GetMethod("WornBy") 
    274                 .ShouldBeTheSameInstanceAs(ThenTheType.GetMethod("wornby")); 
     272            Type.GetMethod("WornBy") 
     273                .ShouldBeTheSameInstanceAs(Type.GetMethod("wornby")); 
    275274        } 
    276275        [Test] 
     
    279278            GivenTypeFor<RingOfPower>(); 
    280279 
    281             ThenTheType.GetMethod("ToString").Owner.TypeName.ShouldBe("Object"); 
    282         } 
    283         protected ICollection<IMethod> TheMethods { get { return ThenTheType.GetMethods(); } } 
     280            Type.GetMethod("ToString").Owner.TypeName.ShouldBe("Object"); 
     281        } 
     282        protected ICollection<IMethod> TheMethods { get { return Type.GetMethods(); } } 
    284283    } 
    285284 
     
    292291    public class when_building_types_from_the_type_system : context 
    293292    { 
    294         readonly ITypeSystem TypeSystem = new ReflectionBasedTypeSystem(); 
     293        readonly ITypeSystem TypeSystem = TypeSystems.Default; 
    295294 
    296295        [Test] 
     
    311310    public class IType_context : context 
    312311    { 
    313         protected IType ThenTheType; 
     312         
     313        protected ITypeSystem _typeSystem; 
     314 
     315        public IType_context() 
     316        { 
     317            _typeSystem = TypeSystems.Default; 
     318        } 
     319        protected IType Type; 
    314320 
    315321        protected void GivenTypeFor<TTarget>() 
    316322        { 
    317             ThenTheType = TypeForClr<TTarget>(); 
     323            Type = TypeForClr<TTarget>(); 
    318324        } 
    319325 
    320326        protected IType TypeForClr<TTarget>() 
    321327        { 
    322             return new ReflectionBasedTypeSystem { SurrogateFactory = new DefaultSurrogateFactory() }.FromClr(typeof(TTarget)); 
     328            return _typeSystem.FromClr(typeof(TTarget)); 
    323329        } 
    324330    } 
  • trunk/src/core/OpenRasta.Tests.Unit/TypeSystem/Surrogates_Specification.cs

    r314 r429  
    1111 
    1212using System; 
     13using System.Collections; 
    1314using System.Collections.Generic; 
     15using System.Linq; 
    1416using Instances_Specification; 
    1517using NUnit.Framework; 
    1618using OpenRasta.Testing; 
    1719using OpenRasta.Tests.Unit.Fakes; 
     20 
    1821using OpenRasta.TypeSystem; 
    1922using OpenRasta.TypeSystem.ReflectionBased; 
     23using Frodo = OpenRasta.Tests.Unit.Fakes.Frodo; 
    2024 
    2125namespace Surrogates_Specification 
    2226{ 
    23     public class when_using_ListOfT : context 
     27 
     28    public class when_using_ListOfT : instance_context 
    2429    { 
    2530        ITypeBuilder _theBuilder; 
     
    2833        public void indexer_values_are_ignored_and_values_are_appended() 
    2934        { 
    30             GivenTypeInstance(); 
     35            given_builder(); 
    3136 
    3237            _theBuilder.GetProperty(":1").TrySetValue("hello").ShouldBeTrue(); 
    3338            _theBuilder.GetProperty(":0").TrySetValue("hello2").ShouldBeTrue(); 
    3439 
    35             var theList = (List<string>) _theBuilder.Create(); 
     40            var theList = (List<string>)_theBuilder.Create(); 
    3641            theList[0].ShouldBe("hello"); 
    3742            theList[1].ShouldBe("hello2"); 
     
    4045        public void the_indexer_is_surrogated() 
    4146        { 
    42             GivenTypeInstance(); 
     47            given_builder(); 
    4348 
    4449            _theBuilder.GetProperty(":0").TrySetValue("hello") 
    4550                .ShouldBeTrue(); 
    4651 
    47             var theList = (List<string>) _theBuilder.Create(); 
     52            var theList = (List<string>)_theBuilder.Create(); 
    4853            theList[0].ShouldBe("hello"); 
    4954        } 
    5055 
    51         void GivenTypeInstance() 
    52         { 
    53             _theBuilder = new ReflectionBasedTypeSystem().FromClr(typeof(List<string>)).CreateBuilder(); 
    54         } 
    55     } 
    56  
    57     public class when_using_ListOfT_as_a_nested_property : context 
     56        void given_builder() 
     57        { 
     58            _theBuilder = _ts.FromClr(typeof(List<string>)).CreateBuilder(); 
     59        } 
     60    } 
     61 
     62    public class when_using_ListOfT_as_a_nested_property : instance_context 
    5863    { 
    5964        ITypeBuilder _theBuilder; 
     
    6772                .ShouldBeTrue(); 
    6873 
    69             var theList = (ListContainer) _theBuilder.Create(); 
     74            var theList = (ListContainer)_theBuilder.Create(); 
    7075            theList.ListOfStrings[0].ShouldBe("hello"); 
    7176        } 
     
    7378        public void indexer_value_is_ignored_when_surrogate_is_an_intermediary() 
    7479        { 
    75             var instance = new ReflectionBasedTypeSystem().FromClr(typeof(House)).CreateBuilder(); 
     80            var instance = _ts.FromClr(typeof(House)).CreateBuilder(); 
    7681 
    7782            instance.GetProperty("Customers:4.FirstName").TrySetValue("Anakin"); 
     
    8388        void GivenTypeInstance() 
    8489        { 
    85             _theBuilder = new ReflectionBasedTypeSystem().FromClr(typeof(ListContainer)).CreateBuilder(); 
     90            _theBuilder = _ts.FromClr(typeof(ListContainer)).CreateBuilder(); 
    8691        } 
    8792 
     
    9398    public class when_using_surrogated_property : instance_context 
    9499    { 
    95          
     100 
    96101    } 
    97102    public class when_using_DateTime_surrogate : instance_context 
     
    102107        public void nested_surrogate_types_are_used_for_read_only_properties() 
    103108        { 
    104             GivenTypeInstance<Customer>(); 
    105             GivenProperty("DateOfBirth.Day", 14); 
    106             GivenProperty("DateOfBirth.Month", 12); 
    107  
    108             WhenCreatingTheObject(); 
    109  
    110             ThenTheObject<Customer>().DateOfBirth.Day.ShouldBe(14); 
    111             ThenTheObject<Customer>().DateOfBirth.Month.ShouldBe(12); 
     109            given_builder_for<Customer>(); 
     110            given_property("DateOfBirth.Day", 14); 
     111            given_property("DateOfBirth.Month", 12); 
     112 
     113            when_creating_object(); 
     114 
     115            result_as<Customer>().DateOfBirth.Day.ShouldBe(14); 
     116            result_as<Customer>().DateOfBirth.Month.ShouldBe(12); 
    112117        } 
    113118 
     
    115120        public void surrogate_types_are_used_for_read_only_properties() 
    116121        { 
    117             GivenTypeInstance<DateTime>(); 
    118             GivenProperty("Day", 14); 
    119  
    120             WhenCreatingTheObject(); 
    121  
    122             ThenTheObject<DateTime>().Day.ShouldBe(14); 
    123         } 
    124  
    125         T ThenTheObject<T>() 
    126         { 
    127             return (T) _result; 
    128         } 
    129  
    130         void WhenCreatingTheObject() 
    131         { 
    132             _result = ThenTypeBuilder.Create(); 
     122            given_builder_for<DateTime>(); 
     123            given_property("Day", 14); 
     124 
     125            when_creating_object(); 
     126 
     127            result_as<DateTime>().Day.ShouldBe(14); 
     128        } 
     129 
     130        T result_as<T>() 
     131        { 
     132            return (T)_result; 
     133        } 
     134 
     135        void when_creating_object() 
     136        { 
     137            _result = TypeBuilder.Create(); 
     138        } 
     139 
     140    } 
     141    public class indexer_for_enumerates : context.indexer_context<IEnumerable<string>,string> 
     142    { 
     143        [Test] 
     144        public void values_are_generated() 
     145        { 
     146            given_builder(); 
     147            given_successful_property(":0", "zero"); 
     148            given_successful_property(":1", "one"); 
     149            given_successful_property(":3", "three"); 
     150 
     151            when_object_built(); 
     152 
     153            then_values_should_be("zero","one","three"); 
     154        } 
     155    } 
     156 
     157    public class collection_for_enumerates : context.indexer_context<ICollection<string>, string> 
     158    { 
     159        [Test] 
     160        public void values_are_generated() 
     161        { 
     162            given_builder(); 
     163            given_successful_property(":0", "zero"); 
     164            given_successful_property(":1", "one"); 
     165            given_successful_property(":3", "three"); 
     166 
     167            when_object_built(); 
     168 
     169            then_values_should_be("zero", "one", "three"); 
     170        } 
     171    } 
     172 
     173    public class list_for_enumerates : context.indexer_context<IList<string>, string> 
     174    { 
     175        [Test] 
     176        public void values_are_generated() 
     177        { 
     178            given_builder(); 
     179            given_successful_property(":0", "zero"); 
     180            given_successful_property(":1", "one"); 
     181            given_successful_property(":3", "three"); 
     182 
     183            when_object_built(); 
     184 
     185            then_values_should_be("zero", "one", "three"); 
     186        } 
     187    } 
     188    public class Replicator : List<Frodo>{} 
     189    public class using_enumerable_types_with_indexer_surrogates : context.indexer_context<Replicator,Frodo> 
     190    { 
     191        public void multiple_values_are_added_to_the_same_object() 
     192        { 
     193            given_builder(); 
     194            given_successful_property(":0.FirstName", "Frodo"); 
     195            given_successful_property(":0.LastName", "Baggins"); 
     196 
     197            when_object_built(); 
     198 
     199            result.First().FirstName.ShouldBe("Frodo"); 
     200            result.First().LastName.ShouldBe("Baggins"); 
     201        } 
     202    } 
     203    namespace context 
     204    { 
     205        public class indexer_context<T,TValue> : OpenRasta.Testing.context 
     206            where T:IEnumerable<TValue> 
     207        { 
     208            protected static ITypeSystem TypeSystem = TypeSystems.Default; 
     209            protected ITypeBuilder builder; 
     210            protected T result; 
     211 
     212            protected void given_builder() 
     213            { 
     214                builder = TypeSystem.FromClr<T>().CreateBuilder(); 
     215            } 
     216            protected void given_successful_property(string key, object value) 
     217            { 
     218                builder.GetProperty(key).TrySetValue(value).ShouldBeTrue(); 
     219            } 
     220            protected void when_object_built() 
     221            { 
     222                result = (T)builder.Create(); 
     223            } 
     224            protected void then_values_should_be(params object[] values) 
     225            { 
     226                for (int i = 0; i < values.Length; i++) 
     227                { 
     228                    result.Skip(i).FirstOrDefault().ShouldBe(values[i]); 
     229                } 
     230            } 
    133231        } 
    134232    } 
  • trunk/src/core/OpenRasta.Tests.Unit/Web/Handlers/HandlerRepository_Specification.cs

    r362 r429  
    1515        public void canoot_add_the_same_handler_type_twice_to_the_same_key() 
    1616        { 
    17             var type = new ReflectionBasedTypeSystem().FromClr(typeof(string)); 
     17            var type = TypeSystems.Default.FromClr(typeof(string)); 
    1818            var repo = new HandlerRepository(); 
    1919 
     
    2626        public void two_handlers_can_be_registered_for_the_same_key() 
    2727        { 
    28             var handler1 = new ReflectionBasedTypeSystem().FromClr(typeof(Sauron)); 
    29             var handler2 = new ReflectionBasedTypeSystem().FromClr(typeof(Frodo)); 
     28            var handler1 = TypeSystems.Default.FromClr(typeof(Sauron)); 
     29            var handler2 = TypeSystems.Default.FromClr(typeof(Frodo)); 
    3030 
    3131            var repo = new HandlerRepository(); 
     
    4040        public void the_first_handler_is_returned_when_two_handlers_are_registered_for_the_same_key() 
    4141        { 
    42             var handler1 = new ReflectionBasedTypeSystem().FromClr(typeof(Sauron)); 
    43             var handler2 = new ReflectionBasedTypeSystem().FromClr(typeof(Frodo)); 
     42            var handler1 = TypeSystems.Default.FromClr(typeof(Sauron)); 
     43            var handler2 = TypeSystems.Default.FromClr(typeof(Frodo)); 
    4444 
    4545            var repo = new HandlerRepository(); 
     
    5555            var repo = new HandlerRepository(); 
    5656 
    57             Executing(() => repo.AddResourceHandler(null, new ReflectionBasedTypeSystem().FromClr(typeof(Frodo)))) 
     57            Executing(() => repo.AddResourceHandler(null, TypeSystems.Default.FromClr(typeof(Frodo)))) 
    5858                .ShouldThrow<ArgumentNullException>(); 
    5959 
     
    6363            var repo = new HandlerRepository(); 
    6464 
    65             Executing(() => repo.AddResourceHandler(null, new ReflectionBasedTypeSystem().FromClr(typeof(Frodo)))) 
     65            Executing(() => repo.AddResourceHandler(null, TypeSystems.Default.FromClr(typeof(Frodo)))) 
    6666                .ShouldThrow<ArgumentNullException>(); 
    6767        } 
    6868        public void the_same_handler_can_be_registered_for_two_resources() 
    6969        { 
    70             var gilGalad = new ReflectionBasedTypeSystem().FromClr(typeof(GilGalad)); 
     70            var gilGalad = TypeSystems.Default.FromClr(typeof(GilGalad)); 
    7171 
    7272            var repo = new HandlerRepository(); 
     
    8080        public void enumerating_over_the_list_of_handlers_will_only_return_distinct_handlers() 
    8181        { 
    82             var gilGalad = new ReflectionBasedTypeSystem().FromClr(typeof(GilGalad)); 
     82            var gilGalad = TypeSystems.Default.FromClr(typeof(GilGalad)); 
    8383 
    8484            var repo = new HandlerRepository(); 
  • trunk/src/core/OpenRasta.Tests.Unit/Web/Markup/SelectElement_Specification.cs

    r323 r429  
    2020namespace SelectElement_Specification 
    2121{ 
    22     public class when_there_is_a_value : markup_element_context<ISelectElement> 
     22    public class when_the_property_returns_a_value_for_enumerations : markup_element_context<ISelectElement> 
    2323    { 
    24         public AttributeTargets PropertyReturningFalse { get{ return AttributeTargets.Interface;} } 
     24        public AttributeTargets PropertyReturningFalse 
     25        { 
     26            get{ return AttributeTargets.Interface; } 
     27        } 
     28        [Test] 
    2529        public void the_option_element_is_selected() 
    2630        { 
     
    3337        } 
    3438    } 
    35     //public class when_setting_a_value_before_adding_option_elements : context 
    36     //{ 
    37     //    [Test] 
    38     //    public void the_value_is_stored() 
    39     //    { 
    40     //        var element = new SelectElement(); 
    41     //        element.Value = "25"; 
    42     //        element.Children.Add(new OptionElement {Content = "26"}); 
    43     //        element.Value.ShouldBe("25"); 
    44     //    } 
    45     //    [Test] 
    46     //    public void the_selected_property_is_set_on_the_option_element() 
    47     //    { 
    48     //        var element = new SelectElement(); 
    49     //        element.Value = "25"; 
    50     //        element.Children.Add(new OptionElement {Content = "25"}); 
    51     //        element.Children.First().Selected.ShouldBe(true); 
    52     //    } 
    53     //    [Test] 
    54     //    public void the_selected_property_on_the_option_element_is_reset_if_the_assigned_value_is_different() 
    55     //    { 
     39    public class when_building_an_option_tag : context 
     40    { 
     41        [Test] 
     42        public void the_markup_for_selected_options_is_correct() 
     43        { 
     44            var element = Document.CreateElement<IOptionElement>().Value("value")["content"]; 
     45            element.Selected = true; 
     46            element.ToString().ShouldBe("<option value=\"value\" selected=\"selected\">content</option>"); 
     47        } 
     48        [Test] 
     49        public void the_markup_for_not_selected_options_is_correct() 
     50        { 
    5651 
    57     //        var element = new SelectElement(); 
    58     //        element.Value = "25"; 
    59     //        element.Children.Add(new OptionElement { Content = "26", Selected = true }); 
    60     //        element.Children.First().Selected.ShouldBe(false); 
    61     //    } 
    62     //    [Test] 
    63     //    public void rendering_the_element_when_the_value_doesnt_match_an_option_results_in_an_error() 
    64     //    { 
    65     //        var element = new SelectElement() {Value = "24"}; 
    66     //        element.Children.Add(new OptionElement {Content = "25"}); 
    67     //        Executing(() => element.ToString()) 
    68     //            .ShouldThrow<InvalidOperationException>(); 
    69     //    } 
    70     //} 
    71     //public class when_setting_a_value_after_adding_option_elements : context 
    72     //{ 
    73     //    [Test] 
    74     //    public void the_value_is_stored() 
    75     //    { 
    76     //        var element = new SelectElement(); 
    77     //        element.Children.Add(new OptionElement { Content = "26" }); 
    78     //        element.Value = "25"; 
    79     //        element.Value.ShouldBe("25"); 
    80     //    } 
    81     //    [Test] 
    82     //    public void the_selected_property_is_set_on_the_option_element() 
    83     //    { 
    84  
    85     //        var element = new SelectElement(); 
    86     //        element.Children.Add(new OptionElement { Content = "25" }); 
    87     //        element.Value = "25"; 
    88     //        element.Children.First().Selected.ShouldBe(true); 
    89     //    } 
    90     //    [Test] 
    91     //    public void the_value_is_stored_after_removing_an_option_element() 
    92     //    { 
    93     //        var element = new SelectElement(); 
    94     //        element.Children.Add(new OptionElement { Content = "25" }); 
    95     //        element.Value = "25"; 
    96              
    97     //        element.Children.RemoveAt(0); 
    98     //        element.Value.ShouldBe("25"); 
    99     //    } 
    100     //} 
     52            var element = Document.CreateElement<IOptionElement>().Value("value")["content"]; 
     53            element.Selected = false; 
     54            element.ToString().ShouldBe("<option value=\"value\">content</option>"); 
     55        } 
     56    } 
    10157} 
    10258 
  • trunk/src/core/OpenRasta.Tests.Unit/Web/Pipeline/Contributors/ResponseEntityWriter_Specification.cs

    r362 r429  
    9494            Context.PipelineData.ResponseCodec = CodecRegistration.FromResourceType(typeof(object), 
    9595                                                                       typeof(TCodec), 
    96                                                                        new ReflectionBasedTypeSystem(), 
     96                                                                       TypeSystems.Default, 
    9797                                                                       new MediaType("application/unknown"), 
    9898                                                                       null, 
  • trunk/src/core/OpenRasta.Tests.Unit/Web/TemplatedUriResolver_Specification.cs

    r412 r429  
    1919using OpenRasta.Tests.Unit.Fakes; 
    2020using OpenRasta.TypeSystem; 
     21using OpenRasta.TypeSystem.ReflectionBased; 
    2122using OpenRasta.Web; 
    2223 
     
    3334            when_matching_uri("https://localhost/Valinor/Olorin"); 
    3435 
    35             matching_result 
     36            var resourceKey = matching_result 
    3637                .ShouldNotBeNull() 
    37                 .ResourceKey.ShouldBeOfType<IType>() 
     38                .ResourceKey; 
     39            resourceKey.ShouldBeOfType<IType>() 
    3840                .Equals<Gandalf>().ShouldBeTrue(); 
    3941        } 
     
    5557            when_creating_uri<IConvertible>("location2", null); 
    5658 
    57             ThenTheResult.ShouldBe("http://localhost/location2"); 
     59            Result.ShouldBe("http://localhost/location2"); 
    5860        } 
    5961 
     
    6769            when_creating_uri<object>(new NameValueCollection { { "variable1", "injected1" } }); 
    6870 
    69             ThenTheResult.ToString().ShouldBe("http://localhost/test/injected1"); 
     71            Result.ToString().ShouldBe("http://localhost/test/injected1"); 
    7072        } 
    7173 
     
    7779            when_creating_uri<IList<object>>(new NameValueCollection { { "variable1", "injected1" } }); 
    7880 
    79             ThenTheResult.ToString().ShouldBe("http://localhost/test/injected1"); 
     81            Result.ToString().ShouldBe("http://localhost/test/injected1"); 
    8082        } 
    8183 
     
    9092            when_creating_uri<IList<object>>(new NameValueCollection { { "variable1", "injected1" } }); 
    9193 
    92             ThenTheResult.ToString().ShouldBe("http://localhost/test?query=injected1"); 
     94            Result.ToString().ShouldBe("http://localhost/test?query=injected1"); 
    9395        } 
    9496 
     
    101103            when_creating_uri<IConvertible>(null); 
    102104 
    103             ThenTheResult.ShouldBe("http://localhost/location1"); 
     105            Result.ShouldBe("http://localhost/location1"); 
    104106        } 
    105107 
     
    112114            when_creating_uri<Frodo>(null); 
    113115 
    114             ThenTheResult.ShouldBe("http://localhost/theshire"); 
     116            Result.ShouldBe("http://localhost/theshire"); 
    115117        } 
    116118        [Test] 
     
    121123            when_creating_uri<Frodo>("http://localhost/lotr/".ToUri(), null); 
    122124 
    123             ThenTheResult.ShouldBe("http://localhost/lotr/theshire"); 
     125            Result.ShouldBe("http://localhost/lotr/theshire"); 
    124126        } 
    125127 
     
    131133            when_creating_uri<Frodo>("http://localhost/lotr".ToUri(), null); 
    132134 
    133             ThenTheResult.ShouldBe("http://localhost/lotr/theshire"); 
     135            Result.ShouldBe("http://localhost/lotr/theshire"); 
    134136        } 
    135137    } 
     
    141143            protected TemplatedUriResolver Resolver; 
    142144 
    143             protected Uri ThenTheResult; 
     145            protected Uri Result; 
     146            ITypeSystem TypeSystem; 
    144147 
     148            public templated_uri_resolver_context() 
     149            { 
     150                TypeSystem = TypeSystems.Default; 
     151            } 
    145152            [SetUp] 
    146153            public void before_each_behavior() 
    147154            { 
    148                 ThenTheResult = null; 
     155                Result = null; 
    149156                Resolver = new TemplatedUriResolver(); 
    150157            } 
    151158            protected void when_creating_uri<T>(Uri baseUri, NameValueCollection templateParameters) 
    152159            { 
    153                 ThenTheResult = Resolver.CreateUriFor(baseUri, typeof(T), templateParameters); 
     160                Result = Resolver.CreateUriFor(baseUri, typeof(T), templateParameters); 
    154161            } 
    155162 
    156163            protected void given_uri_mapping(string uri, Type type, CultureInfo cultureInfo, string alias) 
    157164            { 
    158                 Resolver.Add(new UriRegistration(uri, type, alias, cultureInfo)); 
     165                Resolver.Add(new UriRegistration(uri,  TypeSystem.FromClr(type), alias, cultureInfo)); 
    159166            } 
    160167 
    161168            protected void when_creating_uri<T1>(NameValueCollection nameValueCollection) 
    162169            { 
    163                 ThenTheResult = Resolver.CreateUriFor(new Uri("http://localhost"), typeof(T1), nameValueCollection); 
     170                Result = Resolver.CreateUriFor(new Uri("http://localhost"), typeof(T1), nameValueCollection); 
    164171            } 
    165172 
    166173            protected void when_creating_uri<T1>(string uriName, NameValueCollection nameValueCollection) 
    167174            { 
    168                 ThenTheResult = Resolver.CreateUriFor(new Uri("http://localhost"), typeof(T1), uriName, nameValueCollection); 
     175                Result = Resolver.CreateUriFor(new Uri("http://localhost"), typeof(T1), uriName, nameValueCollection); 
    169176            } 
    170177        } 
  • trunk/src/core/OpenRasta.Tests.Unit/openrasta_context.cs

    r420 r429  
    55using System.IO; 
    66using System.Text; 
     7using OpenRasta.Binding.Path; 
    78using OpenRasta.Codecs; 
    89using OpenRasta.Collections; 
     
    2829        public openrasta_context() 
    2930        { 
    30             TypeSystem = new ReflectionBasedTypeSystem(); 
     31            TypeSystem = TypeSystems.Default; 
    3132        } 
    3233 
     
    146147        { 
    147148            var bytes = Encoding.UTF8.GetBytes(content); 
    148             Request.Entity = new HttpEntity(new HttpHeaderDictionary(), new MemoryStream(bytes)) { ContentLength = bytes.Length }; 
     149            Request.Entity = new HttpEntity(Request.Entity.Headers, new MemoryStream(bytes)) { ContentLength = bytes.Length }; 
    149150        } 
    150151 
     
    208209                Resolver.AddDependency<IAuthenticationProvider, InMemAuthenticationProvider>(); 
    209210            Resolver.AddDependencyInstance(typeof(IErrorCollector), Errors = new TestErrorCollector()); 
     211            Resolver.AddDependency<IPathManager, DefaultPathManager>(); 
    210212             
    211213            manager.SetupCommunicationContext(Context = new InMemoryCommunicationContext()); 
  • trunk/src/core/OpenRasta/Binding/BinderBaseAttribute.cs

    r314 r429  
    1010 
    1111using System; 
    12 using OpenRasta.TypeSystem; 
    1312 
    1413namespace OpenRasta.Binding 
    1514{ 
    16     [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] 
    17     public abstract class BinderBaseAttribute : Attribute, IObjectBinderLocator 
     15    [Obsolete("The type was renamed. Please use BinderAttribute instead.")] 
     16    public abstract class BinderBaseAttribute : BinderAttribute 
    1817    { 
    19         public abstract IObjectBinder GetBinder(IMember parameterInfo); 
    2018    } 
    2119} 
  • trunk/src/core/OpenRasta/Binding/BindingResult.cs

    r314 r429  
    1111namespace OpenRasta.Binding 
    1212{ 
     13    /// <summary> 
     14    /// Represents the result of a binding. 
     15    /// </summary> 
    1316    public class BindingResult 
    1417    { 
     
    2023        } 
    2124 
     25        /// <summary> 
     26        /// Gets the instance of the built object. 
     27        /// </summary> 
     28        /// <remarks> 
     29        /// The value of this property is undefined when the binding has not been successful. 
     30        /// </remarks> 
    2231        public object Instance { get; private set; } 
     32 
     33        /// <summary> 
     34        /// Gets a value defining if the binding was successful. 
     35        /// </summary> 
    2336        public bool Successful { get; private set; } 
    2437 
     38        /// <summary> 
     39        /// Creates a binding result for failing bindings. 
     40        /// </summary> 
     41        /// <returns></returns> 
    2542        public static BindingResult Failure() 
    2643        { 
     
    2845        } 
    2946 
     47        /// <summary> 
     48        /// Creates a binding result for successful bindings. 
     49        /// </summary> 
     50        /// <param name="instance">The object successful built by the binder.</param> 
     51        /// <returns>An instance of the <see cref="BindingResult"/> type.</returns> 
    3052        public static BindingResult Success(object instance) 
    3153        { 
  • trunk/src/core/OpenRasta/Binding/ChangeSetBinder.cs

    r348 r429  
    1515namespace OpenRasta.Binding 
    1616{ 
     17    /// <summary> 
     18    /// Represents a binder for the ChangeSet type. 
     19    /// </summary> 
     20    /// <typeparam name="T"></typeparam> 
    1721    public class ChangeSetBinder<T> : KeyedValuesBinder where T : class 
    1822    { 
    1923        /// <summary> 
    20         /// Constructs a new binder for types of type ChangeSet. 
     24        /// Constructs a new binder for types of type <see cref="ChangeSet"/>. 
    2125        /// </summary> 
    2226        /// <param name="type"></param> 
  • trunk/src/core/OpenRasta/Binding/DefaultObjectBinderLocator.cs

    r362 r429  
    2222        { 
    2323            Logger = NullLogger.Instance; 
    24             TypeSystem = new ReflectionBasedTypeSystem(); 
     24            TypeSystem = TypeSystems.Default; 
    2525        } 
    2626 
     
    3030        public IObjectBinder GetBinder(IMember member) 
    3131        { 
    32             BinderBaseAttribute binderAttribute = member.FindAttribute<BinderBaseAttribute>() ?? member.Type.FindAttribute<BinderBaseAttribute>(); 
     32            var abstractObjectBinderAttribute = member.FindAttribute<BinderAttribute>() ?? member.Type.FindAttribute<BinderAttribute>(); 
    3333 
    34             if (binderAttribute != null) 
    35                 return binderAttribute.GetBinder(member); 
     34            if (abstractObjectBinderAttribute != null) 
     35                return abstractObjectBinderAttribute.GetBinder(member); 
    3636 
    3737            IMethod binderMethod = member.GetMethod("GetBinder"); 
  • trunk/src/core/OpenRasta/Binding/IObjectBinder.cs

    r314 r429  
    1313namespace OpenRasta.Binding 
    1414{ 
     15    /// <summary> 
     16    /// Represents a component able to build instances of objects from object paths and values. 
     17    /// </summary> 
    1518    public interface IObjectBinder 
    1619    { 
     20        /// <summary> 
     21        /// Gets a value defining if the binder contains any values. 
     22        /// </summary> 
    1723        bool IsEmpty { get; } 
     24 
     25        /// <summary> 
     26        /// Gets the list of prefixes that the binder will ignore when parsing the keys and value pairs. 
     27        /// </summary> 
    1828        ICollection<string> Prefixes { get; } 
     29 
     30        /// <summary> 
     31        /// Tries to set a property value based on a key and a list of values. 
     32        /// </summary> 
     33        /// <typeparam name="TValue">The type of values being used to assign to the destination property.</typeparam> 
     34        /// <param name="key">The object path to the property to assign.</param> 
     35        /// <param name="values">The values to be used in realizing the value for the property</param> 
     36        /// <param name="converter">The converter responsible for converting between the source values and the destination value.</param> 
     37        /// <returns><c>true</c> if the assignment was successful, otherwise <c>false</c>.</returns> 
    1938        bool SetProperty<TValue>(string key, IEnumerable<TValue> values, ValueConverter<TValue> converter); 
     39 
     40        /// <summary> 
     41        /// Tries to set an instance as the object used when assigning values. 
     42        /// </summary> 
     43        /// <param name="builtInstance">The instance of an object being used for binding.</param> 
     44        /// <returns><c>true</c> if the assignment was successful, otherwise <c>false</c>.</returns> 
    2045        bool SetInstance(object builtInstance); 
     46 
     47        /// <summary> 
     48        /// Attempts to build an object and return a <see cref="BindingResult"/> instance containing the result of the building. 
     49        /// </summary> 
     50        /// <returns>An instance of the <see cref="BindingResult"/> type containing the result of the binding.</returns> 
    2151        BindingResult BuildObject(); 
    2252    } 
  • trunk/src/core/OpenRasta/Binding/IObjectBinderLocator.cs

    r314 r429  
    1313namespace OpenRasta.Binding 
    1414{ 
     15    /// <summary> 
     16    /// Defines a component able to locate an object binder for a member. 
     17    /// </summary> 
    1518    public interface IObjectBinderLocator 
    1619    { 
     20        /// <summary> 
     21        /// Gets a binder for a member. 
     22        /// </summary> 
     23        /// <param name="member">The member for which to find a binder.</param> 
     24        /// <returns>An instance of an <see cref="IObjectBinder"/> defined for this member.</returns> 
    1725        IObjectBinder GetBinder(IMember member); 
    1826    } 
  • trunk/src/core/OpenRasta/Binding/KeyedValues.cs

    r315 r429  
    11namespace OpenRasta.Binding 
    22{ 
     3    /// <summary> 
     4    /// Represents a key and associated values. 
     5    /// </summary> 
    36    public abstract class KeyedValues 
    47    { 
     8        /// <summary> 
     9        /// The key for which a value is provided. 
     10        /// </summary> 
    511        public string Key { get; protected set; } 
     12 
     13        /// <summary> 
     14        /// Sets a value defining if the KeyedValue was used during the binding process. 
     15        /// </summary> 
    616        public bool WasUsed { get; protected set; } 
     17 
     18        /// <summary> 
     19        /// Tries to set the value on the provided object binder. 
     20        /// </summary> 
     21        /// <param name="binder">The <see cref="IObjectBinder"/> to use when applying the value.</param> 
     22        /// <returns><c>true</c> if the assignment was successful, otherwise <c>false</c>.</returns> 
    723        public abstract bool SetProperty(IObjectBinder binder); 
    824    } 
  • trunk/src/core/OpenRasta/Binding/KeyedValuesBinder.cs

    r421 r429  
    1111using System; 
    1212using System.Collections.Generic; 
    13 using System.Linq; 
    1413using OpenRasta.Binding.Path; 
    1514using OpenRasta.TypeSystem; 
     
    2019    public class KeyedValuesBinder : IObjectBinder 
    2120    { 
     21        readonly bool _isEnumerable; 
    2222        readonly string _name; 
    2323        readonly string _typeName; 
     
    2525        object _cachedBuiltObject; 
    2626        bool _isInstanceConstructed; 
    27         bool _isEnumerable; 
    2827 
    2928        public KeyedValuesBinder(IType target) : this(target, target.Name) 
     
    3332        public KeyedValuesBinder(IType target, string name) 
    3433        { 
    35             TypeSystem = target.TypeSystem; 
    36             _isEnumerable = !target.Equals<string>() && target.Type.IsCollection; 
     34            _isEnumerable = !target.Equals<string>() && target.Type.IsEnumerable; 
    3735            Builder = target.CreateBuilder(); 
    3836            _name = name; 
     
    4341        } 
    4442 
    45         protected IPathManager PathManager { get; set; } 
    46  
    4743        public bool IsEmpty 
    4844        { 
    49             get { return !_isEnumerable && !Builder.HasValue; } 
     45            get { return !Builder.HasValue; } 
    5046        } 
    5147 
    5248        public ICollection<string> Prefixes { get; private set; } 
    5349 
    54         public ITypeSystem TypeSystem { get; set; } 
    55  
    5650        protected ITypeBuilder Builder { get; private set; } 
     51        protected IPathManager PathManager { get; set; } 
    5752 
    5853        public virtual BindingResult BuildObject() 
     
    8479            bool success; 
    8580 
    86                 if (keyType.Type == PathComponentType.Constructor) 
    87                     success = SetConstructorValue(values, converter); 
    88                 else 
    89                     success = SetPropertyValue(key, keyType.ParsedValue, values, converter); 
     81            if (keyType.Type == PathComponentType.Constructor) 
     82                success = SetConstructorValue(values, converter); 
     83            else 
     84                success = SetPropertyValue(key, keyType.ParsedValue, values, converter); 
    9085 
    9186            if (!success) 
     
    10196        bool SetPropertyValue<TValue>(string key, string property, IEnumerable<TValue> values, ValueConverter<TValue> converter) 
    10297        { 
    103             IPropertyBuilder propertyBuilder = Builder.GetProperty(property ?? key); 
     98            var propertyBuilder = Builder.GetProperty(property ?? key); 
    10499            if (propertyBuilder == null) return false; 
    105100            return propertyBuilder.TrySetValue(values, converter); 
  • trunk/src/core/OpenRasta/Binding/KeyedValuesBinderAttribute.cs

    r314 r429  
    1313namespace OpenRasta.Binding 
    1414{ 
    15     public class KeyedValuesBinderAttribute : BinderBaseAttribute 
     15    public class KeyedValuesBinderAttribute : BinderAttribute 
    1616    { 
    1717        public override IObjectBinder GetBinder(IMember memberInfo) 
  • trunk/src/core/OpenRasta/Binding/KeyedValues`1.cs

    r314 r429  
    1515{ 
    1616    /// <summary> 
    17     /// Represent a string key associated with a series of values and a converter, used to match key and values pairs with the keyvalue binder. 
     17    /// Represent a key associated with a series of typed values and a converter, used to match key and values pairs with binders. 
    1818    /// </summary> 
    1919    /// <typeparam name="T">The type of the values.</typeparam> 
     
    2828            Converter = converter; 
    2929        } 
     30 
    3031 
    3132        public ValueConverter<T> Converter { get; private set; } 
  • trunk/src/core/OpenRasta/Binding/ValueConverter.cs

    r314 r429  
    1313namespace OpenRasta.Binding 
    1414{ 
     15    /// <summary> 
     16    /// Defines a conversion method used to convert entities between multiple types. 
     17    /// </summary> 
     18    /// <typeparam name="T">The type of the entity to convert.</typeparam> 
     19    /// <param name="entity">The entity instance to convert.</param> 
     20    /// <param name="entityType">The target Type</param> 
     21    /// <returns>The result of the conversion.</returns> 
    1522    public delegate BindingResult ValueConverter<T>(T entity, Type entityType); 
    1623} 
  • trunk/src/core/OpenRasta/Codecs/CodecRepository.cs

    r369 r429  
    3838        } 
    3939 
    40         public CodecRegistration FindByExtension(IMember resourceType, string extension) 
     40        public CodecRegistration FindByExtension(IMember resourceMember, string extension) 
    4141        { 
    4242            foreach (var codecRegistration in _codecs) 
     
    4545                if (codecRegistration.Extensions.Contains(extension, StringComparison.OrdinalIgnoreCase)) 
    4646                { 
    47                     if (codecRegistration.IsStrict && resourceType.CompareTo(codecResourceType) == 0) 
     47                    if (codecRegistration.IsStrict && resourceMember.Type.CompareTo(codecResourceType) == 0) 
    4848                        return codecRegistration; 
    4949 
    50                     if (resourceType.CompareTo(codecResourceType) >= 0) 
     50                    if (resourceMember.Type.CompareTo(codecResourceType) >= 0) 
    5151                        return codecRegistration; 
    5252                } 
     
    129129        } 
    130130 
    131         static int CalculateDistance(IMember type, CodecRegistration registration) 
     131        static int CalculateDistance(IMember member, CodecRegistration registration) 
    132132        { 
    133133            if (registration.ResourceType == null) 
    134134                return -1; 
    135135            if (registration.IsStrict) 
    136                 return (type.CompareTo(registration.ResourceType) == 0) ? 0 : -1; 
    137             return type.CompareTo(registration.ResourceType); 
     136                return (member.Type.CompareTo(registration.ResourceType) == 0) ? 0 : -1; 
     137            return member.Type.CompareTo(registration.ResourceType); 
    138138        } 
    139139 
  • trunk/src/core/OpenRasta/Configuration/DefaultDependencyRegistrar.cs

    r420 r429  
    1515using System.Reflection; 
    1616using OpenRasta.Binding; 
     17using OpenRasta.Binding.Path; 
    1718using OpenRasta.Codecs; 
    1819using OpenRasta.CodeDom.Compiler; 
     
    3334using OpenRasta.TypeSystem; 
    3435using OpenRasta.TypeSystem.ReflectionBased; 
     36using OpenRasta.TypeSystem.Surrogated; 
     37using OpenRasta.TypeSystem.Surrogates; 
     38using OpenRasta.TypeSystem.Surrogates.Static; 
    3539using OpenRasta.Web; 
    3640 
     
    3943    public class DefaultDependencyRegistrar : IDependencyRegistrar 
    4044    { 
     45        protected Type PathManagerType; 
     46 
    4147        public DefaultDependencyRegistrar() 
    4248        { 
     
    5056            OperationHydratorTypes = new List<Type>(); 
    5157            OperationCodecSelectorTypes = new List<Type>(); 
    52  
     58            SurrogateBuilders = new List<Type>(); 
    5359            LogSourceTypes = new List<Type>(); 
    5460 
     
    6571            SetOperationExecutor<OperationExecutor>(); 
    6672            SetOperationInterceptorProvider<SystemAndAttributesOperationInterceptorProvider>(); 
     73            SetPathManager<DefaultPathManager>(); 
    6774 
    6875            AddMethodFilter<TypeExclusionMethodFilter<object>>(); 
     
    7683            AddOperationCodecResolvers(); 
    7784            AddLogSources(); 
     85            AddSurrogateBuilders(); 
     86        } 
     87 
     88        public void AddSurrogateBuilders() 
     89        { 
     90            SurrogateBuilders.Add(typeof(ListIndexerSurrogateBuilder)); 
     91            SurrogateBuilders.Add(typeof(DateTimeSurrogate)); 
     92        } 
     93 
     94        protected IList<Type> SurrogateBuilders { get; private set; } 
     95 
     96        public void SetPathManager<T>() 
     97        { 
     98            PathManagerType = typeof(T); 
    7899        } 
    79100 
     
    186207        { 
    187208            RegisterCoreComponents(resolver); 
     209            RegisterSurrogateBuilders(resolver); 
    188210            RegisterLogging(resolver); 
    189211            RegisterMetaModelHandlers(resolver); 
    190             RegisterCodecs(resolver); 
    191212            RegisterContributors(resolver); 
    192213            RegisterCodeSnippeModifiers(resolver); 
     
    194215            RegisterOperationModel(resolver); 
    195216            RegisterLogSources(resolver); 
     217            RegisterCodecs(resolver); 
     218        } 
     219 
     220        protected virtual void RegisterSurrogateBuilders(IDependencyResolver resolver) 
     221        { 
     222            SurrogateBuilders.ForEach(x => resolver.AddDependency(typeof(ISurrogateBuilder), x, DependencyLifetime.Transient)); 
    196223        } 
    197224 
     
    257284            resolver.AddDependency(typeof(IOperationExecutor), OperationExecutorType, DependencyLifetime.Transient); 
    258285            resolver.AddDependency(typeof(IErrorCollector), ErrorCollectorType, DependencyLifetime.Transient); 
    259             resolver.AddDependency(typeof(IOperationInterceptorProvider), OperationInterceptorProviderType, DependencyLifetime.Singleton); 
     286            resolver.AddDependency(typeof(IOperationInterceptorProvider), OperationInterceptorProviderType, DependencyLifetime.Transient); 
     287            resolver.AddDependency(typeof(IPathManager), PathManagerType, DependencyLifetime.Singleton); 
     288            resolver.AddDependency(typeof(ISurrogateProvider), typeof(SurrogateBuilderProvider), DependencyLifetime.Singleton); 
    260289        } 
    261290 
  • trunk/src/core/OpenRasta/Data/ChangeSet`1.cs

    r362 r429  
    1515namespace OpenRasta.Data 
    1616{ 
     17    /// <summary> 
     18    /// Represents a set of changes that can be applied to a type. 
     19    /// </summary> 
     20    /// <typeparam name="T"></typeparam> 
    1721    public class ChangeSet<T> where T : class 
    1822    { 
     
    2226        } 
    2327 
     28        /// <summary> 
     29        /// Gets the list of changes to be applied to an object.