Permalink
Browse files

Validated that Faker can now be used in production, albiet on a limit…

…ed basis until we make the interface more extensible and aware of business rules
  • Loading branch information...
Aaronontheweb committed Mar 18, 2012
1 parent aa4ad7e commit de4a9b6fa9befaac0ae7dc107ed90841bf8b5a45
Showing with 91 additions and 3 deletions.
  1. +81 −0 Faker.Tests/FakeTests/FakeTests.cs
  2. +2 −2 Faker/Fake.cs
  3. +8 −1 Faker/Matcher.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+
+namespace Faker.Tests.FakeTests
+{
+ /// <summary>
+ /// Testing harnesss for validating that Faker itself can get the job done
+ /// </summary>
+ [TestFixture(Description = "Tests that validate that Faker behaves as expected")]
+ public class FakeTests
+ {
+
+ #region Test classes
+
+ public class Project
+ {
+ public Guid ProjectId { get; set; }
+
+ public Guid ApiKey { get; set; }
+
+ public string ProjectSlug { get; set; }
+
+ public string ProjectName { get; set; }
+
+ public string ProjectDescription { get; set; }
+
+ public DateTime DateCreated { get; set; }
+
+ public DateTime LastActivity { get; set; }
+
+ public ProjectType TargetOS { get; set; }
+
+ public IList<AppVersion> Versions { get; set; }
+
+ public Project()
+ {
+ Versions = new List<AppVersion>();
+ }
+ }
+
+ public enum ProjectType
+ {
+ iOS,
+ Android,
+ WindowsPhone
+ };
+
+ public class AppVersion
+ {
+ public Guid VersionId { get; set; }
+
+ public string VersionSlug { get; set; }
+
+ public string VersionName { get; set; }
+ }
+
+
+ #endregion
+
+ #region Setup / Teardown
+ #endregion
+
+ #region Tests
+
+ [Test(Description = "Should be able to fake a single instance of a rich class")]
+ public void Should_Fake_Single_Instance_Of_Rich_Class()
+ {
+ var fake = new Fake<Project>();
+
+ var projectInstance = fake.Generate();
+
+ Assert.IsNotNull(projectInstance);
+ Assert.IsTrue(projectInstance.Versions.Count > 0);
+ }
+
+ #endregion
+ }
+}
View
@@ -26,7 +26,7 @@ public Fake()
/// Generates a single fake value for a given type
/// </summary>
/// <returns>A populated instance of a given class</returns>
- T Generate()
+ public T Generate()
{
//create a new instance of the type we want to Fake
var instance = (T)Matcher.SafeObjectCreate(typeof(T));
@@ -42,7 +42,7 @@ T Generate()
/// Generates a list of fake values for a given type
/// </summary>
/// <returns>A list of populated instances with length [count] of a given class</returns>
- IList<T> Generate(int count)
+ public IList<T> Generate(int count)
{
//Create a list to hold all of the fakes we want to return back to the caller
var items = new List<T>();
View
@@ -172,7 +172,14 @@ protected virtual void ProcessProperty(PropertyInfo property, object targetObjec
/// <returns>true if it's an array, false otherwise</returns>
protected virtual bool IsArray(Type targetType)
{
- return typeof(IList).IsAssignableFrom(targetType);
+ if (!targetType.IsGenericType)
+ return false;
+ var genericArguments = targetType.GetGenericArguments();
+ if (genericArguments.Length != 1)
+ return false;
+
+ var listType = typeof(IList<>).MakeGenericType(genericArguments);
+ return listType.IsAssignableFrom(targetType);
}
/// <summary>

0 comments on commit de4a9b6

Please sign in to comment.