Skip to content

Commit 2f41f11

Browse files
Clean up test helpers and fix warnings
1 parent f65ec38 commit 2f41f11

File tree

14 files changed

+53
-1058
lines changed

14 files changed

+53
-1058
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ dotnet_style_prefer_simplified_interpolation = true:warning
144144
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#implicit-and-explicit-types
145145
csharp_style_var_for_built_in_types = never
146146
csharp_style_var_when_type_is_apparent = true:warning
147-
csharp_style_var_elsewhere = false:warning
147+
csharp_style_var_elsewhere = true:warning
148148
# Expression-bodied members
149149
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-bodied-members
150150
csharp_style_expression_bodied_methods = true:suggestion

src/Umbraco.Deploy.Contrib/Extensions/ArtifactTypeResolverCollectionBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Umbraco.Deploy.Contrib.Connectors.Serialization;
1+
using Umbraco.Deploy.Contrib.Connectors.Serialization;
22
using Umbraco.Deploy.Serialization;
33

44
namespace Umbraco.Extensions

src/Umbraco.Deploy.Contrib/GridCellValueConnectors/DocTypeGridEditorCellValueConnector.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using Newtonsoft.Json;
44
using Newtonsoft.Json.Linq;
55
using Umbraco.Core;
6+
using Umbraco.Core.Composing;
67
using Umbraco.Core.Deploy;
78
using Umbraco.Core.Logging;
89
using Umbraco.Core.Models;
@@ -23,7 +24,18 @@ public class DocTypeGridEditorCellValueConnector : GridCellValueConnectorBase2
2324

2425
private ValueConnectorCollection ValueConnectors => _valueConnectorsLazy.Value;
2526

27+
[Obsolete("Please use the constructor taking all parameters. This constructor will be removed in a future version.")]
2628
public DocTypeGridEditorCellValueConnector(ILogger logger, IContentTypeService contentTypeService, Lazy<ValueConnectorCollection> valueConnectors)
29+
: this(
30+
Current.Factory.GetInstance<IEntityService>(),
31+
Current.Factory.GetInstance<ILocalLinkParser>(),
32+
logger,
33+
contentTypeService,
34+
valueConnectors)
35+
{ }
36+
37+
public DocTypeGridEditorCellValueConnector(IEntityService entityService, ILocalLinkParser localLinkParser, ILogger logger, IContentTypeService contentTypeService, Lazy<ValueConnectorCollection> valueConnectors)
38+
: base(entityService, localLinkParser)
2739
{
2840
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
2941
_contentTypeService = contentTypeService ?? throw new ArgumentNullException(nameof(contentTypeService));
@@ -127,11 +139,8 @@ public sealed override void SetValue(GridValue.GridControl gridControl, IContext
127139
_logger.Debug<DocTypeGridEditorCellValueConnector>($"SetValue - ContentTypeAlias - {docTypeGridEditorContent.ContentTypeAlias}");
128140

129141
// check if the doc type exist - else abort packaging
130-
var contentType = contextCache.GetContentTypeByAlias(_contentTypeService, docTypeGridEditorContent.ContentTypeAlias);
131-
if (contentType == null)
132-
{
133-
throw new InvalidOperationException($"Could not resolve the Content Type for the Doc Type Grid Editor property: {docTypeGridEditorContent.ContentTypeAlias}");
134-
}
142+
var contentType = contextCache.GetContentTypeByAlias(_contentTypeService, docTypeGridEditorContent.ContentTypeAlias)
143+
?? throw new InvalidOperationException($"Could not resolve the Content Type for the Doc Type Grid Editor property: {docTypeGridEditorContent.ContentTypeAlias}");
135144

136145
_logger.Debug<DocTypeGridEditorCellValueConnector>($"SetValue - ContentType - {contentType}");
137146

src/Umbraco.Deploy.Contrib/Migrators/Legacy/ContentType/ElementTypeArtifactMigratorBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Linq;
1+
using System.Linq;
22
using Semver;
33
using Umbraco.Deploy.Artifacts.ContentType;
44
using Umbraco.Deploy.Migrators;

src/Umbraco.Deploy.Contrib/Serialization/LegacyArtifactTypeResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Semver;
1+
using Semver;
22
using Umbraco.Deploy.Serialization;
33

44
namespace Umbraco.Deploy.Contrib.Connectors.Serialization

src/Umbraco.Deploy.Contrib/ValueConnectors/BlockEditorValueConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using Newtonsoft.Json;

src/Umbraco.Deploy.Contrib/ValueConnectors/BlockListValueConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using Umbraco.Core.Logging;
44
using Umbraco.Core.Services;

src/Umbraco.Deploy.Contrib/ValueConnectors/MultiUrlPickerValueConnector.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Text.RegularExpressions;
44
using Newtonsoft.Json;
@@ -64,7 +64,6 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
6464
}
6565

6666
var valueAsJToken = JToken.Parse(svalue);
67-
6867
if (valueAsJToken is JArray)
6968
{
7069
// Multiple links, parse as JArray
@@ -114,9 +113,9 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
114113
}
115114
else if (isMedia && TryParseJTokenAttr(link, "url", out string url))
116115
{
117-
// This state can happen due to an issue in RJP.MultiUrlPicker(or our linkPicker in RTE which it relies on),
118-
// where you edit a media link, and just hit "Select".
119-
// That will set the id to null, but the url will still be filled. We try to get the media item, and if so add it as
116+
// This state can happen due to an issue in RJP.MultiUrlPicker(or our linkPicker in RTE which it relies on),
117+
// where you edit a media link, and just hit "Select".
118+
// That will set the id to null, but the url will still be filled. We try to get the media item, and if so add it as
120119
// a dependency to the package. If we can't find it, we abort(aka continue)
121120
var entry = _mediaService.GetMediaByPath(url);
122121
if (entry == null)
@@ -132,6 +131,7 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
132131
link["url"] = udi.ToString();
133132
}
134133
}
134+
135135
return JsonConvert.SerializeObject(links);
136136
}
137137

