Skip to content

Commit

Permalink
migrate code, comment non-migrated code... #20
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrock committed Mar 10, 2023
1 parent 26216c0 commit a0a9646
Show file tree
Hide file tree
Showing 16 changed files with 372 additions and 534 deletions.
168 changes: 0 additions & 168 deletions Sources/SrkToolkit-v2.sln

Large diffs are not rendered by default.

42 changes: 22 additions & 20 deletions Sources/SrkToolkit.AspNetCore2.UnitTests/DecimalModelBinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

namespace SrkToolkit.Web.Tests
{
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using SrkToolkit.Web.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using SrkToolkit.Web.Mvc;
using Xunit;

public class DecimalModelBinderTests
Expand Down Expand Up @@ -88,7 +90,7 @@ public void DoubleNotFrenchStyle()
object value;
var valueProvider = new ValueProviderResult(expectation.Input, expectation.Input, expectation.Culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(expectation.Expected, value, "In: '" + expectation.Input + "' " + expectation.Culture.Name);
Assert.Equal(expectation.Expected, value, "In: '" + expectation.Input + "' " + expectation.Culture.Name);
}
}

Expand All @@ -101,7 +103,7 @@ public void DoubleIsFrenchStyle()
object value;
var valueProvider = new ValueProviderResult(expectation.Input, expectation.Input, expectation.Culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(expectation.Expected, value, "In: '" + expectation.Input + "' " + expectation.Culture.Name);
Assert.Equal(expectation.Expected, value, "In: '" + expectation.Input + "' " + expectation.Culture.Name);
}
}

Expand All @@ -117,8 +119,8 @@ public void DoubleBug1()
object value;
var valueProvider = new ValueProviderResult(input, input, culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(expected, value);
Assert.AreEqual(0, result.Errors.Count);
Assert.Equal(expected, value);
Assert.Equal(0, result.Errors.Count);
}

[Fact]
Expand All @@ -133,7 +135,7 @@ public void DoubleNotNullable()
object value;
var valueProvider = new ValueProviderResult(input, input, culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(1, result.Errors.Count);
Assert.Equal(1, result.Errors.Count);
}

[Fact]
Expand All @@ -148,8 +150,8 @@ public void DoubleIsNullable()
object value;
var valueProvider = new ValueProviderResult(input, input, culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(expected, value);
Assert.AreEqual(0, result.Errors.Count);
Assert.Equal(expected, value);
Assert.Equal(0, result.Errors.Count);
}

[Fact]
Expand All @@ -162,7 +164,7 @@ public void DecimalNotFrenchStyle()
object value;
var valueProvider = new ValueProviderResult(expectation.Input, expectation.Input, expectation.Culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(expectedValue, value, "In: '" + expectation.Input + "' " + expectation.Culture.Name);
Assert.Equal(expectedValue, value, "In: '" + expectation.Input + "' " + expectation.Culture.Name);
}
}

Expand All @@ -176,7 +178,7 @@ public void DecimalIsFrenchStyle()
object value;
var valueProvider = new ValueProviderResult(expectation.Input, expectation.Input, expectation.Culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(expectedValue, value, "In: '" + expectation.Input + "' " + expectation.Culture.Name);
Assert.Equal(expectedValue, value, "In: '" + expectation.Input + "' " + expectation.Culture.Name);
}
}

Expand All @@ -192,8 +194,8 @@ public void DecimalBug1()
object value;
var valueProvider = new ValueProviderResult(input, input, culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(expected, value);
Assert.AreEqual(0, result.Errors.Count);
Assert.Equal(expected, value);
Assert.Equal(0, result.Errors.Count);
}

[Fact]
Expand All @@ -208,7 +210,7 @@ public void DecimalNotNullable()
object value;
var valueProvider = new ValueProviderResult(input, input, culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(1, result.Errors.Count);
Assert.Equal(1, result.Errors.Count);
}

[Fact]
Expand All @@ -223,8 +225,8 @@ public void DecimalIsNullable()
object value;
var valueProvider = new ValueProviderResult(input, input, culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(expected, value);
Assert.AreEqual(0, result.Errors.Count);
Assert.Equal(expected, value);
Assert.Equal(0, result.Errors.Count);
}

[Fact]
Expand All @@ -239,8 +241,8 @@ public void DecimalIsNullableNull()
object value;
var valueProvider = new ValueProviderResult(input, input, culture);
var result = target.BindModelImpl(null, out value);
Assert.AreEqual(expected, value);
Assert.AreEqual(0, result.Errors.Count);
Assert.Equal(expected, value);
Assert.Equal(0, result.Errors.Count);
}

[Fact]
Expand All @@ -254,8 +256,8 @@ public void Bug1()
object value;
var valueProvider = new ValueProviderResult(input, input, culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(expected, value);
Assert.AreEqual(0, result.Errors.Count);
Assert.Equal(expected, value);
Assert.Equal(0, result.Errors.Count);
}
}

Expand All @@ -266,7 +268,7 @@ public void Works()
{
var binders = new ModelBinderDictionary();
DecimalModelBinder.Register(binders);
Assert.AreEqual(6, binders.Count);
Assert.Equal(6, binders.Count);
}
}

