Skip to content

Commit 3513dd1

Browse files
author
Bart Koelman
committed
AV1708: Do not use 'Helper' or 'Shared' in type names
1 parent d273ce1 commit 3513dd1

File tree

5 files changed

+63
-51
lines changed

5 files changed

+63
-51
lines changed

src/JsonApiDotNetCore/Errors/NonSharedTransactionException.cs renamed to src/JsonApiDotNetCore/Errors/NonParticipatingTransactionException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace JsonApiDotNetCore.Errors
88
/// The error that is thrown when a repository does not participate in the overarching transaction during an atomic:operations request.
99
/// </summary>
1010
[PublicAPI]
11-
public sealed class NonSharedTransactionException : JsonApiException
11+
public sealed class NonParticipatingTransactionException : JsonApiException
1212
{
13-
public NonSharedTransactionException()
13+
public NonParticipatingTransactionException()
1414
: base(new Error(HttpStatusCode.UnprocessableEntity)
1515
{
1616
Title = "Unsupported combination of resource types in atomic:operations request.",

src/JsonApiDotNetCore/Repositories/ResourceRepositoryAccessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private object GetWriteRepository(Type resourceType)
156156

157157
if (repository.TransactionId != _request.TransactionId)
158158
{
159-
throw new NonSharedTransactionException();
159+
throw new NonParticipatingTransactionException();
160160
}
161161
}
162162

src/JsonApiDotNetCore/TypeHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
using JsonApiDotNetCore.Resources;
88
using JsonApiDotNetCore.Resources.Annotations;
99

10+
// TODO: Refactor TypeHelper into separate responsibilities
11+
1012
#pragma warning disable AV1008 // Class should not be static
13+
#pragma warning disable AV1708 // Type name contains term that should be avoided
1114

1215
namespace JsonApiDotNetCore
1316
{
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using JsonApiDotNetCore;
3+
using JsonApiDotNetCore.Resources;
4+
using Xunit;
5+
6+
namespace UnitTests.Internal
7+
{
8+
public sealed class TypeAnalysisTests
9+
{
10+
[Fact]
11+
public void New_Creates_An_Instance_If_T_Implements_Interface()
12+
{
13+
// Arrange
14+
Type type = typeof(Model);
15+
16+
// Act
17+
var instance = (IIdentifiable)TypeHelper.CreateInstance(type);
18+
19+
// Assert
20+
Assert.NotNull(instance);
21+
Assert.IsType<Model>(instance);
22+
}
23+
24+
[Fact]
25+
public void Implements_Returns_True_If_Type_Implements_Interface()
26+
{
27+
// Arrange
28+
Type type = typeof(Model);
29+
30+
// Act
31+
bool result = TypeHelper.IsOrImplementsInterface(type, typeof(IIdentifiable));
32+
33+
// Assert
34+
Assert.True(result);
35+
}
36+
37+
[Fact]
38+
public void Implements_Returns_False_If_Type_DoesNot_Implement_Interface()
39+
{
40+
// Arrange
41+
Type type = typeof(string);
42+
43+
// Act
44+
bool result = TypeHelper.IsOrImplementsInterface(type, typeof(IIdentifiable));
45+
46+
// Assert
47+
Assert.False(result);
48+
}
49+
50+
private sealed class Model : IIdentifiable
51+
{
52+
public string StringId { get; set; }
53+
public string LocalId { get; set; }
54+
}
55+
}
56+
}

test/UnitTests/Internal/TypeHelperTests.cs renamed to test/UnitTests/Internal/TypeConversionTests.cs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
22
using System.Collections.Generic;
33
using JsonApiDotNetCore;
4-
using JsonApiDotNetCore.Resources;
54
using Xunit;
65

76
namespace UnitTests.Internal
87
{
9-
public sealed class TypeHelperTests
8+
public sealed class TypeConversionTests
109
{
1110
[Fact]
1211
public void Can_Convert_DateTimeOffsets()
@@ -131,46 +130,6 @@ public void Bad_TimeSpanString_Throws()
131130
Assert.Throws<FormatException>(action);
132131
}
133132

134-
[Fact]
135-
public void New_Creates_An_Instance_If_T_Implements_Interface()
136-
{
137-
// Arrange
138-
Type type = typeof(Model);
139-
140-
// Act
141-
var instance = (IIdentifiable)TypeHelper.CreateInstance(type);
142-
143-
// Assert
144-
Assert.NotNull(instance);
145-
Assert.IsType<Model>(instance);
146-
}
147-
148-
[Fact]
149-
public void Implements_Returns_True_If_Type_Implements_Interface()
150-
{
151-
// Arrange
152-
Type type = typeof(Model);
153-
154-
// Act
155-
bool result = TypeHelper.IsOrImplementsInterface(type, typeof(IIdentifiable));
156-
157-
// Assert
158-
Assert.True(result);
159-
}
160-
161-
[Fact]
162-
public void Implements_Returns_False_If_Type_DoesNot_Implement_Interface()
163-
{
164-
// Arrange
165-
Type type = typeof(string);
166-
167-
// Act
168-
bool result = TypeHelper.IsOrImplementsInterface(type, typeof(IIdentifiable));
169-
170-
// Assert
171-
Assert.False(result);
172-
}
173-
174133
private enum TestEnum
175134
{
176135
Test = 1
@@ -187,11 +146,5 @@ private class BaseType : IType
187146
private interface IType
188147
{
189148
}
190-
191-
private sealed class Model : IIdentifiable
192-
{
193-
public string StringId { get; set; }
194-
public string LocalId { get; set; }
195-
}
196149
}
197150
}

0 commit comments

Comments
 (0)