diff --git a/src/StubGenerator.Test.Models/ModelWithComplexTypeProperty.cs b/src/StubGenerator.Test.Models/ModelWithComplexTypeProperty.cs index baba616..0dfd21c 100644 --- a/src/StubGenerator.Test.Models/ModelWithComplexTypeProperty.cs +++ b/src/StubGenerator.Test.Models/ModelWithComplexTypeProperty.cs @@ -58,6 +58,12 @@ public ModelConstructorHasParameters(int intField) } + public class UnsupportedTypes + { + public byte[] ByteArray { get; set; } + } + + public class ModelConstructorMixed { public ModelConstructorMixed() diff --git a/src/StubGenerator.Test/CacheManagerTests.cs b/src/StubGenerator.Test/CacheManagerTests.cs index 535a755..3fe64a6 100644 --- a/src/StubGenerator.Test/CacheManagerTests.cs +++ b/src/StubGenerator.Test/CacheManagerTests.cs @@ -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(); 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(); @@ -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(); @@ -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(); diff --git a/src/StubGenerator.Test/StubManagerTests.cs b/src/StubGenerator.Test/StubManagerTests.cs index d782287..f8084b9 100644 --- a/src/StubGenerator.Test/StubManagerTests.cs +++ b/src/StubGenerator.Test/StubManagerTests.cs @@ -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(); + Assert.NotNull(generatedStubData); + Assert.Null(generatedStubData.ByteArray); + } } } diff --git a/src/StubMiddleware.Core/Core/StubManager.cs b/src/StubMiddleware.Core/Core/StubManager.cs index 181974e..d392a4a 100644 --- a/src/StubMiddleware.Core/Core/StubManager.cs +++ b/src/StubMiddleware.Core/Core/StubManager.cs @@ -73,15 +73,18 @@ private void FillPropertiesWithFakeData(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 diff --git a/src/StubMiddleware.Core/StubGenerator.csproj b/src/StubMiddleware.Core/StubGenerator.csproj index 9768918..dd97277 100644 --- a/src/StubMiddleware.Core/StubGenerator.csproj +++ b/src/StubMiddleware.Core/StubGenerator.csproj @@ -9,7 +9,7 @@ https://github.com/MCKanpolat/StubMiddleware https://github.com/MCKanpolat/StubMiddleware stub stubgenerator - 1.0.4 + 1.0.5 Stub Data Generator for .net core diff --git a/src/StubMiddleware/StubMiddleware.csproj b/src/StubMiddleware/StubMiddleware.csproj index 2b24410..4968897 100644 --- a/src/StubMiddleware/StubMiddleware.csproj +++ b/src/StubMiddleware/StubMiddleware.csproj @@ -11,8 +11,9 @@ false Stub Data Generator Middleware for Asp.Net core - 1.0.4.0 - 1.0.4 + 1.0.5.0 + 1.0.5 + 1.0.5.0