Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek-galezowski committed Mar 7, 2024
1 parent 3f9262d commit 9869ee9
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/netstandard2.0/AnyExtensibility/BasicGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public interface BasicGenerator
{
[Obsolete("Do not use this method. It does not generate strings")]
[EditorBrowsable(EditorBrowsableState.Never)]
string ToString();
string? ToString();

T Instance<T>();
T Instance<T>(params GenerationCustomization[] customizations);
T InstanceOf<T>(InlineGenerator<T> gen);
}
}
4 changes: 2 additions & 2 deletions src/netstandard2.0/AnyGenerators/Root/InlineGenerators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ public static InlineGenerator<Dictionary<TKey, TValue>> Dictionary<TKey, TValue>
// Used by reflection
// public API
// ReSharper disable once UnusedMember.Global
public static InlineGenerator<IReadOnlyDictionary<TKey, TValue>> ReadOnlyDictionary<TKey, TValue>()
public static InlineGenerator<IReadOnlyDictionary<TKey, TValue>> ReadOnlyDictionary<TKey, TValue>() where TKey : notnull
{
return InternalInlineGenerators.ReadOnlyDictionary<TKey, TValue>();
}

public static InlineGenerator<IReadOnlyDictionary<TKey, TValue>> ReadOnlyDictionary<TKey, TValue>(int length)
public static InlineGenerator<IReadOnlyDictionary<TKey, TValue>> ReadOnlyDictionary<TKey, TValue>(int length) where TKey : notnull
{
return InternalInlineGenerators.ReadOnlyDictionary<TKey, TValue>(length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static Dictionary<TKey, TValue> Dictionary<TKey, TValue>(this BasicGenera
return gen.InstanceOf(InlineGenerators.Dictionary<TKey, TValue>());
}

public static IReadOnlyDictionary<TKey, TValue> ReadOnlyDictionary<TKey, TValue>(this BasicGenerator gen, int length)
public static IReadOnlyDictionary<TKey, TValue> ReadOnlyDictionary<TKey, TValue>(this BasicGenerator gen, int length) where TKey : notnull
{
return gen.InstanceOf(InlineGenerators.ReadOnlyDictionary<TKey, TValue>(length));
}
Expand All @@ -176,7 +176,7 @@ public static IReadOnlyDictionary<TKey, TValue> ReadOnlyDictionaryWithKeys<TKey,
return gen.InstanceOf(InlineGenerators.DictionaryWithKeys<TKey, TValue>(keys));
}

public static IReadOnlyDictionary<TKey, TValue> ReadOnlyDictionary<TKey, TValue>(this BasicGenerator gen)
public static IReadOnlyDictionary<TKey, TValue> ReadOnlyDictionary<TKey, TValue>(this BasicGenerator gen) where TKey : notnull
{
return gen.InstanceOf(InlineGenerators.ReadOnlyDictionary<TKey, TValue>());
}
Expand Down
1 change: 1 addition & 0 deletions src/netstandard2.0/BuildScript/BuildScript.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/netstandard2.0/TypeResolution/AllGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public T Dummy<T>(GenerationRequest request)

public T OtherThan<T>(params T[]? omittedValues)
{
return (T)OtherThan(typeof(T), omittedValues?.Cast<object>()?.ToArray(), DefaultGenerationRequest.WithDefaultLimits());
return (T)OtherThan(typeof(T), omittedValues?.Cast<object>()?.ToArray() ?? [], DefaultGenerationRequest.WithDefaultLimits());
}

public object OtherThan(Type type, object[] skippedValues, GenerationRequest request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ namespace TddXt.TypeResolution.FakeChainElements.DummyChainElements;

public class FallbackDummyObjectResolution : IResolution
{
public object? Apply(InstanceGenerator allGenerator, GenerationRequest generationRequest, Type type)
public object Apply(InstanceGenerator allGenerator, GenerationRequest generationRequest, Type type)
{
object result;
try
{
result = SmartType.For(type).GetPublicParameterlessConstructor().Value().Invoke(Enumerable.Empty<object>());
}
catch (Exception e)
catch
{
result = FormatterServices.GetUninitializedObject(type);

}
generationRequest.CustomizeCreatedValue(result, allGenerator);
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using TddXt.AnyExtensibility;

namespace TddXt.TypeResolution.FakeChainElements.InlineGeneratorTypes.Collections;

public class DictionaryWithKeysGenerator<TKey, TValue>(IEnumerable<TKey> keys)
: InlineGenerator<Dictionary<TKey, TValue>>
: InlineGenerator<Dictionary<TKey, TValue>> where TKey : notnull
{
public Dictionary<TKey, TValue> GenerateInstance(InstanceGenerator instanceGenerator, GenerationRequest request)
{
var dict = new Dictionary<TKey, TValue>();

foreach (var key in keys)
{
dict.Add(key, instanceGenerator.Instance<TValue>(request));
}

return dict;
return keys.ToDictionary(key => key, key => instanceGenerator.Instance<TValue>(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ public object ResolveNextNestingLevel(
Trace.RecursionLimitReachedTryingDummy();
return instanceGenerator.Dummy(nestedRequest, type)!;
}
catch (TargetInvocationException e)
catch (TargetInvocationException)
{
return default!;
}
catch (MemberAccessException e)
catch (MemberAccessException)
{
return default!;
}
catch (ArgumentException e)
catch (ArgumentException)
{
return default!;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ public static InlineGenerator<List<T>> ListWith<T>(T[] included)
return new InclusiveEnumerableGenerator<T>(included).AsList();
}

public static InlineGenerator<SortedList<TKey, TValue>> SortedList<TKey, TValue>(int length)
public static InlineGenerator<SortedList<TKey, TValue>> SortedList<TKey, TValue>(int length) where TKey : notnull
{
return new EnumerableGenerator<KeyValuePair<TKey, TValue>>(ManyStrategies.FromConstant(length)).AsSortedList();
}

public static InlineGenerator<SortedList<TKey, TValue>> SortedList<TKey, TValue>()
public static InlineGenerator<SortedList<TKey, TValue>> SortedList<TKey, TValue>() where TKey : notnull
{
return new EnumerableGenerator<KeyValuePair<TKey, TValue>>(
ManyStrategies.FromRequest()).AsSortedList();
Expand Down Expand Up @@ -186,33 +186,33 @@ public static InlineGenerator<SortedSet<T>> SortedSet<T>()
return new EnumerableGenerator<T>(ManyStrategies.FromRequest()).AsSortedSet();
}

public static InlineGenerator<Dictionary<TKey, TValue>> Dictionary<TKey, TValue>(int length)
public static InlineGenerator<Dictionary<TKey, TValue>> Dictionary<TKey, TValue>(int length) where TKey : notnull
{
return new EnumerableGenerator<KeyValuePair<TKey, TValue>>(ManyStrategies.FromConstant(length)).AsDictionary();
}

// Used by reflection
// public API
// ReSharper disable once UnusedMember.Global
public static InlineGenerator<IReadOnlyDictionary<TKey, TValue>> ReadOnlyDictionary<TKey, TValue>()
public static InlineGenerator<IReadOnlyDictionary<TKey, TValue>> ReadOnlyDictionary<TKey, TValue>() where TKey : notnull
{
return new EnumerableGenerator<KeyValuePair<TKey, TValue>>(ManyStrategies.FromRequest()).AsReadOnlyDictionary();
}

public static InlineGenerator<IReadOnlyDictionary<TKey, TValue>> ReadOnlyDictionary<TKey, TValue>(int length)
public static InlineGenerator<IReadOnlyDictionary<TKey, TValue>> ReadOnlyDictionary<TKey, TValue>(int length) where TKey : notnull
{
return new EnumerableGenerator<KeyValuePair<TKey, TValue>>(ManyStrategies.FromConstant(length)).AsReadOnlyDictionary();
}

// Used by reflection
// public API
// ReSharper disable once UnusedMember.Global
public static InlineGenerator<Dictionary<TKey, TValue>> Dictionary<TKey, TValue>()
public static InlineGenerator<Dictionary<TKey, TValue>> Dictionary<TKey, TValue>() where TKey : notnull
{
return new EnumerableGenerator<KeyValuePair<TKey, TValue>>(ManyStrategies.FromRequest()).AsDictionary();
}

public static InlineGenerator<ConcurrentDictionary<TKey, TValue>> ConcurrentDictionary<TKey, TValue>(int length)
public static InlineGenerator<ConcurrentDictionary<TKey, TValue>> ConcurrentDictionary<TKey, TValue>(int length) where TKey : notnull
{
return new EnumerableGenerator<KeyValuePair<TKey, TValue>>(ManyStrategies.FromConstant(length))
.AsConcurrentDictionary();
Expand All @@ -221,7 +221,7 @@ public static InlineGenerator<ConcurrentDictionary<TKey, TValue>> ConcurrentDict
// Used by reflection
// public API
// ReSharper disable once UnusedMember.Global
public static InlineGenerator<ConcurrentDictionary<TKey, TValue>> ConcurrentDictionary<TKey, TValue>()
public static InlineGenerator<ConcurrentDictionary<TKey, TValue>> ConcurrentDictionary<TKey, TValue>() where TKey : notnull
{
return new EnumerableGenerator<KeyValuePair<TKey, TValue>>(ManyStrategies.FromRequest())
.AsConcurrentDictionary();
Expand Down Expand Up @@ -253,7 +253,7 @@ public static InlineGenerator<ConcurrentQueue<T>> ConcurrentQueue<T>()
return new EnumerableGenerator<T>(ManyStrategies.FromRequest()).AsConcurrentQueue();
}

public static InlineGenerator<SortedDictionary<TKey, TValue>> SortedDictionary<TKey, TValue>(int length)
public static InlineGenerator<SortedDictionary<TKey, TValue>> SortedDictionary<TKey, TValue>(int length) where TKey : notnull
{
return new EnumerableGenerator<KeyValuePair<TKey, TValue>>(ManyStrategies.FromConstant(length))
.AsSortedDictionary();
Expand All @@ -262,7 +262,7 @@ public static InlineGenerator<SortedDictionary<TKey, TValue>> SortedDictionary<T
// Used by reflection
// public API
// ReSharper disable once UnusedMember.Global
public static InlineGenerator<SortedDictionary<TKey, TValue>> SortedDictionary<TKey, TValue>()
public static InlineGenerator<SortedDictionary<TKey, TValue>> SortedDictionary<TKey, TValue>() where TKey : notnull
{
return new EnumerableGenerator<KeyValuePair<TKey, TValue>>(ManyStrategies.FromRequest())
.AsSortedDictionary();
Expand Down Expand Up @@ -298,7 +298,7 @@ public static InlineGenerator<T> From<T>(T[] possibleValues)
return new GeneratorByPickingFromSpecifiedSetOfValues<T>(possibleValues);
}

public static InlineGenerator<Dictionary<TKey, TValue>> DictionaryWithKeys<TKey, TValue>(IEnumerable<TKey> keys)
public static InlineGenerator<Dictionary<TKey, TValue>> DictionaryWithKeys<TKey, TValue>(IEnumerable<TKey> keys) where TKey : notnull
{
return new DictionaryWithKeysGenerator<TKey, TValue>(keys);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public IntegerSequence(int startingValue, int step, int initialStepsCount)

}

public bool Equals(IntegerSequence other)
public bool Equals(IntegerSequence? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return _startingValue == other._startingValue && _step == other._step;
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Core.NullableReferenceTypesExtensions;
using TddXt.AnyExtensibility;
using TddXt.TypeResolution.FakeChainElements.InlineGeneratorTypes;

Expand All @@ -13,7 +14,7 @@ public bool AppliesTo(Type type)

public object Apply(InstanceGenerator instanceGenerator, GenerationRequest request, Type type)
{
var elementType = type.GetElementType();
var elementType = type.GetElementType().OrThrow();
var array = InternalInlineGenerators.GetByNameAndType(nameof(InternalInlineGenerators.Array), elementType)
.GenerateInstance(instanceGenerator, request);
return array;
Expand Down

0 comments on commit 9869ee9

Please sign in to comment.