Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace ObjectFiller.Test.BugfixTests
{
using Tynamix.ObjectFiller;



[TestClass]
public class Bug87ErrorWhenNameInParentIsSameAsParent
{
public class Parent
Expand All @@ -29,11 +29,16 @@ public class Child
public void ParentShallGetFilledWithourError()
{
Filler<Parent> filler = new Filler<Parent>();
filler.Setup()
.OnProperty(x => x.MakeTheError).Use(12345)
.SetupFor<Child>()
.OnProperty(x => x.MakeTheError).Use("TEST");

var filledObject = filler.Create();
Assert.IsNotNull(filledObject);
Assert.IsNotNull(filledObject.MakeTheError);
Assert.AreEqual(12345, filledObject.MakeTheError);
Assert.IsFalse(string.IsNullOrWhiteSpace(filledObject.Child.MakeTheError));
Assert.AreEqual("TEST", filledObject.Child.MakeTheError);
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions Tynamix.ObjectFiller.Test/SpecifyListCount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections.Generic;

namespace Tynamix.ObjectFiller.Test
{
using Microsoft.VisualStudio.TestTools.UnitTesting;

public class SimpleList
{
public List<string> Strings10 { get; set; }
public ICollection<string> Strings2050 { get; set; }
public string[] Strings50100 { get; set; }

public int Item { get; set; }
}

[TestClass]
public class TestSpecifyListCount
{

[TestMethod]
public void Generate10Strings()
{
Filler<SimpleList> filler = new Filler<SimpleList>();

filler.Setup()
.OnProperty(x => x.Strings10).Use(new Collectionizer<string, CityName>(1,10))
.OnProperty(x => x.Strings2050).Use(new Collectionizer<string, StreetName>(20, 50))
.OnProperty(x => x.Strings50100).Use(new Collectionizer<string, RealNames>(50, 100))
.OnProperty(x => x.Item).Use(1);

var result = filler.Create();

Assert.IsTrue(result.Strings10.Count > 0 && result.Strings10.Count <= 10);
Assert.IsTrue(result.Strings2050.Count >= 20 && result.Strings2050.Count <= 50);
Assert.IsTrue(result.Strings50100.Length >= 50 && result.Strings50100.Length <= 100);
}
}
}
1 change: 1 addition & 0 deletions Tynamix.ObjectFiller.Test/Tynamix.ObjectFiller.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Compile Include="SaveFillerSetupTest.cs" />
<Compile Include="SequenceGeneratorTest.cs" />
<Compile Include="SetupTests.cs" />
<Compile Include="SpecifyListCount.cs" />
<Compile Include="StreetNamesPluginTest.cs" />
<Compile Include="TestIgnoranceOfInheritance.cs" />
<Compile Include="TestPoco\Library\Book.cs" />
Expand Down
4 changes: 3 additions & 1 deletion Tynamix.ObjectFiller/Filler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,9 @@ private IEnumerable<PropertyInfo> GetPropertyFromProperties(
IEnumerable<PropertyInfo> properties,
PropertyInfo property)
{
return properties.Where(x => x.Name == property.Name && x.Module.Equals(property.Module));
return properties.Where(x => x.Name == property.Name
&& x.Module.Equals(property.Module)
&& x.DeclaringType?.AssemblyQualifiedName == property.DeclaringType?.AssemblyQualifiedName);
}

/// <summary>
Expand Down
12 changes: 11 additions & 1 deletion Tynamix.ObjectFiller/Plugins/List/Collectionizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Tynamix.ObjectFiller
/// </summary>
/// <typeparam name="T">Typeparameter of of the target List</typeparam>
/// <typeparam name="TRandomizer">Plugin which will be used to create the List</typeparam>
public class Collectionizer<T, TRandomizer> : IRandomizerPlugin<List<T>>
public class Collectionizer<T, TRandomizer> : IRandomizerPlugin<List<T>>, IRandomizerPlugin<T[]>
#if !NETSTANDARD1_0
, IRandomizerPlugin<ArrayList>
#endif
Expand Down Expand Up @@ -110,6 +110,15 @@ public List<T> GetValue()
return result;
}

/// <summary>
/// Gets random data for type <see cref="T"/>
/// </summary>
/// <returns>Random data for type <see cref="T"/></returns>
T[] IRandomizerPlugin<T[]>.GetValue()
{
return this.GetValue().ToArray();
}

#if !NETSTANDARD1_0
/// <summary>
/// Gets random data for type <see cref="T"/>
Expand All @@ -123,6 +132,7 @@ ArrayList IRandomizerPlugin<ArrayList>.GetValue()
return arrayList;
}
#endif

}

}