Skip to content

Commit

Permalink
renaming some signatures on IRequestData, closes gh-3
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Mar 31, 2012
1 parent cc7f5dc commit a565229
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 51 deletions.
3 changes: 0 additions & 3 deletions src/FubuCore.Testing/Binding/BindingContextTester.cs
Expand Up @@ -11,9 +11,6 @@

namespace FubuCore.Testing.Binding
{

// TODO -- convert all of these to the new BindingScenario test formats!

[TestFixture]
public class BindingContextTester
{
Expand Down
4 changes: 2 additions & 2 deletions src/FubuCore.Testing/Binding/InMemoryRequestDataTester.cs
Expand Up @@ -62,10 +62,10 @@ public void has_prefixed_key()
_data["pre-ab"] = 1;
_data["pre4"] = 1;

_data.HasAnyValuePrefixedWith("pre").ShouldBeTrue();
_data.HasChildRequest("pre").ShouldBeTrue();


_data.HasAnyValuePrefixedWith("else").ShouldBeFalse();
_data.HasChildRequest("else").ShouldBeFalse();
}
}
}
Expand Up @@ -61,6 +61,17 @@ public void get_all_valid_data_3_levels_deep()
request.Site.Address.City.ShouldEqual("Austin");
}

[Test]
public void does_not_place_a_value_if_the_inner_request_data_cannot_fill_the_child_request()
{
data["Order"] = "3";
data["UserName"] = "Max";
data["SiteName"] = "site 1";

var request = resolve<UpdateSiteRequest>();
request.Site.Address.ShouldBeNull();
}

[Test]
public void get_3_deep_errors()
{
Expand Down
4 changes: 2 additions & 2 deletions src/FubuCore.Testing/Binding/PrefixedRequestDataTester.cs
Expand Up @@ -50,8 +50,8 @@ public void positive_on_any_values_prefixed()
{
inner["SiteAddress[0]Name"] = "Jeremy";

prefixed.HasAnyValuePrefixedWith("Address[0]").ShouldBeTrue();
prefixed.HasAnyValuePrefixedWith("Address[1]").ShouldBeFalse();
prefixed.HasChildRequest("Address[0]").ShouldBeTrue();
prefixed.HasChildRequest("Address[1]").ShouldBeFalse();
}
}
}
Expand Up @@ -31,7 +31,7 @@ public void value_of_complicated_values()
[Test]
public void get_subrequest()
{
theData.GetSubRequest("Nested").Value("Flag3").ShouldEqual("f3");
theData.GetChildRequest("Nested").Value("Flag3").ShouldEqual("f3");
}

[Test]
Expand Down
Expand Up @@ -111,10 +111,10 @@ public void has_any_value_prefixed_with_key()

var request = SettingsRequestData.For(core1, core2, core3);

request.HasAnyValuePrefixedWith("One").ShouldBeTrue();
request.HasAnyValuePrefixedWith("Two").ShouldBeTrue();
request.HasAnyValuePrefixedWith("Three").ShouldBeTrue();
request.HasAnyValuePrefixedWith("NotInTheRequestDataAnywhere").ShouldBeFalse();
request.HasChildRequest("One").ShouldBeTrue();
request.HasChildRequest("Two").ShouldBeTrue();
request.HasChildRequest("Three").ShouldBeTrue();
request.HasChildRequest("NotInTheRequestDataAnywhere").ShouldBeFalse();
}
}
}
1 change: 0 additions & 1 deletion src/FubuCore.Testing/FubuExceptionTester.cs
@@ -1,6 +1,5 @@
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using FubuMVC.Core;
using FubuTestingSupport;
using NUnit.Framework;

