Skip to content

Fix Bug #132 #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2022
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
4 changes: 2 additions & 2 deletions ObjectFillerNET.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0EC5FD26-A565-4D47-A192-0FC142C3B7F0}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tynamix.ObjectFiller.Test.BugfixTests
{
[TestClass]
public class Bug132PropertiesOnBaseClassesNotPopulatedBeyond2Levels
{
public class BaseId
{
public string Id { get; set; }
}

public class BaseWithAudit : BaseId
{
public string CreatedBy { get; set; }
public string UpdatedBy { get; set; }
}

public class Person : BaseWithAudit
{
public string Name { get; set; }
public string LastName { get; set; }
}
[TestMethod]
public void Bug132PropertiesOnBaseClassNotPopulated()
{
var filler = new Filler<Person>();
var x = filler.Create();
Assert.IsFalse(string.IsNullOrWhiteSpace(x.Name));
Assert.IsFalse(string.IsNullOrWhiteSpace(x.LastName));
Assert.IsFalse(string.IsNullOrWhiteSpace(x.CreatedBy));
Assert.IsFalse(string.IsNullOrWhiteSpace(x.UpdatedBy));
Assert.IsFalse(string.IsNullOrWhiteSpace(x.Id));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Tynamix.ObjectFiller.Test.BugfixTests
{

[TestClass]
public class Bug68HashsetCanNotBeCreated
{
[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace Tynamix.ObjectFiller.Test.BugfixTests
{

[TestClass]
public class Bug89FillTypesInheritsFromDictionary
{
public class EntityA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace Tynamix.ObjectFiller.Test.BugfixTests
{

[TestClass]
public class Bug89FillTypesInheritsFromList
{
public class EntityA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Tynamix.ObjectFiller.Test.BugfixTests
using System.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;


public class OrderWithObject
{
public IReadOnlyCollection<Book> OrderLines { get; set; }
Expand Down
5 changes: 4 additions & 1 deletion Tynamix.ObjectFiller.Test/CollectionizerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ public class CollectionizerPoco

public List<int> IntRange { get; set; }

#if !NET6
public ArrayList ArrayList { get; set; }

#endif
public string[] StringArray { get; set; }
}

[TestClass]
public class CollectionizerTest
{
#if !NET6
[TestMethod]
public void TestCityNames()
{
Expand All @@ -31,6 +33,7 @@ public void TestCityNames()
Assert.IsTrue(arrayList.ArrayList.Count >= 3 && arrayList.ArrayList.Count <= 10);
Assert.IsTrue(arrayList.ArrayList.ToArray().Cast<string>().All(x => x.Length >= 20 && x.Length <= 25));
}
#endif

[TestMethod]
public void TestMnemonicStringPlugin()
Expand Down
35 changes: 20 additions & 15 deletions Tynamix.ObjectFiller.Test/Tynamix.ObjectFiller.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net6;net48</TargetFrameworks>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Tynamix.ObjectFiller\Tynamix.ObjectFiller.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project>
<ItemGroup>
<ProjectReference Include="..\Tynamix.ObjectFiller\Tynamix.ObjectFiller.csproj" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net6'">
<DefineConstants>NET6</DefineConstants>
</PropertyGroup>


</Project>
39 changes: 28 additions & 11 deletions Tynamix.ObjectFiller/NetTypeApiExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,12 @@ internal static IEnumerable<PropertyInfo> GetProperties(this Type source, bool i
{
#if NETSTANDARD

var propertyInfos = source.GetTypeInfo().DeclaredProperties.ToList();

if (ignoreInheritance == false && source.GetTypeInfo().BaseType != null)
if (ignoreInheritance)
{
foreach (var property in source.GetTypeInfo().BaseType.GetTypeInfo().DeclaredProperties)
{
if (!propertyInfos.Any(x => x.Name == property.Name))
{
propertyInfos.Add(property);
}
}
return source.GetTypeInfo().DeclaredProperties.ToList();
}
return propertyInfos;

return GetDeclaredPropertyInfosRecursive(new List<PropertyInfo>(), source.GetTypeInfo());
#else

if (ignoreInheritance)
Expand All @@ -127,6 +120,30 @@ internal static IEnumerable<PropertyInfo> GetProperties(this Type source, bool i

}

#if NETSTANDARD

internal static List<PropertyInfo> GetDeclaredPropertyInfosRecursive(List<PropertyInfo> propertyInfos, TypeInfo typeInfo)
{
foreach (var property in typeInfo.DeclaredProperties)
{
if (!propertyInfos.Any(x => x.Name == property.Name))
{
propertyInfos.Add(property);
}
}

if(typeInfo.BaseType != null)
{
return GetDeclaredPropertyInfosRecursive(propertyInfos, typeInfo.BaseType.GetTypeInfo());
}

return propertyInfos;
}

#endif



internal static Type[] GetGenericTypeArguments(this Type source)
{
#if NETSTANDARD
Expand Down
22 changes: 15 additions & 7 deletions Tynamix.ObjectFiller/Tynamix.ObjectFiller.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.0;netstandard1.3;netstandard2.0;net35;net40;net45;net451;net452;</TargetFrameworks>
<TargetFrameworks>netstandard1.0;netstandard1.3;netstandard2.0;net35;net452;</TargetFrameworks>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<Version>1.5.6</Version>
<Authors>Roman Lautner, Hendrik L., Christian Harlass, GothikX</Authors>
<Company>Tynamix</Company>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageProjectUrl>http://objectfiller.net/</PackageProjectUrl>
<PackageIconUrl></PackageIconUrl>
<PackageReleaseNotes>-1.5.6
* Added target framework nertstandard1.3, netstandard2.0 to improve easier usage with .NET 5
<PackageReleaseNotes>-1.5.7
* Fix multi inheritance bug on .NET Standard

-1.5.6
* Added target framework netstandard1.3, netstandard2.0 to improve easier usage with .NET 5
* Added Long Range plugin (thx to weitzhandler)

-1.5.5
Expand Down Expand Up @@ -153,14 +156,19 @@
-1.0.0
* Initial release</PackageReleaseNotes>
<PackageTags>objectfiller tynamix test testdata prototyp prototyping unittest design designviewmodel generator random data randomdata testing poco lorem ipsum fakedata fake faker</PackageTags>
<Description>The Tynamix ObjectFiller.NET fills the properties of your objects with random data. Use it for unittest, prototyping and whereever you need some random testdata. It has a fluent API and is highly customizable. It supports also IEnumerables and Dictionaries and constructors WITH parameters. It is also possible to fill instances and to write private properties.</Description>
<Description>The Tynamix ObjectFiller.NET fills the properties of your objects with random data.
Use it for unittest, prototyping and whereever you need some random testdata.

It has a fluent API and is highly customizable.
It supports also IEnumerables and Dictionaries and constructors WITH parameters.
It is also possible to fill instances and to write private properties.</Description>
<RepositoryUrl>https://github.com/Tynamix/ObjectFiller.NET</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Copyright>Copyright ©Roman Lautner 2021</Copyright>
<Copyright>Copyright ©Roman Lautner 2022</Copyright>
<DocumentationFile>bin\Debug\Tynamix.ObjectFiller.xml</DocumentationFile>
<AssemblyVersion>1.5.6</AssemblyVersion>
<FileVersion>1.5.6</FileVersion>
<AssemblyVersion>1.5.7</AssemblyVersion>
<FileVersion>1.5.7</FileVersion>
<PackageIcon>logo.png</PackageIcon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
os: Visual Studio 2017
os: Visual Studio 2022

install:
- dotnet restore
Expand Down