Skip to content

Commit

Permalink
improve code consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
lofcz committed Jan 8, 2025
1 parent 64e38e0 commit 37abc82
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 153 deletions.
16 changes: 8 additions & 8 deletions FastCloner.Tests/ArrayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void Array_Of_Same_Arrays_Should_Be_Cloned()
Assert.That(ReferenceEquals(cloned[1], cloned[4]), Is.True);
}

public class AC
public class Ac
{
public int[] A { get; set; }

Expand All @@ -201,18 +201,18 @@ public class AC
[Test]
public void Class_With_Same_Arrays_Should_Be_Cloned()
{
AC ac = new AC();
Ac ac = new Ac();
ac.A = ac.B = new int[3];
AC clone = ac.DeepClone();
Ac clone = ac.DeepClone();
Assert.That(ReferenceEquals(ac.A, clone.A), Is.False);
Assert.That(ReferenceEquals(clone.A, clone.B), Is.True);
}

[Test]
public void Class_With_Null_Array_hould_Be_Cloned()
{
AC ac = new AC();
AC cloned = ac.DeepClone();
Ac ac = new Ac();
Ac cloned = ac.DeepClone();
Assert.That(cloned.A, Is.Null);
Assert.That(cloned.B, Is.Null);
}
Expand Down Expand Up @@ -271,9 +271,9 @@ public void MultiDim_Array_Should_Be_Cloned3()
[Test]
public void MultiDim_Array_Of_Classes_Should_Be_Cloned()
{
AC[,] arr = new AC[2, 2];
arr[0, 0] = arr[1, 1] = new AC();
AC[,] clone = arr.DeepClone();
Ac[,] arr = new Ac[2, 2];
arr[0, 0] = arr[1, 1] = new Ac();
Ac[,] clone = arr.DeepClone();
Assert.That(clone[0, 0], Is.Not.Null);
Assert.That(clone[1, 1], Is.Not.Null);
Assert.That(ReferenceEquals(clone[1, 1], clone[0, 0]));
Expand Down
6 changes: 3 additions & 3 deletions FastCloner.Tests/ConcurrentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ private class TestClassForSingleCallTest

private class CountHolder
{
private int _count;
public int Count => _count;
private int count;
public int Count => count;

public void Increment()
{
Interlocked.Increment(ref _count);
Interlocked.Increment(ref count);
}
}

Expand Down
2 changes: 1 addition & 1 deletion FastCloner.Tests/InheritanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void Struct_Casted_To_Interface_Should_Be_Cloned()
Assert.That(((S1)cloned).F, Is.EqualTo(1));
}

public IDisposable CCC(IDisposable xx)
public IDisposable Ccc(IDisposable xx)
{
S1 x = (S1)xx;
return x;
Expand Down
128 changes: 64 additions & 64 deletions FastCloner.Tests/SpecialCaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ public class C3 : CBase<int>
public class C2 : CBase<int>
{

public C3 c3 { get; set; } = new C3();
public C3 C3 { get; set; } = new C3();
}

public class C1 : CBase<int>
{
public C2 c2 { get; set; } = new C2();
public C2 C2 { get; set; } = new C2();
}

[Test]
Expand All @@ -240,10 +240,10 @@ public void Test_DeepClone_ClassHierarchy()
C1 original = new C1
{
Id = 1,
c2 = new C2
C2 = new C2
{
Id = 2,
c3 = new C3
C3 = new C3
{
Id = 3
}
Expand All @@ -258,10 +258,10 @@ public void Test_DeepClone_ClassHierarchy()
{
Assert.That(cloned1, Is.Not.SameAs(original));
Assert.That(cloned1.Id, Is.EqualTo(original.Id));
Assert.That(cloned1.c2, Is.Not.SameAs(original.c2));
Assert.That(cloned1.c2.Id, Is.EqualTo(original.c2.Id));
Assert.That(cloned1.c2.c3, Is.Not.SameAs(original.c2.c3));
Assert.That(cloned1.c2.c3.Id, Is.EqualTo(original.c2.c3.Id));
Assert.That(cloned1.C2, Is.Not.SameAs(original.C2));
Assert.That(cloned1.C2.Id, Is.EqualTo(original.C2.Id));
Assert.That(cloned1.C2.C3, Is.Not.SameAs(original.C2.C3));
Assert.That(cloned1.C2.C3.Id, Is.EqualTo(original.C2.C3.Id));
});
}

Expand Down Expand Up @@ -313,11 +313,11 @@ private class TestAutoProps
public string B { get; private set; } = "My string";
public int C => A * 2;

private int _d;
private int d;
public int D
{
get => _d;
set => _d = value;
get => d;
set => d = value;
}
}

Expand Down Expand Up @@ -377,8 +377,8 @@ public void ParallelCloning_WithReadOnlyFields_ShouldBeThreadSafe()

private class ClassWithReadOnlyField
{
private readonly string _readOnlyField = "test";
public string ReadOnlyValue => _readOnlyField;
private readonly string readOnlyField = "test";
public string ReadOnlyValue => readOnlyField;
}


Expand All @@ -391,12 +391,12 @@ private class TestAutoPropsWithIgnored

public int C => A * 2;

private int _d;
private int d;
[FastClonerIgnore]
public int D
{
get => _d;
set => _d = value;
get => d;
set => d = value;
}
}

Expand Down Expand Up @@ -1086,18 +1086,18 @@ public void NotifyPropertyChanged_With_Collection_Clone()
});
}

public class INotifyTest : INotifyPropertyChanged
public class NotifyTest : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

