8000 Add more System.Xaml tests (#8203) · dotnet/wpf@e1babd2 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1babd2

Browse files
authored
Add more System.Xaml tests (#8203)
* Add System.Xaml tests * Fix IDE warnings and fix Debug assert tests
1 parent 5363688 commit e1babd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+16910
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Collections.Generic;
6+
using System.Reflection;
7+
8+
namespace System.Xaml.Tests.Common;
9+
10+
public class CustomAssembly : Assembly
11+
{
12+
protected Assembly DelegatingAssembly { get; }
13+
14+
public CustomAssembly(Assembly delegatingAssembly)
15+
{
16+
DelegatingAssembly = delegatingAssembly;
17+
}
18+
19+
public Optional<string?> FullNameResult { get; set; }
20+
public override string? FullName => FullNameResult.Or(DelegatingAssembly.FullName);
21+
22+
public Optional<bool> IsDynamicResult { get; set; }
23+
public override bool IsDynamic => IsDynamicResult.Or(DelegatingAssembly.IsDynamic);
24+
25+
public Optional<bool> ReflectionOnlyResult { get; set; }
26+
public override bool ReflectionOnly => ReflectionOnlyResult.Or(DelegatingAssembly.ReflectionOnly);
27+
28+
public Optional<IList<CustomAttributeData>> GetCustomAttributesDataResult { get; set; }
29+
public override IList<CustomAttributeData> GetCustomAttributesData()
30+
{
31+
return GetCustomAttributesDataResult.Or(DelegatingAssembly.GetCustomAttributesData);
32+
}
33+
34+
public Optional<Dictionary<Type, object?[]?>> GetCustomAttributesMap { get; set; }
35+
36+
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
37+
{
38+
if (GetCustomAttributesMap.HasValue)
39+
{
40+
object?[]? result;
41+
if (GetCustomAttributesMap.Value.TryGetValue(attributeType, out result))
42+
{
43+
return result!;
44+
}
45+
}
46+
47+
return DelegatingAssembly.GetCustomAttributes(attributeType, inherit);
48+
}
49+
50+
public override bool Equals(object? o) => DelegatingAssembly.Equals(o);
51+
52+
public override int GetHashCode() => DelegatingAssembly.GetHashCode();
53+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Globalization;
6+
using System.Reflection;
7+
8+
namespace System.Xaml.Tests.Common;
9+
10+
public class CustomConstructorInfo : ConstructorInfo
11+
{
12+
protected ConstructorInfo DelegatingConstructor { get; }
13+
14+
public CustomConstructorInfo(ConstructorInfo delegatingConstructor)
15+
{
16+
DelegatingConstructor = delegatingConstructor;
17+
}
18+
19+
public Optional<MethodAttributes> AttributesResult { get; set; }
20+
public override MethodAttributes Attributes => AttributesResult.Or(DelegatingConstructor.Attributes);
21+
22+
public Optional<Type> DeclaringTypeResult { get; set; }
23+
public override Type DeclaringType => DeclaringTypeResult.Or(DelegatingConstructor.DeclaringType!);
24+
25+
public Optional<MethodImplAttributes> GetMethodImplementationFlagsResult { get; set; }
26+
public override MethodImplAttributes GetMethodImplementationFlags() => GetMethodImplementationFlagsResult.Or(DelegatingConstructor.GetMethodImplementationFlags);
27+
28+
public Optional<ParameterInfo[]> GetParametersResult { get; set; }
29+
public override ParameterInfo[] GetParameters() => GetParametersResult.Or(DelegatingConstructor.GetParameters);
30+
31+
public Optional<bool> IsSecurityCriticalResult { get; set; }
32+
public override bool IsSecurityCritical => IsSecurityCriticalResult.Or(DelegatingConstructor.IsSecurityCritical);
33+
34+
public Optional<bool> IsSecuritySafeCriticalResult { get; set; }
35+
public override bool IsSecuritySafeCritical => IsSecuritySafeCriticalResult.Or(DelegatingConstructor.IsSecuritySafeCritical);
36+
37+
public Optional<bool> IsSecurityTransparentResult { get; set; }
38+
public override bool IsSecurityTransparent => IsSecurityTransparentResult.Or(DelegatingConstructor.IsSecurityTransparent);
39+
40+
public Optional<RuntimeMethodHandle> MethodHandleResult { get; set; }
41+
public override RuntimeMethodHandle MethodHandle => MethodHandleResult.Or(DelegatingConstructor.MethodHandle);
42+
43+
public Optional<MemberTypes> MemberTypeResult { get; set; }
44+
public override MemberTypes MemberType => MemberTypeResult.Or(DelegatingConstructor.MemberType);
45+
46+
public Optional<string> NameResult { get; set; }
47+
public override string Name => NameResult.Or(DelegatingConstructor.Name);
48+
49+
public Optional<Type> ReflectedTypeResult { get; set; }
50+
public override Type ReflectedType => ReflectedTypeResult.Or(DelegatingConstructor.ReflectedType!);
51+
52+
public override object Invoke(BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture)
53+
{
54+
return DelegatingConstructor.Invoke(invokeAttr, binder, parameters, culture);
55+
}
56+
57+
public override object? Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture)
58+
{
59+
return DelegatingConstructor.Invoke(obj, invokeAttr, binder, parameters, culture);
60+
}
61+
62+
public override object[] GetCustomAttributes(bool inherit)
63+
{
64+
return DelegatingConstructor.GetCustomAttributes(inherit);
65+
}
66+
67+
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
68+
{
69+
return DelegatingConstructor.GetCustomAttributes(attributeType, inherit);
70+
}
71+
72+
public override bool IsDefined(Type attributeType, bool inherit)
73+
{
74+
return DelegatingConstructor.IsDefined(attributeType, inherit);
75+
}
76+
77+
public override bool Equals(object? obj) => DelegatingConstructor.Equals(obj);
78+
79+
public override int GetHashCode() => DelegatingConstructor.GetHashCode();
80+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Globalization;
6+
using System.Reflection;
7+
8+
namespace System.Xaml.Tests.Common;
9+
10+
public class CustomMethodInfo : MethodInfo
11+
{
12+
protected MethodInfo DelegatingMethod { get; }
13+
14+
public CustomMethodInfo(MethodInfo delegatingMethod)
15+
{
16+
DelegatingMethod = delegatingMethod;
17+
}
18+
19+
public Optional<MethodAttributes> AttributesResult { get; set; }
20+
public override MethodAttributes Attributes => AttributesResult.Or(DelegatingMethod.Attributes);
21+
22+
public Optional<Type?> DeclaringTypeResult { get; set; }
23+
public override Type DeclaringType => DeclaringTypeResult.Or(DelegatingMethod.DeclaringType)!;
24+
25+
public Optional<MethodInfo> GetBaseDefinitionResult { get; set; }
26+
public override MethodInfo GetBaseDefinition() => GetBaseDefinitionResult.Or(DelegatingMethod.GetBaseDefinition);
27+
28+
public Optional<MethodImplAttributes> GetMethodImplementationFlagsResult { get; set; }
29+
public override MethodImplAttributes GetMethodImplementationFlags() => GetMethodImplementationFlagsResult.Or(DelegatingMethod.GetMethodImplementationFlags);
30+
31+
public Optional<ParameterInfo[]> GetParametersResult { get; set; }
32+
public override ParameterInfo[] GetParameters() => GetParametersResult.Or(DelegatingMethod.GetParameters);
33+
34+
public Optional<RuntimeMethodHandle> MethodHandleResult { get; set; }
35+
public override RuntimeMethodHandle MethodHandle => MethodHandleResult.Or(DelegatingMethod.MethodHandle);
36+
37+
public Optional<MemberTypes> MemberTypeResult { get; set; }
38+
public override MemberTypes MemberType => MemberTypeResult.Or(DelegatingMethod.MemberType);
39+
40+
public Optional<string> NameResult { get; set; }
41+
public override string Name => NameResult.Or(DelegatingMethod.Name);
42+
43+
public Optional<Type> ReflectedTypeResult { get; set; }
44+
public override Type ReflectedType => ReflectedTypeResult.Or(DelegatingMethod.ReflectedType!);
45+
46+
public Optional<ParameterInfo> ReturnParameterResult { get; set; }
47+
public override ParameterInfo ReturnParameter => ReturnParameterResult.Or(DelegatingMethod.ReturnParameter);
48+
49+
public Optional<Type?> ReturnTypeResult { get; set; }
50+
public override Type ReturnType => ReturnTypeResult.Or(DelegatingMethod.ReturnType)!;
51+
52+
public Optional<ICustomAttributeProvider> ReturnTypeCustomAttributesResult { get; set; }
53+
public override ICustomAttributeProvider ReturnTypeCustomAttributes => ReturnTypeCustomAttributesResult.Or(DelegatingMethod.ReturnTypeCustomAttributes);
54+
55+
public override object? Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture)
56+
{
57+
return DelegatingMethod.Invoke(obj, invokeAttr, binder, parameters, culture);
58+
}
59+
60+
public override object[] GetCustomAttributes(bool inherit)
61+
{
62+
return DelegatingMethod.GetCustomAttributes(inherit);
63+
}
64+
65+
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
66+
{
67+
return DelegatingMethod.GetCustomAttributes(attributeType, inherit);
68+
}
69+
70+
public override bool IsDefined(Type attributeType, bool inherit)
71+
{
72+
return DelegatingMethod.IsDefined(attributeType, inherit);
73+
}
74+
75+
public override bool Equals(object? obj) => DelegatingMethod.Equals(obj);
76+
77+
public override int GetHashCode() => DelegatingMethod.GetHashCode();
78+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Collections.Generic;
6+
using System.Reflection;
7+
8+
namespace System.Xaml.Tests.Common;
9+
10+
public class CustomType : TypeDelegator
11+
{
12+
public CustomType(Type delegatingType) : base(delegatingType)
13+
{
14+
}
15+
16+
public Optional<Assembly> AssemblyResult { get; set; }
17+
public override Assembly Assembly => AssemblyResult.Or(base.Assembly);
18+
19+
public Optional<IList<CustomAttributeData>> GetCustomAttributesDataResult { get; set; }
20+
public override IList<CustomAttributeData> GetCustomAttributesData()
21+
{
22+
return GetCustomAttributesDataResult.Or(typeImpl.GetCustomAttributesData);
23+
}
24+
25+
public Optional<Type?> DeclaringTypeResult { get; set; }
26+
public override Type? DeclaringType => DeclaringTypeResult.Or(typeImpl.DeclaringType);
27+
28+
29+
public Optional<ConstructorInfo?> GetConstructorResult { get; set; }
30+
protected override ConstructorInfo? GetConstructorImpl(BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers)
31+
{
32+
return GetConstructorResult.Or(base.GetConstructorImpl, bindingAttr, binder, callConvention, types, modifiers);
33+
}
34+
35+
public Optional<EventInfo[]> GetEventsResult { get; set; }
36+
public override EventInfo[] GetEvents(BindingFlags bindingAttr)
37+
{
38+
return GetEventsResult.Or(typeImpl.GetEvents, bindingAttr);
39+
}
40+
41+
public Optional<Type?[]?> GetGenericParameterConstraintsResult { get; set; }
42+
public override Type[] GetGenericParameterConstraints()
43+
{
44+
return GetGenericParameterConstraintsResult.Or(typeImpl.GetGenericParameterConstraints)!;
45+
}
46+
47+
public Optional<Type?[]?> GetInterfacesResult { get; set; }
48+
public override Type[] GetInterfaces()
49+
{
50+
return GetInterfacesResult.Or(typeImpl.GetInterfaces)!;
51+
}
52+
53+
public Optional<MemberInfo[]> GetMemberResult { get; set; }
54+
public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
55+
{
56+
return GetMemberResult.Or(typeImpl.GetMember, name, type, bindingAttr);
57+
}
58+
59+
public Optional<PropertyInfo[]> GetPropertiesResult { get; set; }
60+
public override PropertyInfo[] GetProperties(BindingFlags bindingAttr)
61+
{
62+
return GetPropertiesResult.Or(typeImpl.GetProperties, bindingAttr);
63+
}
64+
65+
public Optional<bool> IsGenericParameterResult { get; set; }
66+
public override bool IsGenericParameter => IsGenericParameterResult.Or(typeImpl.IsGenericParameter);
67+
68+
public Optional<Type> UnderlyingSystemTypeResult { get; set; }
69+
public override Type UnderlyingSystemType => UnderlyingSystemTypeResult.Or(typeImpl.UnderlyingSystemType);
70+
}

0 commit comments

Comments
 (0)
0