@@ -145,11 +145,9 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
145145
}
146146

147147
var isMedia = link["isMedia"] != null;
148-
int intId;
149-
string url;
150-
GuidUdi guidUdi;
148+
151149
// Only do processing if the Id is set on the element. OR if the url is set and its a media item
152-
if (TryParseJTokenAttr(link, "id", out intId))
150+
if (TryParseJTokenAttr(link, "id", out int intId))
153151
{
154152
// Checks weather we are resolving a media item or a document
155153
var objectTypeId = isMedia
@@ -169,19 +167,19 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
169167
link["id"] = udi.ToString();
170168
}
171169
}
172-
else if (TryParseJTokenAttr(link, "udi", out guidUdi))
170+
else if (TryParseJTokenAttr(link, "udi", out GuidUdi guidUdi))
173171
{
174172
if (contextCache.EntityExists(_entityService, guidUdi.Guid))
175173
{
176174
// Add the artifact dependency
177175
dependencies.Add(new ArtifactDependency(guidUdi, false, ArtifactDependencyMode.Exist));
178176
}
179177
}
180-
else if (isMedia && TryParseJTokenAttr(link, "url", out url))
178+
else if (isMedia && TryParseJTokenAttr(link, "url", out string url))
181179
{
182-
// This state can happen due to an issue in RJP.MultiUrlPicker(or our linkPicker in RTE which it relies on),
183-
// where you edit a media link, and just hits "Select".
184-
// That will set the id to null, but the url will still be filled. We try to get the media item, and if so add it as
180+
// This state can happen due to an issue in RJP.MultiUrlPicker(or our linkPicker in RTE which it relies on),
181+
// where you edit a media link, and just hits "Select".
182+
// That will set the id to null, but the url will still be filled. We try to get the media item, and if so add it as
185183
// a dependency to the package. If we can't find it, we abort(aka continue)
186184
var entry = _mediaService.GetMediaByPath(url);
187185
if (entry != null)
@@ -194,10 +192,11 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
194192
link["url"] = udi.ToString();
195193
}
196194
}
195+
197196
return JsonConvert.SerializeObject(link);
198197
}
199198

200-
//if none of the above...
199+
// If none of the above...
201200
return string.Empty;
202201
}
203202

@@ -209,19 +208,16 @@ public sealed override object FromArtifact(string value, PropertyType propertyTy
209208
}
210209