private string _prop;
private string prop;
public string Prop
{
get => _prop;
get => prop;

set
{
_prop = value;
prop = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Prop)));
}
}
Expand Down Expand Up @@ -1278,15 +1278,15 @@ public void Test_Notify_Triggered_Correctly()
{
// Arrange
List<string> output = [];
INotifyTest a = new INotifyTest();
NotifyTest a = new NotifyTest();
a.PropertyChanged += (sender, args) =>
{
output.Add(((INotifyTest)sender).Prop);
output.Add(((NotifyTest)sender).Prop);
};

// Act
a.Prop = "A changed";
INotifyTest b = a.DeepClone();
NotifyTest b = a.DeepClone();
b.Prop = "B changed";
b.Prop = "B changed again";

Expand All @@ -1297,77 +1297,77 @@ public void Test_Notify_Triggered_Correctly()

public class NotifyingPerson : INotifyPropertyChanged
{
private string _name;
private int _age;
private NotifyingAddress _address;
private ObservableCollection<NotifyingPerson> _children;
private string name;
private int age;
private NotifyingAddress address;
private ObservableCollection<NotifyingPerson> children;

public event PropertyChangedEventHandler PropertyChanged;

public string Name
{
get => _name;
get => name;
set
{
_name = value;
name = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Name)));
}
}

public int Age
{
get => _age;
get => age;
set
{
_age = value;
age = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Age)));
}
}

public NotifyingAddress Address
{
get => _address;
get => address;
set
{
_address = value;
address = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Address)));
}
}

public ObservableCollection<NotifyingPerson> Children
{
get => _children;
get => children;
set
{
_children = value;
children = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Children)));
}
}
}

public class NotifyingAddress : INotifyPropertyChanged
{
private string _street;
private string _city;
private string street;
private string city;

public event PropertyChangedEventHandler PropertyChanged;

public string Street
{
get => _street;
get => street;
set
{
_street = value;
street = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Street)));
}
}

public string City
{
get => _city;
get => city;
set
{
_city = value;
city = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(City)));
}
}
Expand Down Expand Up @@ -1525,22 +1525,22 @@ public void IReadOnlySet_Overlaps_ShouldWorkCorrectly()

public class ReadOnlySet<T> : IReadOnlySet<T>
{
private readonly ISet<T> _set;
private readonly ISet<T> set;

public ReadOnlySet(ISet<T> set)
{
_set = set ?? throw new ArgumentNullException(nameof(set));
this.set = set ?? throw new ArgumentNullException(nameof(set));
}

public int Count => _set.Count;
public bool Contains(T item) => _set.Contains(item);
public bool IsProperSubsetOf(IEnumerable<T> other) => _set.IsProperSubsetOf(other);
public bool IsProperSupersetOf(IEnumerable<T> other) => _set.IsProperSupersetOf(other);
public bool IsSubsetOf(IEnumerable<T> other) => _set.IsSubsetOf(other);
public bool IsSupersetOf(IEnumerable<T> other) => _set.IsSupersetOf(other);
public bool Overlaps(IEnumerable<T> other) => _set.Overlaps(other);
public bool SetEquals(IEnumerable<T> other) => _set.SetEquals(other);
public IEnumerator<T> GetEnumerator() => _set.GetEnumerator();
public int Count => set.Count;
public bool Contains(T item) => set.Contains(item);
public bool IsProperSubsetOf(IEnumerable<T> other) => set.IsProperSubsetOf(other);
public bool IsProperSupersetOf(IEnumerable<T> other) => set.IsProperSupersetOf(other);
public bool IsSubsetOf(IEnumerable<T> other) => set.IsSubsetOf(other);
public bool IsSupersetOf(IEnumerable<T> other) => set.IsSupersetOf(other);
public bool Overlaps(IEnumerable<T> other) => set.Overlaps(other);
public bool SetEquals(IEnumerable<T> other) => set.SetEquals(other);
public IEnumerator<T> GetEnumerator() => set.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
Expand Down Expand Up @@ -1811,9 +1811,9 @@ public class LazyClass
{
public static int Counter;

private readonly LazyRef<object> _lazyValue = new LazyRef<object>(() => (++Counter).ToString(CultureInfo.InvariantCulture));
private readonly LazyRef<object> lazyValue = new LazyRef<object>(() => (++Counter).ToString(CultureInfo.InvariantCulture));

public string GetValue() => _lazyValue.Value.ToString();
public string GetValue() => lazyValue.Value.ToString();
}

[Table("Currency", Schema = "Sales")]
Expand Down Expand Up @@ -1858,15 +1858,15 @@ public void Closure_Clone()
private class TestComparer : Comparer<int>
{
// make object unsafe to work
private object _fieldX = new object();
private object fieldX = new object();

public override int Compare(int x, int y) => x.CompareTo(y);
}

public sealed class LazyRef<T>
{
private Func<T> _initializer;
private T _value;
private Func<T> initializer;
private T value;

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
Expand All @@ -1876,21 +1876,21 @@ public T Value
{
get
{
if (_initializer != null)
if (initializer != null)
{
_value = _initializer();
_initializer = null;
value = initializer();
initializer = null;
}
return _value;
return value;
}
set
{
_value = value;
_initializer = null;
this.value = value;
initializer = null;
}
}

public LazyRef(Func<T> initializer) => _initializer = initializer;
public LazyRef(Func<T> initializer) => this.initializer = initializer;
}

[Test]
Expand Down
Loading

0 comments on commit 37abc82

Please sign in to comment.