Skip to content

Commit

Permalink
Test - Add CamelCaseNaming Converter unit test
Browse files Browse the repository at this point in the history
Resolves #2
  • Loading branch information
amaitland committed Jul 23, 2020
1 parent 426b4c5 commit 0ae176b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright © 2020 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using Xunit;
using CefSharp.Extensions.ModelBinding;

namespace CefSharp.Extensions.Test.ModelBinding
{
public class ModelBindingExtensionsFacts
{
[Theory]
[InlineData("A", "A")]
[InlineData("AB", "AB")]
[InlineData("AString", "aString")]
[InlineData("aString", "aString")]
public void ConvertStringToCamelCaseTheory(string input, string expected)
{
var actual = input.ConvertNameToCamelCase();

Assert.Equal(expected, actual);
}
}
}
7 changes: 7 additions & 0 deletions CefSharp.Extensions/CefSharp.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@
</None>
</ItemGroup>

<ItemGroup>
<!-- As per https://www.meziantou.net/declaring-internalsvisibleto-in-the-csproj.htm -->
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>CefSharp.Extensions.Test</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
20 changes: 5 additions & 15 deletions CefSharp.Extensions/ModelBinding/ModelBindingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,31 +421,21 @@ public static bool IsCustomStruct(this Type source)
}

/// <summary>
/// Converts the name of a method into camelCase
/// Converts the name of a property/method into camelCase
/// </summary>
/// <param name="method">the method which will have it's name converted</param>
/// <returns>the camel case version of the method name.</returns>
public static string ConvertNameToCamelCase(this MethodInfo method)
{
return ConvertNameToCamelCase(method.Name);
}

/// <summary>
/// Converts the name of a property into camelCase
/// </summary>
/// <param name="property">the property which will have it's name converted</param>
/// <param name="memberInfo">the property/method which will have it's name converted</param>
/// <returns>the camel case version of the property name.</returns>
public static string ConvertNameToCamelCase(this PropertyInfo property)
public static string ConvertNameToCamelCase(this MemberInfo memberInfo)
{
return ConvertNameToCamelCase(property.Name);
return ConvertNameToCamelCase(memberInfo.Name);
}

/// <summary>
/// Converts a string (usually .NET value of some sort) to a camelCase representation.
/// </summary>
/// <param name="sourceString"></param>
/// <returns>the string converted to camelCase or preserved based on it's original structure.</returns>
private static string ConvertNameToCamelCase(this string sourceString)
internal static string ConvertNameToCamelCase(this string sourceString)
{
// don't allow whitespace in property names.
// because we use this in the actual binding process, we should be throwing and not allowing invalid entries.
Expand Down

0 comments on commit 0ae176b

Please sign in to comment.