211210
var valueAsJToken = JToken.Parse(value);
212-
213211
if (valueAsJToken is JArray)
214212
{
215-
//Multiple links, parse as JArray
213+
// Multiple links, parse as JArray
216214
var links = JsonConvert.DeserializeObject<JArray>(value);
217215
if (links != null)
218216
{
219217
foreach (var link in links)
220218
{
221-
GuidUdi udi;
222-
string url;
223219
// Only do processing on an item if the Id or the url is set
224-
if (TryParseJTokenAttr(link, "id", out udi))
220+
if (TryParseJTokenAttr(link, "id", out GuidUdi udi))
225221
{
226222
// Check the type of the link
227223
var nodeObjectType = link["isMedia"] != null
@@ -237,15 +233,15 @@ public sealed override object FromArtifact(string value, PropertyType propertyTy
237233
link["id"] = idAttempt.Success ? idAttempt.Result : 0;
238234
}
239235
}
240-
else if (TryParseJTokenAttr(link, "url", out url))
236+
else if (TryParseJTokenAttr(link, "url", out string url))
241237
{
242238
// Check whether the url attribute of the link contains a udi, if so, replace it with the
243239
// path to the file, i.e. the regex replaces <udi> with /path/to/file
244240
var newUrl = MediaUdiSrcRegex.Replace(url, match =>
245241
{
246242
var udiString = match.Groups["udi"].ToString();
247-
GuidUdi foundUdi;
248-
if (GuidUdi.TryParse(udiString, out foundUdi) && foundUdi.EntityType == Constants.UdiEntityType.Media)
243+
if (GuidUdi.TryParse(udiString, out var foundUdi) &&
244+
foundUdi.EntityType == Constants.UdiEntityType.Media)
249245
{
250246
// (take care of nulls)
251247
var media = _mediaService.GetById(foundUdi.Guid);
@@ -254,23 +250,24 @@ public sealed override object FromArtifact(string value, PropertyType propertyTy
254250
return media.GetUrl("umbracoFile", _logger);
255251
}
256252
}
253+
257254
return string.Empty;
258255
});
256+
259257
link["url"] = newUrl;
260258
}
261259
}
260+
262261
value = JsonConvert.SerializeObject(links);
263262
}
264263
}
265264
else if (valueAsJToken is JObject)
266265
{
267-
//Single link, parse as JToken
266+
// Single link, parse as JToken
268267
var link = JsonConvert.DeserializeObject<JToken>(value);
269268

270-
GuidUdi udi;
271-
string url;
272269
// Only do processing on an item if the Id or the url is set
273-
if (TryParseJTokenAttr(link, "id", out udi))
270+
if (TryParseJTokenAttr(link, "id", out GuidUdi udi))
274271
{
275272
// Check the type of the link
276273
var nodeObjectType = link["isMedia"] != null
@@ -286,15 +283,14 @@ public sealed override object FromArtifact(string value, PropertyType propertyTy
286283
link["id"] = idAttempt.Success ? idAttempt.Result : 0;
287284
}
288285
}
289-
else if (TryParseJTokenAttr(link, "url", out url))
286+
else if (TryParseJTokenAttr(link, "url", out string url))
290287
{
291-
// Check whether the url attribute of the link contains a udi, if so, replace it with the
288+
// Check whether the url attribute of the link contains a udi, if so, replace it with the
292289
// path to the file, i.e. the regex replaces <udi> with /path/to/file
293290
var newUrl = MediaUdiSrcRegex.Replace(url, match =>
294291
{
295292
var udiString = match.Groups["udi"].ToString();
296-
GuidUdi foundUdi;
297-
if (GuidUdi.TryParse(udiString, out foundUdi) &&
293+
if (GuidUdi.TryParse(udiString, out var foundUdi) &&
298294
foundUdi.EntityType == Constants.UdiEntityType.Media)
299295
{
300296
// (take care of nulls)
@@ -307,6 +303,7 @@ public sealed override object FromArtifact(string value, PropertyType propertyTy
307303

308304
return string.Empty;
309305
});
306+
310307
link["url"] = newUrl;
311308
}
312309

@@ -323,6 +320,7 @@ private bool TryParseJTokenAttr(JToken link, string attrName, out int attrValue)
323320
var val = link[attrName].ToString();
324321
return int.TryParse(val, out attrValue);
325322
}
323+
326324
attrValue = 0;
327325
return false;
328326
}
@@ -334,6 +332,7 @@ private bool TryParseJTokenAttr(JToken link, string attrName, out GuidUdi attrVa
334332
var val = link[attrName].ToString();
335333
return GuidUdi.TryParse(val, out attrValue);
336334
}
335+
337336
attrValue = null;
338337
return false;
339338
}
@@ -349,7 +348,8 @@ private bool TryParseJTokenAttr(JToken link, string attrName, out string strAttr
349348
return true;
350349
}
351350
}
352-
strAttr = "";
351+
352+
strAttr = string.Empty;
353353
return false;
354354
}
355355
}

tests/Umbraco.Deploy.Contrib.Tests/TestHelpers/MemoryFileTypeCollection.cs

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)