|
| 1 | +// Copyright 2004-2025 Castle Project - http://www.castleproject.org/ |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +namespace Castle.DynamicProxy.Tests |
| 16 | +{ |
| 17 | + using System; |
| 18 | + |
| 19 | + using Castle.DynamicProxy.Tests.Interceptors; |
| 20 | + |
| 21 | + using NUnit.Framework; |
| 22 | + |
| 23 | + [TestFixture] |
| 24 | + public class CaseSensitivityTestCase : BasePEVerifyTestCase |
| 25 | + { |
| 26 | + [TestCase(typeof(IDifferentlyCasedEvents))] |
| 27 | + [TestCase(typeof(IDifferentlyCasedMethods))] |
| 28 | + [TestCase(typeof(IDifferentlyCasedProperties))] |
| 29 | + public void Can_proxy_type_with_differently_cased_members(Type interfaceTypeToProxy) |
| 30 | + { |
| 31 | + _ = generator.CreateInterfaceProxyWithoutTarget(interfaceTypeToProxy); |
| 32 | + } |
| 33 | + |
| 34 | + [Test] |
| 35 | + public void Can_distinguish_differently_cased_events_during_interception() |
| 36 | + { |
| 37 | + var interceptor = new KeepDataInterceptor(); |
| 38 | + var proxy = generator.CreateInterfaceProxyWithoutTarget<IDifferentlyCasedEvents>(interceptor); |
| 39 | + |
| 40 | + proxy.Abc += delegate { }; |
| 41 | + Assert.AreEqual("add_Abc", interceptor.Invocation.Method.Name); |
| 42 | + |
| 43 | + proxy.aBc += delegate { }; |
| 44 | + Assert.AreEqual("add_aBc", interceptor.Invocation.Method.Name); |
| 45 | + |
| 46 | + proxy.abC += delegate { }; |
| 47 | + Assert.AreEqual("add_abC", interceptor.Invocation.Method.Name); |
| 48 | + } |
| 49 | + |
| 50 | + [Test] |
| 51 | + public void Can_distinguish_differently_cased_methods_during_interception() |
| 52 | + { |
| 53 | + var interceptor = new KeepDataInterceptor(); |
| 54 | + var proxy = generator.CreateInterfaceProxyWithoutTarget<IDifferentlyCasedMethods>(interceptor); |
| 55 | + |
| 56 | + proxy.Abc(); |
| 57 | + Assert.AreEqual("Abc", interceptor.Invocation.Method.Name); |
| 58 | + |
| 59 | + proxy.aBc(); |
| 60 | + Assert.AreEqual("aBc", interceptor.Invocation.Method.Name); |
| 61 | + |
| 62 | + proxy.abC(); |
| 63 | + Assert.AreEqual("abC", interceptor.Invocation.Method.Name); |
| 64 | + } |
| 65 | + |
| 66 | + [Test] |
| 67 | + public void Can_distinguish_differently_cased_properties_during_interception() |
| 68 | + { |
| 69 | + var interceptor = new KeepDataInterceptor(); |
| 70 | + var proxy = generator.CreateInterfaceProxyWithoutTarget<IDifferentlyCasedProperties>(interceptor); |
| 71 | + |
| 72 | + _ = proxy.Abc; |
| 73 | + Assert.AreEqual("get_Abc", interceptor.Invocation.Method.Name); |
| 74 | + |
| 75 | + _ = proxy.aBc; |
| 76 | + Assert.AreEqual("get_aBc", interceptor.Invocation.Method.Name); |
| 77 | + |
| 78 | + _ = proxy.abC; |
| 79 | + Assert.AreEqual("get_abC", interceptor.Invocation.Method.Name); |
| 80 | + } |
| 81 | + |
| 82 | + public interface IDifferentlyCasedEvents |
| 83 | + { |
| 84 | + event EventHandler Abc; |
| 85 | + event EventHandler aBc; |
| 86 | + event EventHandler abC; |
| 87 | + } |
| 88 | + |
| 89 | + public interface IDifferentlyCasedMethods |
| 90 | + { |
| 91 | + void Abc(); |
| 92 | + void aBc(); |
| 93 | + void abC(); |
| 94 | + } |
| 95 | + |
| 96 | + public interface IDifferentlyCasedProperties |
| 97 | + { |
| 98 | + object Abc { get; } |
| 99 | + object aBc { get; } |
| 100 | + object abC { get; } |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments