Skip to content

Commit

Permalink
1.0.5 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
MCKanpolat committed Mar 1, 2018
1 parent 30436d4 commit 947d679
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/StubGenerator.Test.Models/ModelWithComplexTypeProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public ModelConstructorHasParameters(int intField)
}


public class UnsupportedTypes
{
public byte[] ByteArray { get; set; }
}


public class ModelConstructorMixed
{
public ModelConstructorMixed()
Expand Down
8 changes: 4 additions & 4 deletions src/StubGenerator.Test/CacheManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public CacheManagerTests()
_stubTypeMemoryCache = new MemoryStubTypeCache(_cacheKeyGenerator);
}

[Fact(DisplayName = "Cache_Key_Generator_Test")]
[Fact(DisplayName = "Cache Key Generator Test")]
public void CacheKeyGeneratorTest()
{
var cacheKey = _cacheKeyGenerator.GenerateKey<PersonDto>();
Assert.NotEmpty(cacheKey);
}

[Fact(DisplayName = "Should add PropertyInfo Cache Successfully")]
[Fact(DisplayName = "Should Add PropertyInfo Cache Successfully")]
public void Should_Add_PropertyInfos_To_Cache_Successfully()
{
var personData = new PersonDto();
Expand All @@ -33,7 +33,7 @@ public void Should_Add_PropertyInfos_To_Cache_Successfully()
}


[Fact(DisplayName = "Memory_Cache_Manager_Empty_Test")]
[Fact(DisplayName = "Ensure Memory Cache Manager Empty")]
public void CacheManagerEmptyTest()
{
var personData = new PersonDto();
Expand All @@ -43,7 +43,7 @@ public void CacheManagerEmptyTest()
}


[Fact(DisplayName = "Memory_Cache_Manager_Concurrency_Test")]
[Fact(DisplayName = "Memory Cache Manager Concurrency")]
public void CacheManagerConcurrencyTest()
{
var personData = new PersonDto();
Expand Down
9 changes: 9 additions & 0 deletions src/StubGenerator.Test/StubManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,14 @@ public void Should_Generate_Data_For_Complex_Type_Properties_Check_Parameterless
Assert.NotNull(generatedStubData.ModelConstructorMixed);
Assert.Null(generatedStubData.ModelConstructorHasParameters);
}


[Fact(DisplayName = "Check Unsupported Types")]
public void Check_Unsupported_Types()
{
var generatedStubData = _stubManager.CreateNew<UnsupportedTypes>();
Assert.NotNull(generatedStubData);
Assert.Null(generatedStubData.ByteArray);
}
}
}
19 changes: 11 additions & 8 deletions src/StubMiddleware.Core/Core/StubManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,18 @@ private void FillPropertiesWithFakeData<TObject>(TObject obj, PropertyInfo[] pro
foreach (PropertyInfo property in propertyInfos)
{
if (property.PropertyType.IsCollectionType())
{
var collectionTypeInstance = Activator.CreateInstance(property.PropertyType);
var complexType = property.PropertyType.GetGenericArguments()[0];
property.SetValue(obj, collectionTypeInstance);
for (var i = 0; i < listItemSize; i++)
{ /*check the type has parameterless constructor*/
if ((property.PropertyType.GetConstructor(Type.EmptyTypes) != null))
{
dynamic item = Activator.CreateInstance(complexType);
FillPropertiesWithFakeData(item, _stubTypeCache.GetOrAdd(item, property.PropertyType.GetGenericArguments()[0].GetProperties()));
collectionTypeInstance.GetType().GetMethod("Add").Invoke(collectionTypeInstance, new[] { item });
var collectionTypeInstance = Activator.CreateInstance(property.PropertyType);
var complexType = property.PropertyType.GetGenericArguments()[0];
property.SetValue(obj, collectionTypeInstance);
for (var i = 0; i < listItemSize; i++)
{
dynamic item = Activator.CreateInstance(complexType);
FillPropertiesWithFakeData(item, _stubTypeCache.GetOrAdd(item, property.PropertyType.GetGenericArguments()[0].GetProperties()));
collectionTypeInstance.GetType().GetMethod("Add").Invoke(collectionTypeInstance, new[] { item });
}
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/StubMiddleware.Core/StubGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageProjectUrl>https://github.com/MCKanpolat/StubMiddleware</PackageProjectUrl>
<RepositoryUrl>https://github.com/MCKanpolat/StubMiddleware</RepositoryUrl>
<PackageTags>stub stubgenerator</PackageTags>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
<Description>Stub Data Generator for .net core</Description>
</PropertyGroup>

Expand Down
5 changes: 3 additions & 2 deletions src/StubMiddleware/StubMiddleware.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<Copyright></Copyright>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Description>Stub Data Generator Middleware for Asp.Net core</Description>
<AssemblyVersion>1.0.4.0</AssemblyVersion>
<Version>1.0.4</Version>
<AssemblyVersion>1.0.5.0</AssemblyVersion>
<Version>1.0.5</Version>
<FileVersion>1.0.5.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 947d679

Please sign in to comment.