Skip to content

Commit

Permalink
Merge branch 'rel/2.0.0-preview2' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bricelam committed Jun 5, 2017
2 parents 3075c74 + e900873 commit 6a4a951
Show file tree
Hide file tree
Showing 33 changed files with 366 additions and 108 deletions.
2 changes: 1 addition & 1 deletion src/EFCore.Design/Design/Internal/DatabaseOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public virtual Task<ReverseEngineerFiles> ScaffoldContextAsync(
loggerFactory.AddProvider(new LoggerProvider(categoryName => new OperationLogger(categoryName, _reporter)));
#pragma warning restore CS0618 // Type or member is obsolete

var generator = services.GetRequiredService<ModelScaffolder>();
var generator = services.GetRequiredService<IModelScaffolder>();

return generator.GenerateAsync(
connectionString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public class CSharpDbContextGenerator
public class CSharpDbContextGenerator : ICSharpDbContextGenerator
{
private const string EntityLambdaIdentifier = "entity";

private readonly CSharpUtilities _cSharpUtilities;
private readonly ICSharpUtilities _cSharpUtilities;
private readonly IScaffoldingHelper _scaffoldingHelper;
private readonly IAnnotationRenderer _annotationRenderer;
private IndentedStringBuilder _sb;
Expand All @@ -37,7 +37,7 @@ public class CSharpDbContextGenerator
public CSharpDbContextGenerator(
[NotNull] IScaffoldingHelper scaffoldingHelper,
[NotNull] IAnnotationRenderer annotationRenderer,
[NotNull] CSharpUtilities cSharpUtilities)
[NotNull] ICSharpUtilities cSharpUtilities)
{
Check.NotNull(scaffoldingHelper, nameof(scaffoldingHelper));
Check.NotNull(annotationRenderer, nameof(annotationRenderer));
Expand All @@ -53,10 +53,10 @@ public CSharpDbContextGenerator(
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string WriteCode(
[NotNull] IModel model,
[NotNull] string @namespace,
[NotNull] string contextName,
[NotNull] string connectionString,
IModel model,
string @namespace,
string contextName,
string connectionString,
bool useDataAnnotations)
{
Check.NotNull(model, nameof(model));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public class CSharpEntityTypeGenerator
public class CSharpEntityTypeGenerator : ICSharpEntityTypeGenerator
{
private CSharpUtilities CSharpUtilities { get; }
private ICSharpUtilities CSharpUtilities { get; }

private IndentedStringBuilder _sb;
private bool _useDataAnnotations;
Expand All @@ -31,7 +31,7 @@ public class CSharpEntityTypeGenerator
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public CSharpEntityTypeGenerator(
[NotNull] CSharpUtilities cSharpUtilities)
[NotNull] ICSharpUtilities cSharpUtilities)
{
Check.NotNull(cSharpUtilities, nameof(cSharpUtilities));

Expand All @@ -42,7 +42,7 @@ public CSharpEntityTypeGenerator(
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string WriteCode([NotNull] IEntityType entityType, [NotNull] string @namespace, bool useDataAnnotations)
public virtual string WriteCode(IEntityType entityType, string @namespace, bool useDataAnnotations)
{
Check.NotNull(entityType, nameof(entityType));
Check.NotNull(@namespace, nameof(@namespace));
Expand Down
7 changes: 4 additions & 3 deletions src/EFCore.Design/Scaffolding/Internal/CSharpNamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
public class CSharpNamer<T>
{
private readonly Func<T, string> _nameGetter;
private readonly CSharpUtilities _cSharpUtilities;
private readonly ICSharpUtilities _cSharpUtilities;

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
Expand All @@ -27,12 +27,13 @@ public class CSharpNamer<T>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public CSharpNamer([NotNull] Func<T, string> nameGetter)
public CSharpNamer([NotNull] Func<T, string> nameGetter, [NotNull] ICSharpUtilities cSharpUtilities)
{
Check.NotNull(nameGetter, nameof(nameGetter));
Check.NotNull(cSharpUtilities, nameof(cSharpUtilities));

_nameGetter = nameGetter;
_cSharpUtilities = new CSharpUtilities();
_cSharpUtilities = cSharpUtilities;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ public class CSharpScaffoldingGenerator : ScaffoldingCodeGenerator
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual CSharpDbContextGenerator CSharpDbContextGenerator { get; }
public virtual ICSharpDbContextGenerator CSharpDbContextGenerator { get; }

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual CSharpEntityTypeGenerator CSharpEntityTypeGenerator { get; }
public virtual ICSharpEntityTypeGenerator CSharpEntityTypeGenerator { get; }

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public CSharpScaffoldingGenerator(
[NotNull] IFileService fileService,
[NotNull] CSharpDbContextGenerator cSharpDbContextGenerator,
[NotNull] CSharpEntityTypeGenerator cSharpEntityTypeGenerator)
[NotNull] ICSharpDbContextGenerator cSharpDbContextGenerator,
[NotNull] ICSharpEntityTypeGenerator cSharpEntityTypeGenerator)
: base(fileService)
{
Check.NotNull(cSharpDbContextGenerator, nameof(cSharpDbContextGenerator));
Expand Down
9 changes: 5 additions & 4 deletions src/EFCore.Design/Scaffolding/Internal/CSharpUniqueNamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class CSharpUniqueNamer<T> : CSharpNamer<T>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public CSharpUniqueNamer([NotNull] Func<T, string> nameGetter)
: this(nameGetter, null)
public CSharpUniqueNamer([NotNull] Func<T, string> nameGetter, [NotNull] ICSharpUtilities cSharpUtilities)
: this(nameGetter, null, cSharpUtilities)
{
}

Expand All @@ -29,8 +29,9 @@ public CSharpUniqueNamer([NotNull] Func<T, string> nameGetter)
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public CSharpUniqueNamer([NotNull] Func<T, string> nameGetter,
[CanBeNull] IEnumerable<string> usedNames)
: base(nameGetter)
[CanBeNull] IEnumerable<string> usedNames,
[NotNull] ICSharpUtilities cSharpUtilities)
: base(nameGetter, cSharpUtilities)
{
if (usedNames != null)
{
Expand Down
34 changes: 14 additions & 20 deletions src/EFCore.Design/Scaffolding/Internal/CSharpUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public class CSharpUtilities
public class CSharpUtilities : ICSharpUtilities
{
private static readonly HashSet<string> _cSharpKeywords = new HashSet<string>
{
Expand Down Expand Up @@ -108,13 +108,7 @@ private static readonly Regex _invalidCharsRegex
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public static CSharpUtilities Instance { get; } = new CSharpUtilities();

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string DelimitString([NotNull] string value)
public virtual string DelimitString(string value)
{
Check.NotNull(value, nameof(value));

Expand All @@ -127,7 +121,7 @@ public virtual string DelimitString([NotNull] string value)
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string EscapeString([NotNull] string str)
public virtual string EscapeString(string str)
{
Check.NotNull(str, nameof(str));

Expand All @@ -138,7 +132,7 @@ public virtual string EscapeString([NotNull] string str)
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string EscapeVerbatimString([NotNull] string str)
public virtual string EscapeVerbatimString(string str)
{
Check.NotEmpty(str, nameof(str));

Expand All @@ -149,7 +143,7 @@ public virtual string EscapeVerbatimString([NotNull] string str)
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string GenerateLiteral([NotNull] byte[] value)
public virtual string GenerateLiteral(byte[] value)
{
Check.NotNull(value, nameof(value));

Expand Down Expand Up @@ -232,7 +226,7 @@ public virtual string GenerateLiteral(Guid value)
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string GenerateLiteral([NotNull] string value)
public virtual string GenerateLiteral(string value)
{
Check.NotNull(value, nameof(value));

Expand All @@ -243,7 +237,7 @@ public virtual string GenerateLiteral([NotNull] string value)
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string GenerateVerbatimStringLiteral([NotNull] string value)
public virtual string GenerateVerbatimStringLiteral(string value)
{
Check.NotNull(value, nameof(value));

Expand All @@ -254,7 +248,7 @@ public virtual string GenerateVerbatimStringLiteral([NotNull] string value)
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string GenerateLiteral([NotNull] object value)
public virtual string GenerateLiteral(object value)
{
Check.NotNull(value, nameof(value));

Expand All @@ -270,24 +264,24 @@ public virtual string GenerateLiteral([NotNull] object value)
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual bool IsCSharpKeyword([NotNull] string identifier)
public virtual bool IsCSharpKeyword(string identifier)
=> _cSharpKeywords.Contains(identifier);

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string GenerateCSharpIdentifier(
[NotNull] string identifier, [CanBeNull] ICollection<string> existingIdentifiers)
string identifier, [CanBeNull] ICollection<string> existingIdentifiers)
=> GenerateCSharpIdentifier(identifier, existingIdentifiers, Uniquifier);

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string GenerateCSharpIdentifier(
[NotNull] string identifier, [CanBeNull] ICollection<string> existingIdentifiers,
[NotNull] Func<string, ICollection<string>, string> uniquifier)
string identifier, [CanBeNull] ICollection<string> existingIdentifiers,
Func<string, ICollection<string>, string> uniquifier)
{
Check.NotNull(identifier, nameof(identifier));
Check.NotNull(uniquifier, nameof(uniquifier));
Expand Down Expand Up @@ -321,7 +315,7 @@ public virtual string GenerateCSharpIdentifier(
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string Uniquifier(
[NotNull] string proposedIdentifier, [CanBeNull] ICollection<string> existingIdentifiers)
string proposedIdentifier, [CanBeNull] ICollection<string> existingIdentifiers)
{
Check.NotEmpty(proposedIdentifier, nameof(proposedIdentifier));

Expand Down Expand Up @@ -364,7 +358,7 @@ public virtual string Uniquifier(
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string GetTypeName([NotNull] Type type)
public virtual string GetTypeName(Type type)
{
Check.NotNull(type, nameof(type));

Expand Down
11 changes: 5 additions & 6 deletions src/EFCore.Design/Scaffolding/Internal/CandidateNamingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
Expand All @@ -16,13 +15,13 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public class CandidateNamingService
public class CandidateNamingService : ICandidateNamingService
{
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string GenerateCandidateIdentifier([NotNull] string originalIdentifier)
public virtual string GenerateCandidateIdentifier(string originalIdentifier)
{
Check.NotEmpty(originalIdentifier, nameof(originalIdentifier));

Expand Down Expand Up @@ -59,7 +58,7 @@ public virtual string GenerateCandidateIdentifier([NotNull] string originalIdent
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string GetDependentEndCandidateNavigationPropertyName([NotNull] IForeignKey foreignKey)
public virtual string GetDependentEndCandidateNavigationPropertyName(IForeignKey foreignKey)
{
Check.NotNull(foreignKey, nameof(foreignKey));

Expand All @@ -78,8 +77,8 @@ public virtual string GetDependentEndCandidateNavigationPropertyName([NotNull] I
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual string GetPrincipalEndCandidateNavigationPropertyName(
[NotNull] IForeignKey foreignKey,
[NotNull] string dependentEndNavigationPropertyName)
IForeignKey foreignKey,
string dependentEndNavigationPropertyName)
{
Check.NotNull(foreignKey, nameof(foreignKey));
Check.NotEmpty(dependentEndNavigationPropertyName, nameof(dependentEndNavigationPropertyName));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
public interface ICSharpDbContextGenerator
{
string WriteCode(
[NotNull] IModel model,
[NotNull] string @namespace,
[NotNull] string contextName,
[NotNull] string connectionString,
bool useDataAnnotations);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
{
public interface ICSharpEntityTypeGenerator
{
string WriteCode([NotNull] IEntityType entityType, [NotNull] string @namespace, bool useDataAnnotations);
}
}
Loading

0 comments on commit 6a4a951

Please sign in to comment.