Skip to content

Commit 3c49c77

Browse files
committed
Merge pull request #14 from Tynamix/FEATURE_BetterLogging
Logging each exception msg to Debug.WriteLine before throwing. Simplifie...
2 parents dcc7ebe + a5824e2 commit 3c49c77

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

ObjectFiller/Filler.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Configuration;
5+
using System.Diagnostics;
56
using System.Globalization;
67
using System.Linq;
78
using System.Reflection;
@@ -123,8 +124,9 @@ private object CreateInstanceOfType(Type type, ObjectFillerSetup currentSetup)
123124

124125
if (constructorArgs.Count == 0)
125126
{
126-
throw new InvalidOperationException("Could not found a constructor for type [" + type.Name +
127-
"] where the parameters can be filled with the current objectfiller setup");
127+
var message = "Could not found a constructor for type [" + type.Name + "] where the parameters can be filled with the current objectfiller setup";
128+
Debug.WriteLine("ObjectFiller: " + message);
129+
throw new InvalidOperationException(message);
128130
}
129131
}
130132
}
@@ -316,13 +318,12 @@ private IDictionary GetFilledDictionary(Type propertyType, ObjectFillerSetup cur
316318

317319
if (dictionary.Contains(keyObject))
318320
{
319-
throw new ArgumentException(
320-
string.Format(
321-
"Generating Keyvalue failed because it generates always the same data for type [{0}]. Please check your setup.",
322-
keyType));
321+
string message = string.Format("Generating Keyvalue failed because it generates always the same data for type [{0}]. Please check your setup.", keyType);
322+
Debug.WriteLine("ObjectFiller: " + message);
323+
throw new ArgumentException(message);
323324
}
324325

325-
object valueObject = GetFilledObject(valueType, currentSetup);
326+
object valueObject = GetFilledObject(valueType, currentSetup);
326327
dictionary.Add(keyObject, valueObject);
327328
}
328329
return dictionary;
@@ -382,12 +383,12 @@ private object GetInterfaceInstance(Type interfaceType, ObjectFillerSetup setup)
382383
{
383384
if (setup.InterfaceMocker == null)
384385
{
385-
throw new InvalidOperationException(
386-
string.Format("ObjectFiller Interface mocker missing and type [{0}] not registered",
387-
interfaceType.Name));
386+
string message = string.Format("ObjectFiller Interface mocker missing and type [{0}] not registered", interfaceType.Name);
387+
Debug.WriteLine("ObjectFiller: " + message);
388+
throw new InvalidOperationException(message);
388389
}
389390

390-
MethodInfo method = setup.InterfaceMocker.GetType().GetMethod("Create");
391+
MethodInfo method = setup.InterfaceMocker.GetType().GetMethod("Create");
391392
MethodInfo genericMethod = method.MakeGenericMethod(new[] { interfaceType });
392393
result = genericMethod.Invoke(setup.InterfaceMocker, null);
393394
}
@@ -402,7 +403,9 @@ private object GetRandomValue(Type propertyType, ObjectFillerSetup setup)
402403
return setup.TypeToRandomFunc[propertyType]();
403404
}
404405

405-
throw new TypeInitializationException(propertyType.FullName, new Exception("The type [" + propertyType.Name + "] was not registered in the randomizer."));
406+
string message = "The type [" + propertyType.Name + "] was not registered in the randomizer.";
407+
Debug.WriteLine("ObjectFiller: " + message);
408+
throw new TypeInitializationException(propertyType.FullName, new Exception(message));
406409
}
407410

408411
private static bool TypeIsValidForObjectFiller(Type type, ObjectFillerSetup currentSetup)

ObjectFiller/Plugins/EnumeratorPlugin.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34

45
namespace Tynamix.ObjectFiller
56
{
@@ -31,7 +32,9 @@ public T GetValue()
3132

3233
if (!hasNext)
3334
{
34-
throw new Exception("Unable to get next value from enumeration " + _enumerable);
35+
string message = "Unable to get next value from enumeration " + _enumerable;
36+
Debug.WriteLine("ObjectFiller: " + message);
37+
throw new Exception(message);
3538
}
3639
}
3740

ObjectFiller/Plugins/RandomListItem.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34

45
namespace Tynamix.ObjectFiller
56
{
@@ -11,9 +12,11 @@ public RandomListItem(List<T> allAvailableValues)
1112
{
1213
if (allAvailableValues == null || allAvailableValues.Count == 0)
1314
{
14-
throw new ArgumentException("List in RandomListItem ranomizer can not be empty!");
15+
const string message = "List in RandomListItem ranomizer can not be empty!";
16+
Debug.WriteLine("ObjectFiller: " + message);
17+
throw new ArgumentException(message);
1518
}
16-
_allAvailableValues = allAvailableValues;
19+
_allAvailableValues = allAvailableValues;
1720

1821
}
1922

ObjectFiller/Plugins/String/PatternGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ private static char NextChar(char charClass)
251251
if (charClass == 'A') return NextUpperCaseChar();
252252
if (charClass == 'N') return NextDecimalDigit();
253253
if (charClass == 'X') return NextHexDigit();
254+
255+
var message = "Unexpected character class: " + charClass;
256+
Debug.WriteLine("ObjectFiller: " + message);
254257
throw new InvalidOperationException();
255258
}
256259

ObjectFiller/Setup/FluentFillerApi.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Linq.Expressions;
45
using System.Reflection;
56

@@ -114,9 +115,11 @@ public FluentFillerApi<TTargetObject> SetInterfaceMocker(IInterfaceMocker mocker
114115
{
115116
if (SetupManager.GetFor<TTargetObject>().InterfaceMocker != null)
116117
{
117-
throw new ArgumentException("You can not set a interface mocker more than once!");
118+
const string message = "You can not set a interface mocker more than once!";
119+
Debug.WriteLine("ObjectFiller: " + message);
120+
throw new ArgumentException(message);
118121
}
119-
SetupManager.GetFor<TTargetObject>().InterfaceMocker = mocker;
122+
SetupManager.GetFor<TTargetObject>().InterfaceMocker = mocker;
120123
return this;
121124
}
122125

0 commit comments

Comments
 (0)