Expand Down
2 changes: 1 addition & 1 deletion src/FubuCore/Binding/ArrayPropertyBinder.cs
Expand Up @@ -49,9 +49,9 @@ public void FillValues(PropertyInfo property, IBindingContext context)
{
var requestData = requests[i];


context.Logger.PushElement(typeof(T));

// TODO -- got to add the BindResult to context to store it later
context.BindObject(requestData, typeof (T), o =>
{
data[i] = (T) o;
Expand Down
7 changes: 6 additions & 1 deletion src/FubuCore/Binding/BindingContext.cs
Expand Up @@ -61,7 +61,7 @@ public IEnumerable<IRequestData> GetEnumerableRequests(string name)

public IRequestData GetSubRequest(string name)
{
return _requestData.GetSubRequest(name);
return _requestData.GetChildRequest(name);
}


Expand All @@ -80,6 +80,11 @@ public IContextValues Data
get { return _values.Value; }
}

public bool HasChildRequest(string name)
{
return _requestData.HasChildRequest(name);
}

public void ForProperty(PropertyInfo property, Action<IPropertyContext> action)
{
try
Expand Down
27 changes: 15 additions & 12 deletions src/FubuCore/Binding/CollectionPropertyBinder.cs
Expand Up @@ -2,7 +2,6 @@
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using FubuCore.Util;

namespace FubuCore.Binding
{
Expand All @@ -12,7 +11,7 @@ public class CollectionPropertyBinder : IPropertyBinder
public bool Matches(PropertyInfo property)
{
var propertyType = property.PropertyType;
if (propertyType == typeof(string)) return false;
if (propertyType == typeof (string)) return false;

return propertyType.Closes(typeof (IEnumerable<>));
}
Expand All @@ -26,10 +25,7 @@ public void Bind(PropertyInfo property, IBindingContext context)
builder.FillValues(property, context);
}

public interface IEnumerableBuilder
{
void FillValues(PropertyInfo property, IBindingContext context);
}
#region Nested type: EnumerableBuilder

public class EnumerableBuilder<T> : IEnumerableBuilder
{
Expand All @@ -44,16 +40,23 @@ public void FillValues(PropertyInfo property, IBindingContext context)

context.GetEnumerableRequests(property.Name).Each(request =>
{
context.Logger.PushElement(typeof(T));
context.Logger.PushElement(typeof (T));
// TODO -- got to add the BindResult to context to store it later
context.BindObject(request, typeof(T), @object =>
{
collection.Add((T)@object);
});
context.BindObject(request, typeof (T), @object => { collection.Add((T) @object); });
});
}
}

#endregion

#region Nested type: IEnumerableBuilder

public interface IEnumerableBuilder
{
void FillValues(PropertyInfo property, IBindingContext context);
}

#endregion
}
}
4 changes: 2 additions & 2 deletions src/FubuCore/Binding/EnumerateFlatRequestData.cs
Expand Up @@ -8,9 +8,9 @@ public static IEnumerable<IRequestData> For(IRequestData data, string prefix)
{
var indexer = new Indexer(prefix);

while (data.HasAnyValuePrefixedWith(indexer.Prefix))
while (data.HasChildRequest(indexer.Prefix))
{
yield return data.GetSubRequest(indexer.Prefix);
yield return data.GetChildRequest(indexer.Prefix);
indexer.Increment();
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/FubuCore/Binding/IBindingContext.cs
Expand Up @@ -70,5 +70,12 @@ public interface IBindingContext
/// Shortcut to get converted data from the raw request by name
/// </summary>
IContextValues Data { get; }

/// <summary>
/// Tests whether or not the underlying data has a child request
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
bool HasChildRequest(string name);
}
}
4 changes: 2 additions & 2 deletions src/FubuCore/Binding/IRequestData.cs
Expand Up @@ -7,9 +7,9 @@ public interface IRequestData
{
object Value(string key);
bool Value(string key, Action<BindingValue> callback);
bool HasAnyValuePrefixedWith(string key);
bool HasChildRequest(string key);

IRequestData GetSubRequest(string prefixOrChild);
IRequestData GetChildRequest(string prefixOrChild);
IEnumerable<IRequestData> GetEnumerableRequests(string prefixOrChild);
}
}
5 changes: 5 additions & 0 deletions src/FubuCore/Binding/NestedObjectPropertyBinder.cs
Expand Up @@ -15,6 +15,11 @@ public bool Matches(PropertyInfo property)

public void Bind(PropertyInfo property, IBindingContext context)
{
if (!context.HasChildRequest(property.Name))
{
return;
}

var childRequest = context.GetSubRequest(property.Name);
context.BindObject(childRequest, property.PropertyType, o =>
{
Expand Down
1 change: 0 additions & 1 deletion src/FubuCore/Binding/ObjectResolver.cs
@@ -1,6 +1,5 @@
using System;
using FubuCore.Binding.InMemory;
using FubuMVC.Core;


namespace FubuCore.Binding
Expand Down
6 changes: 3 additions & 3 deletions src/FubuCore/Binding/PrefixedRequestData.cs
Expand Up @@ -24,12 +24,12 @@ public bool Value(string key, Action<BindingValue> callback)
return _inner.Value(_prefix + key, callback);
}

public bool HasAnyValuePrefixedWith(string key)
public bool HasChildRequest(string key)
{
return _inner.HasAnyValuePrefixedWith(_prefix + key);
return _inner.HasChildRequest(_prefix + key);
}

public IRequestData GetSubRequest(string prefixOrChild)
public IRequestData GetChildRequest(string prefixOrChild)
{
return new PrefixedRequestData(_inner, _prefix + prefixOrChild);
}
Expand Down
4 changes: 2 additions & 2 deletions src/FubuCore/Binding/RequestData.cs
Expand Up @@ -38,7 +38,7 @@ public bool Value(string key, Action<BindingValue> callback)
return found;
}

public bool HasAnyValuePrefixedWith(string key)
public bool HasChildRequest(string key)
{
return _dictionary.HasAnyValuePrefixedWith(key);
}
Expand All @@ -54,7 +54,7 @@ public IEnumerable<string> GetKeys()
return _dictionary.GetAllKeys();
}

