Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removing ability to create types which have not been setup

  • Loading branch information...
commit fb92cc9fff4d4884ac8f73515b166846d21ba60b 1 parent af1c407
James Brechtel authored
View
2  Plant.Core/BasePlant.cs
@@ -68,7 +68,7 @@ private CreationStrategy StrategyFor<T>()
{
if(creationStrategies.ContainsKey(typeof(T)))
return creationStrategies[typeof (T)];
- return CreationStrategy.Property;
+ throw new TypeNotSetupException(string.Format("No creation strategy defined for type: {0}", typeof(T)));
}
View
1  Plant.Core/Plant.Core.csproj
@@ -48,6 +48,7 @@
<Compile Include="LazyProperty.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PropertyNotFoundException.cs" />
+ <Compile Include="TypeNotSetupException.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
View
11 Plant.Core/TypeNotSetupException.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace Plant.Core
+{
+ public class TypeNotSetupException : Exception
+ {
+ public TypeNotSetupException(string message) : base(message)
+ {
+ }
+ }
+}
View
20 Plant.Tests/BasePlantTest.cs
@@ -13,13 +13,18 @@ public class BasePlantTest
[Test]
public void Should_Create_Instance_Of_Specified_Type()
{
- Assert.IsInstanceOf(typeof(Person), new BasePlant().Create<Person>());
+ var plant = new BasePlant();
+ plant.DefinePropertiesOf<Person>(new { FirstName = "" });
+
+ Assert.IsInstanceOf(typeof(Person), plant.Create<Person>());
}
[Test]
public void Should_Create_Instance_With_Requested_Properties()
{
- Assert.AreEqual("James", new BasePlant().Create<Person>(new { FirstName = "James" }).FirstName);
+ var plant = new BasePlant();
+ plant.DefinePropertiesOf<Person>(new { FirstName=""});
+ Assert.AreEqual("James", plant.Create<Person>(new { FirstName = "James" }).FirstName);
}
[Test]
@@ -34,13 +39,16 @@ public void Should_Use_Default_Instance_Values()
[ExpectedException(typeof(PropertyNotFoundException))]
public void Should_Throw_PropertyNotFound_Exception_When_Given_Invalid_Property()
{
- new BasePlant().Create<Person>(new { Foo = "Nothing" });
+ var plant = new BasePlant();
+ plant.DefinePropertiesOf<Person>(new { FirstName = "" });
+ plant.Create<Person>(new { Foo = "Nothing" });
}
[Test]
- public void Should_Setup_Type_Without_Defaults()
+ [ExpectedException(typeof(TypeNotSetupException))]
+ public void Should_Throw_TypeNotSetupException_When_Trying_To_Create_Type_That_Is_Not_Setup()
{
- Assert.AreEqual("Barbara", new BasePlant().Create<Person>(new { FirstName = "Barbara" }).FirstName);
+ new BasePlant().Create<Person>(new {FirstName = "Barbara"});
}
[Test]
@@ -67,7 +75,7 @@ public void Should_Lazily_Evaluate_Delegate_Properties()
[Test]
[ExpectedException(typeof(LazyPropertyHasWrongTypeException))]
- public void Should_Give_Reasonable_Exception_When_Lazy_Property_Definition_Returns_Wrong_Type()
+ public void Should_Throw_LazyPropertyHasWrongTypeException_When_Lazy_Property_Definition_Returns_Wrong_Type()
{
var plant = new BasePlant();
plant.DefinePropertiesOf<Person>(new
Please sign in to comment.
Something went wrong with that request. Please try again.