Expand Down
28 changes: 14 additions & 14 deletions Sources/SrkToolkit.AspNetCore2.UnitTests/IntegerModelBinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
#if DEBUG
namespace SrkToolkit.Web.Tests
{
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using SrkToolkit.Web.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Globalization;
using SrkToolkit.Web.Mvc;
using System.Web.Mvc;
using Xunit;

public class IntegerModelBinderTests
{
[TestClass]
public class ConvertFrenchStyleDecimals
{
static List<Expectation<int>> intExpectations;
Expand All @@ -47,7 +48,7 @@ public static CultureInfo C(string name)
return new CultureInfo(name);
}

[TestMethod]
[Fact]
public void IntegerExpectations()
{
var target = new IntegerModelBinder<int>();
Expand All @@ -56,11 +57,11 @@ public void IntegerExpectations()
object value;
var valueProvider = new ValueProviderResult(expectation.Input, expectation.Input, expectation.Culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(expectation.Expected, value, "In: '" + expectation.Input + "' " + expectation.Culture.Name);
Assert.Equal(expectation.Expected, value, "In: '" + expectation.Input + "' " + expectation.Culture.Name);
}
}

[TestMethod]
[Fact]
public void IntNotNullable()
{
// typical bug we don't want to see
Expand All @@ -72,10 +73,10 @@ public void IntNotNullable()
object value;
var valueProvider = new ValueProviderResult(input, input, culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(1, result.Errors.Count);
Assert.Equal(1, result.Errors.Count);
}

[TestMethod]
[Fact]
public void IntIsNullable()
{
// typical bug we don't want to see
Expand All @@ -87,21 +88,20 @@ public void IntIsNullable()
object value;
var valueProvider = new ValueProviderResult(input, input, culture);
var result = target.BindModelImpl(valueProvider, out value);
Assert.AreEqual(expected, value);
Assert.AreEqual(0, result.Errors.Count);
Assert.Equal(expected, value);
Assert.Equal(0, result.Errors.Count);
}
}

[TestClass]
public class RegisterMethod
{
[TestMethod]
[Fact]
public void Works()
{
var binders = new ModelBinderDictionary();
IntegerModelBinder.Register(binders);
Assert.AreEqual(14, binders.Count);
Assert.IsTrue(binders.All(b => b.Value.GetType().Name == "IntegerModelBinder`1"));
Assert.Equal(14, binders.Count);
Assert.True(binders.All(b => b.Value.GetType().Name == "IntegerModelBinder`1"));
}
}

Expand Down
23 changes: 11 additions & 12 deletions Sources/SrkToolkit.AspNetCore2.UnitTests/OpenGraphNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,42 @@

namespace SrkToolkit.Web.Tests
{
using SrkToolkit.Web.Open;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SrkToolkit.Web.Open;
using Xunit;

[TestClass]
public class OpenGraphNameTests
{
[TestMethod]
[Fact]
public void HasDefinedNameAndNamespace()
{
var name = "toto";
var nsName = "super";
var ns = new OpenGraphNamespace(nsName, "a");
var obj = new OpenGraphName(ns, name);
Assert.AreEqual(nsName, obj.NamespaceName);
Assert.AreEqual(name, obj.Name);
Assert.Equal(nsName, obj.NamespaceName);
Assert.Equal(name, obj.Name);
}

////[TestMethod]
////[Fact]
////public void StringImplicitOperatorGivesOgNamespaceName()
////{
//// var name = "toto";
//// OpenGraphName obj = name;
//// Assert.AreEqual("og", obj.NamespaceName);
//// Assert.AreEqual(name, obj.Name);
//// Assert.Equal("og", obj.NamespaceName);
//// Assert.Equal(name, obj.Name);
////}

[TestMethod]
[Fact]
public void NameCtorGivesOgNamespaceName()
{
var name = "toto";
OpenGraphName obj = new OpenGraphName(name);
Assert.AreEqual("og", obj.NamespaceName);
Assert.AreEqual(name, obj.Name);
Assert.Equal("og", obj.NamespaceName);
Assert.Equal(name, obj.Name);
}
}
}
21 changes: 10 additions & 11 deletions Sources/SrkToolkit.AspNetCore2.UnitTests/OpenGraphNamespaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,46 @@

namespace SrkToolkit.Web.Tests
{
using SrkToolkit.Web.Open;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SrkToolkit.Web.Open;
using Xunit;

[TestClass]
public class OpenGraphNamespaceTests
{
[TestMethod]
[Fact]
public void HasDefinedName()
{
var nsName = "test";
var ns = new OpenGraphNamespace(nsName, "http://nsname/");
Assert.AreEqual(nsName, ns.Name);
Assert.Equal(nsName, ns.Name);
}

////[TestMethod]
////[Fact]
////public void ImplicitOperatorHasDefinedName()
////{
//// var nsName = "test";
//// OpenGraphNamespace ns = nsName;
//// Assert.AreEqual(nsName, ns.Name);
//// Assert.Equal(nsName, ns.Name);
////}

[TestMethod]
[Fact]
public void CustomRendersHtmlAttribute()
{
var nsName = "test";
var ns = new OpenGraphNamespace(nsName, "http://myns.me/test");
var expected = " xmlns:test=\"http://myns.me/test\" ";
Assert.AreEqual(expected, ns.ToHtmlAttributeString());
Assert.Equal(expected, ns.ToHtmlAttributeString());
}

[TestMethod]
[Fact]
public void DefaultRendersHtmlAttribute()
{
var name = new OpenGraphName("test");
var expected = " xmlns:og=\"http://ogp.me/ns#\" ";
Assert.AreEqual(expected, name.Namespace.ToHtmlAttributeString());
Assert.Equal(expected, name.Namespace.ToHtmlAttributeString());
}
}
}
Loading

0 comments on commit a0a9646

Please sign in to comment.