Skip to content

Commit

Permalink
more tests and indention fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kkozmic committed Dec 1, 2013
1 parent 8163b42 commit 3defb9e
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 84 deletions.
1 change: 1 addition & 0 deletions src/Castle.Core.Tests/Castle.Core.Tests.csproj
Expand Up @@ -254,6 +254,7 @@
<Compile Include="DynamicProxy.Tests\Classes\ClassWithMethodWithParameterWithNullDefaultValue.cs" />
<Compile Include="DynamicProxy.Tests\ClassProxyWithDefaultValuesTestCase.cs" />
<Compile Include="DynamicProxy.Tests\GenericInterfaceWithGenericMethod.cs" />
<Compile Include="DynamicProxy.Tests\Interfaces\InterfaceWithMethodWithParameterWithNullDefaultValue.cs" />
<Compile Include="MultipleSavedAssembliesTestCase.cs" />
<Compile Include="Components.DictionaryAdapter.Tests\AdaptingGenericDictionaryTestCase.cs" />
<Compile Include="Components.DictionaryAdapter.Tests\VirtualObjectTestCase.cs" />
Expand Down
@@ -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
}
}
@@ -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;
}
}
}
@@ -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);
}
}

0 comments on commit 3defb9e

Please sign in to comment.