Skip to content

Commit

Permalink
Merge pull request #1425 from riganti/fix/bugs-net-framework
Browse files Browse the repository at this point in the history
Fixed a couple of bugs for `net472` framework build
  • Loading branch information
acizmarik authored Jul 27, 2022
2 parents b3bea04 + c31898d commit ac2a239
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ ResolvedControl ProcessReplacement(ResolvedControl control)
ResolvedControlHelper.SetContent(newControl, control.Content.ToArray(), StyleOverrideOptions.Append);

// copy properties
foreach (var p in control.Properties.Values)
foreach (var p in control.Properties.Values
#if !DotNetCore
.ToArray()
#endif
)
{
control.Properties.Remove(p.Property);

Expand Down
1 change: 1 addition & 0 deletions src/Framework/Framework/DotVVM.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="System.Collections.Specialized" Version="4.3.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>
<ItemGroup>
<None Update="ResourceManagement\ClientGlobalize\JQueryGlobalizeRegisterTemplate.tt">
Expand Down
3 changes: 2 additions & 1 deletion src/Framework/Framework/Hosting/VisualStudioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ internal static string SerializeConfig(DotvvmConfiguration config, bool includeP
config.ServiceProvider.GetRequiredService<IControlResolver>();
}

var dotvvmVersion = (typeof(DotvvmConfiguration).Assembly.GetName().Version ?? new System.Version(0, 0, 0, 0));
var obj = new {
dotvvmVersion = typeof(DotvvmConfiguration).Assembly.GetName().Version,
dotvvmVersion = dotvvmVersion.ToString(4),
config,
properties = includeProperties ? DotvvmPropertySerializableList.Properties : null,
capabilities = includeProperties ? DotvvmPropertySerializableList.Capabilities : null,
Expand Down
2 changes: 0 additions & 2 deletions src/Framework/Framework/Utils/ReflectionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,8 @@ public static Type UnwrapTaskType(this Type type)
return type.GetGenericArguments()[0];
else if (typeof(Task).IsAssignableFrom(type))
return typeof(void);
#if DotNetCore
else if (type.IsGenericType && typeof(ValueTask<>).IsAssignableFrom(type.GetGenericTypeDefinition()))
return type.GetGenericArguments()[0];
#endif
else
return type;
}
Expand Down
37 changes: 37 additions & 0 deletions src/Framework/Testing/TestEnvironmentHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

namespace DotVVM.Framework.Testing
{
public class TestEnvironmentHelper
{
public enum FrameworkType
{
/// Represents .NET 5+
Net,

/// Represents .NET Core 1.0 - 3.1
NetCore,

/// Represents old .NET Framework 4.7.1 - 4.8
NetFramework,

/// Represents .NET Native
NetNative
}

public static FrameworkType GetFrameworkType()
{
var description = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
if (description.StartsWith(".NET Framework"))
return FrameworkType.NetFramework;
else if (description.StartsWith(".NET Core"))
return FrameworkType.NetCore;
else if (description.StartsWith(".NET Native"))
return FrameworkType.NetNative;
else if (description.StartsWith(".NET"))
return FrameworkType.Net;

throw new ArgumentException($"Unrecognized framework type {description}");
}
}
}
8 changes: 6 additions & 2 deletions src/Tests/Binding/ExpressionHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public void UpdateMember_GetValue()
var cP = Expression.Parameter(typeof(DotvvmControl), "c");
var newValueP = Expression.Parameter(typeof(object), "newValue");
var updateExpr = memberExpressionFactory.UpdateMember(ExpressionUtils.Replace((DotvvmControl c) => c.GetValue(DotvvmBindableObject.DataContextProperty, true), cP), newValueP);
var convertExpression = (TestEnvironmentHelper.GetFrameworkType() == TestEnvironmentHelper.FrameworkType.Net)
? "Convert(newValue, Object)" : "Convert(newValue)";
Assert.IsNotNull(updateExpr);
Assert.AreEqual("c.SetValueToSource(DotvvmBindableObject.DataContextProperty, Convert(newValue, Object))", updateExpr.ToString());
Assert.AreEqual($"c.SetValueToSource(DotvvmBindableObject.DataContextProperty, {convertExpression})", updateExpr.ToString());
}