public IRequestData GetSubRequest(string prefixOrChild)
public IRequestData GetChildRequest(string prefixOrChild)
{
return new PrefixedRequestData(this, prefixOrChild);
}
Expand Down
4 changes: 2 additions & 2 deletions src/FubuCore/Binding/RequestDataBase.cs
Expand Up @@ -44,14 +44,14 @@ protected virtual bool hasValue(string key)
return _allKeys.Value.Contains(key);
}

public virtual bool HasAnyValuePrefixedWith(string key)
public virtual bool HasChildRequest(string key)
{
return _allKeys.Value.Any(x => x.StartsWith(key));
}

public abstract IEnumerable<string> GetKeys();

public IRequestData GetSubRequest(string prefixOrChild)
public IRequestData GetChildRequest(string prefixOrChild)
{
return new PrefixedRequestData(this, prefixOrChild);
}
Expand Down
4 changes: 2 additions & 2 deletions src/FubuCore/Configuration/SettingsRequestData.cs
Expand Up @@ -42,7 +42,7 @@ public bool Value(string key, Action<BindingValue> callback)



public bool HasAnyValuePrefixedWith(string key)
public bool HasChildRequest(string key)
{
return _steps.Any(x => x.HasAnyValuePrefixedWith(key));
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public IEnumerable<string> GetKeys()
return _steps.SelectMany(s => s.AllKeys);
}

public IRequestData GetSubRequest(string prefixOrChild)
public IRequestData GetChildRequest(string prefixOrChild)
{
return new PrefixedRequestData(this, prefixOrChild);
}
Expand Down
8 changes: 4 additions & 4 deletions src/FubuCore/Configuration/SubstitutedRequestData.cs
Expand Up @@ -38,14 +38,14 @@ public bool Value(string key, Action<BindingValue> callback)
});
}

public bool HasAnyValuePrefixedWith(string key)
public bool HasChildRequest(string key)
{
return _inner.HasAnyValuePrefixedWith(key);
return _inner.HasChildRequest(key);
}

public IRequestData GetSubRequest(string prefixOrChild)
public IRequestData GetChildRequest(string prefixOrChild)
{
var prefixedInner = _inner.GetSubRequest(prefixOrChild);
var prefixedInner = _inner.GetChildRequest(prefixOrChild);
return new SubstitutedRequestData(prefixedInner, _substitutions);
}

Expand Down
1 change: 0 additions & 1 deletion src/FubuCore/Configuration/XmlSettingsParser.cs
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using System.Xml;
using FubuCore.Util;
using FubuMVC.Core;

namespace FubuCore.Configuration
{
Expand Down
2 changes: 0 additions & 2 deletions src/FubuCore/Conversion/ConverterLibrary.cs
Expand Up @@ -41,8 +41,6 @@ public ConverterLibrary(IEnumerable<IObjectConverterFamily> families)
}


// TODO -- may need to do a seal() kind of thing that throws an exception after you call this.
// or clear the caches, one of the two
/// <summary>
/// Register a conversion strategy for a single type by a Func
/// </summary>
Expand Down
5 changes: 2 additions & 3 deletions src/FubuCore/FubuException.cs
@@ -1,8 +1,7 @@
using System;
using System.Runtime.Serialization;
using FubuCore;

namespace FubuMVC.Core
namespace FubuCore
{
[Serializable]
public class FubuException : Exception
Expand Down Expand Up @@ -48,7 +47,7 @@ public FubuException(int errorCode, string template, params string[] substitutio
{
}

public override string Message { get { return "FubuMVC Error {0}: \n{1}".ToFormat(_errorCode, _message); } }
public override string Message { get { return "FubuCore Error {0}: \n{1}".ToFormat(_errorCode, _message); } }

public int ErrorCode { get { return _errorCode; } }
}
Expand Down

0 comments on commit a565229

Please sign in to comment.