Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
117 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 71 additions & 60 deletions
131
src/Castle.Core.Tests/DynamicProxy.Tests/ClassProxyWithDefaultValuesTestCase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,72 @@ | ||
// Copyright 2004-2013 Castle Project - http://www.castleproject.org/ | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace Castle.DynamicProxy.Tests | ||
{ | ||
using System.Linq; | ||
|
||
using Castle.DynamicProxy.Tests.Classes; | ||
|
||
using CastleTests.DynamicProxy.Tests.Classes; | ||
|
||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class ClassProxyWithDefaultValuesTestCase : BasePEVerifyTestCase | ||
{ | ||
#if DOTNET45 | ||
[Test] | ||
public void MethodParameterWithDefaultValue_DefaultValueIsSetOnProxiedMethodAsWell() | ||
{ | ||
var proxiedType = generator.CreateClassProxy<ClassWithMethodWithParameterWithDefaultValue>().GetType(); | ||
|
||
var parameter = proxiedType.GetMethod("Method").GetParameters().Single(paramInfo => paramInfo.Name == "value"); | ||
|
||
Assert.True(parameter.HasDefaultValue); | ||
Assert.AreEqual(3, parameter.DefaultValue); | ||
} | ||
|
||
[Test] | ||
public void MethodParameterWithDefaultValue_DefaultValueNullIsSetOnProxiedMethodAsWell() | ||
{ | ||
var proxiedType = generator.CreateClassProxy<ClassWithMethodWithParameterWithNullDefaultValue>().GetType(); | ||
|
||
var parameter = proxiedType.GetMethod("Method").GetParameters().Single(paramInfo => paramInfo.Name == "value"); | ||
|
||
|
||
Assert.False(parameter.HasDefaultValue); | ||
} | ||
|
||
[Test] | ||
public void MethodParameterWithDefaultValue_UseNullDefaultValue() | ||
{ | ||
var proxiedType = generator.CreateClassProxy<ClassWithMethodWithParameterWithNullDefaultValue>(); | ||
var result = proxiedType.Method(); | ||
|
||
Assert.IsTrue(result); | ||
} | ||
#endif | ||
} | ||
// Copyright 2004-2013 Castle Project - http://www.castleproject.org/ | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace Castle.DynamicProxy.Tests | ||
{ | ||
using System.Linq; | ||
|
||
using Castle.DynamicProxy.Tests.Classes; | ||
using Castle.DynamicProxy.Tests.Interceptors; | ||
|
||
using CastleTests.DynamicProxy.Tests.Classes; | ||
using CastleTests.DynamicProxy.Tests.Interfaces; | ||
|
||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class ClassProxyWithDefaultValuesTestCase : BasePEVerifyTestCase | ||
{ | ||
#if DOTNET45 | ||
[Test] | ||
public void MethodParameterWithDefaultValue_DefaultValueIsSetOnProxiedMethodAsWell() | ||
{ | ||
var proxiedType = generator.CreateClassProxy<ClassWithMethodWithParameterWithDefaultValue>().GetType(); | ||
|
||
var parameter = proxiedType.GetMethod("Method").GetParameters().Single(paramInfo => paramInfo.Name == "value"); | ||
|
||
Assert.True(parameter.HasDefaultValue); | ||
Assert.AreEqual(3, parameter.DefaultValue); | ||
} | ||
|
||
[Test] | ||
public void MethodParameterWithDefaultValue_DefaultValueNullIsSetOnProxiedMethodAsWell() | ||
{ | ||
var proxiedType = generator.CreateClassProxy<ClassWithMethodWithParameterWithNullDefaultValue>().GetType(); | ||
|
||
var parameter = proxiedType.GetMethod("Method").GetParameters().Single(paramInfo => paramInfo.Name == "value"); | ||
|
||
Assert.False(parameter.HasDefaultValue); | ||
} | ||
|
||
[Test] | ||
public void MethodParameterWithDefaultValue_UseNullDefaultValue_class_proxy() | ||
{ | ||
var proxy = generator.CreateClassProxy<ClassWithMethodWithParameterWithNullDefaultValue>(); | ||
var result = proxy.Method(); | ||
|
||
Assert.IsTrue(result); | ||
} | ||
|
||
[Test] | ||
public void MethodParameterWithDefaultValue_UseNullDefaultValue_interface_proxy() | ||
{ | ||
var proxy = generator.CreateInterfaceProxyWithoutTarget<InterfaceWithMethodWithParameterWithNullDefaultValue>( | ||
new SetReturnValueInterceptor(true)); | ||
var result = proxy.Method(); | ||
|
||
Assert.IsTrue(result); | ||
} | ||
#endif | ||
} | ||
} |
48 changes: 24 additions & 24 deletions
48
...Core.Tests/DynamicProxy.Tests/Classes/ClassWithMethodWithParameterWithNullDefaultValue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
// Copyright 2004-2013 Castle Project - http://www.castleproject.org/ | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace CastleTests.DynamicProxy.Tests.Classes | ||
{ | ||
public class ClassWithMethodWithParameterWithNullDefaultValue | ||
{ | ||
public virtual bool Method(int? value = null) | ||
{ | ||
return value == null; | ||
} | ||
} | ||
} | ||
// Copyright 2004-2013 Castle Project - http://www.castleproject.org/ | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace CastleTests.DynamicProxy.Tests.Classes | ||
{ | ||
public class ClassWithMethodWithParameterWithNullDefaultValue | ||
{ | ||
public virtual bool Method(int? value = null) | ||
{ | ||
return value == null; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...sts/DynamicProxy.Tests/Interfaces/InterfaceWithMethodWithParameterWithNullDefaultValue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2004-2013 Castle Project - http://www.castleproject.org/ | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace CastleTests.DynamicProxy.Tests.Interfaces | ||
{ | ||
public interface InterfaceWithMethodWithParameterWithNullDefaultValue | ||
{ | ||
bool Method(int? value = null); | ||
} | ||
} |