[TestMethod]
Expand All @@ -45,8 +47,10 @@ public void UpdateMember_NormalProperty()
var vmP = Expression.Parameter(typeof(Tests.Binding.TestViewModel), "vm");
var newValueP = Expression.Parameter(typeof(DateTime), "newValue");
var updateExpr = memberExpressionFactory.UpdateMember(ExpressionUtils.Replace((Tests.Binding.TestViewModel c) => c.DateFrom, vmP), newValueP);
var convertExpression = (TestEnvironmentHelper.GetFrameworkType() == TestEnvironmentHelper.FrameworkType.Net)
? "Convert(newValue, Nullable`1)" : "Convert(newValue)";
Assert.IsNotNull(updateExpr);
Assert.AreEqual("(vm.DateFrom = Convert(newValue, Nullable`1))", updateExpr.ToString());
Assert.AreEqual($"(vm.DateFrom = {convertExpression})", updateExpr.ToString());
}

[TestMethod]
Expand Down
24 changes: 16 additions & 8 deletions src/Tests/Binding/JavascriptCompilationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,13 +860,12 @@ public void JsTranslator_ConvertNumeric(string binding, string expected)
}

[TestMethod]
[DataRow("StringProp.Split('c')", "c", "None")]
[DataRow("StringProp.Split(\"str\")", "str", "None")]
[DataRow("StringProp.Split('c', StringSplitOptions.None)", "c", "None")]
[DataRow("StringProp.Split('c', StringSplitOptions.RemoveEmptyEntries)", "c", "RemoveEmptyEntries")]
public void JsTranslator_StringSplit_WithOptions(string binding, string delimiter, string options)
{
var result = CompileBinding(binding, new[] { typeof(TestViewModel) });
var result = CompileBinding(binding, new[] { new NamespaceImport("DotVVM.Framework.Binding.HelperNamespace") }, new[] { typeof(TestViewModel) });
Assert.AreEqual($"dotvvm.translations.string.split(StringProp(),\"{delimiter}\",\"{options}\")", result);
}

Expand Down Expand Up @@ -1099,20 +1098,29 @@ public void JavascriptCompilation_ApiRefreshOn()
[DataRow("StringProp.EndsWith('test',StringComparison.InvariantCultureIgnoreCase)",
"dotvvm.translations.string.endsWith(StringProp(),\"test\",\"InvariantCultureIgnoreCase\")")]
[DataRow("StringProp.Trim()", "StringProp().trim()")]
[DataRow("StringProp.Trim('0')", "dotvvm.translations.string.trimEnd(dotvvm.translations.string.trimStart(StringProp(),\"0\"),\"0\")")]
[DataRow("StringProp.TrimStart()", "StringProp().trimStart()")]
[DataRow("StringProp.TrimStart('0')", "dotvvm.translations.string.trimStart(StringProp(),\"0\")")]
[DataRow("StringProp.TrimEnd()", "StringProp().trimEnd()")]
[DataRow("StringProp.TrimEnd('0')", "dotvvm.translations.string.trimEnd(StringProp(),\"0\")")]
[DataRow("StringProp.PadLeft(1)", "StringProp().padStart(1)")]
[DataRow("StringProp.PadRight(2)", "StringProp().padEnd(2)")]
[DataRow("StringProp.PadLeft(1,'#')", "StringProp().padStart(1,\"#\")")]
[DataRow("StringProp.PadRight(2,'#')", "StringProp().padEnd(2,\"#\")")]
[DataRow("string.IsNullOrEmpty(StringProp)", "!(StringProp()?.length>0)")]
[DataRow("string.IsNullOrWhiteSpace(StringProp)", "!(StringProp()?.trim().length>0)")]
#if DotNetCore
[DataRow("StringProp.Trim('0')", "dotvvm.translations.string.trimEnd(dotvvm.translations.string.trimStart(StringProp(),\"0\"),\"0\")")]
[DataRow("StringProp.TrimStart()", "StringProp().trimStart()")]
[DataRow("StringProp.TrimStart('0')", "dotvvm.translations.string.trimStart(StringProp(),\"0\")")]
[DataRow("StringProp.TrimEnd()", "StringProp().trimEnd()")]
[DataRow("StringProp.TrimEnd('0')", "dotvvm.translations.string.trimEnd(StringProp(),\"0\")")]
#endif
#if !DotNetCore
[DataRow("StringProp.Trim('0')", "dotvvm.translations.string.trimEnd(dotvvm.translations.string.trimStart(StringProp(),[\"0\"][0]),[\"0\"][0])")]
[DataRow("StringProp.TrimStart()", "dotvvm.translations.string.trimStart(StringProp(),[][0])")]
[DataRow("StringProp.TrimStart('0')", "dotvvm.translations.string.trimStart(StringProp(),[\"0\"][0])")]
[DataRow("StringProp.TrimEnd()", "dotvvm.translations.string.trimEnd(StringProp(),[][0])")]
[DataRow("StringProp.TrimEnd('0')", "dotvvm.translations.string.trimEnd(StringProp(),[\"0\"][0])")]
#endif
public void JavascriptCompilation_StringFunctions(string input, string expected)
{
var result = CompileBinding(input, typeof(TestViewModel));
var result = CompileBinding(input, new[] { new NamespaceImport("DotVVM.Framework.Binding.HelperNamespace") }, typeof(TestViewModel));
Assert.AreEqual(expected, result);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Tests/Binding/NullPropagationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Newtonsoft.Json;
using DotVVM.Framework.Configuration;
using DotVVM.Framework.Binding.HelperNamespace;
using DotVVM.Framework.Testing;

namespace DotVVM.Framework.Tests.Binding
{
Expand Down Expand Up @@ -321,7 +322,9 @@ public void ValueTypePropertyAccess()
var ex = Assert.ThrowsException<NullReferenceException>(() =>
EvalExpression<TestViewModel>(v => TimeSpan.FromSeconds(v.IntProp).TotalMilliseconds, null)
);
Assert.AreEqual("Binding expression 'Convert(v.IntProp, Double)' of type 'System.Double' has evaluated to null.", ex.Message);
var convertExpression = (TestEnvironmentHelper.GetFrameworkType() == TestEnvironmentHelper.FrameworkType.Net)
? "Convert(v.IntProp, Double)" : "Convert(v.IntProp)";
Assert.AreEqual($"Binding expression '{convertExpression}' of type 'System.Double' has evaluated to null.", ex.Message);

Assert.AreEqual(1000d, EvalExpression<TestViewModel>(v => TimeSpan.FromSeconds(v.IntProp).TotalMilliseconds, new TestViewModel { IntProp = 1 }));
}
Expand Down
3 changes: 3 additions & 0 deletions src/Tests/DotVVM.Framework.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<ProjectReference Include="../Framework/Framework/DotVVM.Framework.csproj" />
<ProjectReference Include="../Framework/Testing/DotVVM.Framework.Testing.csproj" />
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<DefineConstants>$(DefineConstants);DotNetCore</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<ProjectReference Include="../Framework/Hosting.Owin/DotVVM.Framework.Hosting.Owin.csproj" />
<PackageReference Include="CheckTestOutput" Version="0.4.3" />
Expand Down
8 changes: 8 additions & 0 deletions src/Tests/Runtime/ConfigurationSerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ public ConfigurationSerializationTests()
void checkConfig(DotvvmConfiguration config, bool includeProperties = false, string checkName = null, string fileExtension = "json", [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null)
{
var serialized = DotVVM.Framework.Hosting.VisualStudioHelper.SerializeConfig(config, includeProperties);
// Unify package versions
serialized = Regex.Replace(serialized, "Version=[0-9.]+", "Version=***");
serialized = Regex.Replace(serialized, "\"dotvvmVersion\": \"[0-9]\\.[0-9]\\.[0-9]\\.[0-9]\"", "\"dotvvmVersion\": \"*.*.*.*\"");
// Unify all occurrences of mscorlib and system.private.corelib
serialized = serialized.Replace("mscorlib, Version=***, Culture=neutral, PublicKeyToken=b77a5c561934e089", "CoreLibrary");
serialized = serialized.Replace("System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", "CoreLibrary");
// Special case - unify IServiceProvider
serialized = serialized.Replace("System.IServiceProvider, CoreLibrary", "System.IServiceProvider, ComponentLibrary");
serialized = serialized.Replace("System.IServiceProvider, System.ComponentModel, Version=***, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.IServiceProvider, ComponentLibrary");

var jobject = JObject.Parse(serialized);
if (jobject["properties"] is object)
foreach (var testControl in ((JObject)jobject["properties"]).Properties().Where(p => p.Name.Contains(".Tests.")).ToArray())
Expand Down
4 changes: 3 additions & 1 deletion src/Tests/Runtime/LruCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void ClearsOnTimeout()
Assert.IsFalse(dict.TryGetValue(1, out _));
}

#if DotNetCore
[TestMethod]
public void IsCollectible()
{
Expand All @@ -95,9 +96,10 @@ WeakReference<SimpleLruDictionary<object, object>> create() =>
Thread.Sleep(32);
GC.Collect(2, GCCollectionMode.Forced);
Thread.Sleep(32);
Assert.IsTrue(counter < 30); // wut, no Assert.LessThan?
Assert.IsTrue(counter < 60); // wut, no Assert.LessThan?
counter++;
}
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
"Identifier": "secondService",
"ParameterType": {
"$type": "DotVVM.Framework.Compilation.ControlTree.Resolved.ResolvedTypeDescriptor, DotVVM.Framework",
"Type": "System.Func`1[[System.Collections.Generic.IEnumerable`1[[System.Lazy`1[[System.IServiceProvider, System.ComponentModel, Version=***, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]], System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]",
"Type": "System.Func`1[[System.Collections.Generic.IEnumerable`1[[System.Lazy`1[[System.IServiceProvider, ComponentLibrary]], CoreLibrary]], CoreLibrary]]",
"Name": "Func`1",
"Namespace": "System",
"Assembly": "System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
"FullName": "System.Func`1[[System.Collections.Generic.IEnumerable`1[[System.Lazy`1[[System.IServiceProvider, System.ComponentModel, Version=***, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]], System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]"
"Assembly": "CoreLibrary",
"FullName": "System.Func`1[[System.Collections.Generic.IEnumerable`1[[System.Lazy`1[[System.IServiceProvider, ComponentLibrary]], CoreLibrary]], CoreLibrary]]"
},
"Inherit": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
},
"DotVVM.Framework.Controls.CheckBox": {
"Checked": {
"type": "System.Nullable`1[[System.Boolean, System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]"
"type": "System.Nullable`1[[System.Boolean, CoreLibrary]]"
},
"CheckedItems": {
"type": "System.Collections.IEnumerable"
Expand Down Expand Up @@ -363,7 +363,7 @@
"type": "System.Boolean"
},
"MaxFileSize": {
"type": "System.Nullable`1[[System.Int32, System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]"
"type": "System.Nullable`1[[System.Int32, CoreLibrary]]"
},
"NumberOfFilesIndicatorText": {
"type": "System.String",
Expand Down Expand Up @@ -471,7 +471,7 @@
"type": "System.Boolean"
},
"SortChanged": {
"type": "System.Action`1[[System.String, System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]"
"type": "System.Action`1[[System.String, CoreLibrary]]"
}
},
"DotVVM.Framework.Controls.GridViewCheckBoxColumn": {
Expand Down Expand Up @@ -615,7 +615,7 @@
"mappingMode": "InnerElement"
},
"ItemChildrenBinding": {
"type": "DotVVM.Framework.Binding.Expressions.IValueBinding`1[[System.Collections.Generic.IEnumerable`1[[System.Object, System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], DotVVM.Framework",
"type": "DotVVM.Framework.Binding.Expressions.IValueBinding`1[[System.Collections.Generic.IEnumerable`1[[System.Object, CoreLibrary]], CoreLibrary]], DotVVM.Framework",
"dataContextChange": [
{
"$type": "DotVVM.Framework.Binding.CollectionElementDataContextChangeAttribute, DotVVM.Framework",
Expand Down Expand Up @@ -699,7 +699,7 @@
},
"DotVVM.Framework.Controls.Infrastructure.DotvvmView": {
"Directives": {
"type": "System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]",
"type": "System.Collections.Generic.Dictionary`2[[System.String, CoreLibrary],[System.String, CoreLibrary]]",
"isValueInherited": true
}
},
Expand Down Expand Up @@ -1020,7 +1020,7 @@
"type": "System.String"
},
"UseHistoryApi": {
"type": "System.Nullable`1[[System.Boolean, System.Private.CoreLib, Version=***, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]"
"type": "System.Nullable`1[[System.Boolean, CoreLibrary]]"
}
},
"DotVVM.Framework.Controls.Styles": {
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/ViewModel/ViewModelTypeMetadataSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static void ClassInit(TestContext context)
DotvvmConfiguration.CreateDefault());
}

#if DotNetCore
[DataTestMethod]
[DataRow(typeof(bool), "'Boolean'")]
[DataRow(typeof(int?), "{'type':'nullable','inner':'Int32'}")]
Expand Down Expand Up @@ -55,6 +56,7 @@ public void ViewModelTypeMetadata_TypeName(Type type, string expected)
var result = typeMetadataSerializer.GetTypeIdentifier(type, dependentObjectTypes, dependentEnumTypes);
Assert.AreEqual(expected.Replace("'", "\""), result.ToString(Formatting.None));
}
#endif

[TestMethod]
public void ViewModelTypeMetadata_TypeMetadata()
Expand Down

0 comments on commit ac2a239

Please sign in to comment.