Commit 6f5bf8d4 authored by csharptest's avatar csharptest Committed by rogerk

Removed dependency on Rhino.Mocks

Added CleanAll batch file
Added the now rhino-free service test to silverlight
parent 2622011a
@echo off
CMD.exe /Q /C "CD %~dp0 && %WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe build.csproj /toolsversion:4.0 "/t:Clean" "/p:BuildConfiguration=Release;TargetVersion=2"
CMD.exe /Q /C "CD %~dp0 && %WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe build.csproj /toolsversion:4.0 "/t:Clean" "/p:BuildConfiguration=Debug;TargetVersion=2"
CMD.exe /Q /C "CD %~dp0 && %WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe build.csproj /toolsversion:4.0 "/t:Clean" "/p:BuildConfiguration=Release_Silverlight;TargetVersion=2"
CMD.exe /Q /C "CD %~dp0 && %WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe build.csproj /toolsversion:4.0 "/t:Clean" "/p:BuildConfiguration=Debug_Silverlight;TargetVersion=2"
<?xml version="1.0" encoding="Windows-1252"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime version="v4.0.30319" safemode="true"/>
<startup>
<requiredRuntime version="v2.0.50727" />
</startup>
<runtime>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Copyright © 2002-2007 Charlie Poole
Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
Copyright © 2000-2002 Philip A. Craig
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment (see the following) in the product documentation is required.
Portions Copyright © 2002-2007 Charlie Poole or Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov or Copyright © 2000-2002 Philip A. Craig
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Copyright (c) 2005 - 2008 Ayende Rahien (ayende@ayende.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Ayende Rahien nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
......@@ -59,10 +59,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\NUnit\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Rhino.Mocks, Version=3.5.0.2, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Rhino.Mocks.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Data" />
......
......@@ -117,6 +117,7 @@
<Compile Include="ReflectionTester.cs" />
<Compile Include="ReusableBuilderTest.cs" />
<Compile Include="SerializableAttribute.cs" />
<Compile Include="ServiceTest.cs" />
<Compile Include="TestCornerCases.cs" />
<Compile Include="TestMimeMessageFormats.cs" />
<Compile Include="TestProtos\UnitTestCSharpOptionsProtoFile.cs" />
......
......@@ -62,10 +62,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\NUnit\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Rhino.Mocks, Version=3.5.0.2, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Rhino.Mocks.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Data" />
......
......@@ -38,9 +38,6 @@ using System;
using Google.ProtocolBuffers.Descriptors;
using Google.ProtocolBuffers.TestProtos;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
using Rhino.Mocks.Constraints;
using Is = Rhino.Mocks.Constraints.Is;
namespace Google.ProtocolBuffers
{
......@@ -77,10 +74,9 @@ namespace Google.ProtocolBuffers
[TestMethod]
public void CallMethodFoo()
{
MockRepository mocks = new MockRepository();
FooRequest fooRequest = FooRequest.CreateBuilder().Build();
FooResponse fooResponse = FooResponse.CreateBuilder().Build();
IRpcController controller = mocks.StrictMock<IRpcController>();
IRpcController controller = new RpcTestController();
bool fooCalled = false;
......@@ -98,60 +94,18 @@ namespace Google.ProtocolBuffers
doneHandlerCalled = true;
});
using (mocks.Record())
{
// No mock interactions to record
}
service.CallMethod(FooDescriptor, controller, fooRequest, doneHandler);
Assert.IsTrue(doneHandlerCalled);
Assert.IsTrue(fooCalled);
mocks.VerifyAll();
}
private delegate void CallFooDelegate(MethodDescriptor descriptor, IRpcController controller,
IMessage request, IMessage response, Action<IMessage> doneHandler);
/// <summary>
/// Tests the generated stub handling of Foo. By this stage we're reasonably confident
/// that the choice between Foo and Bar is arbitrary, hence the lack of a corresponding Bar
/// test.
/// </summary>
[TestMethod]
[Ignore, System.ComponentModel.Description("Crashes Mono - needs further investigation")]
public void GeneratedStubFooCall()
{
FooRequest fooRequest = FooRequest.CreateBuilder().Build();
MockRepository mocks = new MockRepository();
IRpcChannel mockChannel = mocks.StrictMock<IRpcChannel>();
IRpcController mockController = mocks.StrictMock<IRpcController>();
TestGenericService service = TestGenericService.CreateStub(mockChannel);
Action<FooResponse> doneHandler = mocks.StrictMock<Action<FooResponse>>();
using (mocks.Record())
{
// Nasty way of mocking out "the channel calls the done handler".
Expect.Call(() => mockChannel.CallMethod(null, null, null, null, null))
.IgnoreArguments()
.Constraints(Is.Same(FooDescriptor), Is.Same(mockController), Is.Same(fooRequest),
Is.Same(FooResponse.DefaultInstance), Is.Anything())
.Do((CallFooDelegate) ((p1, p2, p3, response, done) => done(response)));
doneHandler(FooResponse.DefaultInstance);
}
service.Foo(mockController, fooRequest, doneHandler);
mocks.VerifyAll();
}
[TestMethod]
public void CallMethodBar()
{
MockRepository mocks = new MockRepository();
BarRequest barRequest = BarRequest.CreateBuilder().Build();
BarResponse barResponse = BarResponse.CreateBuilder().Build();
IRpcController controller = mocks.StrictMock<IRpcController>();
IRpcController controller = new RpcTestController();
bool barCalled = false;
......@@ -169,19 +123,109 @@ namespace Google.ProtocolBuffers
doneHandlerCalled = true;
});
using (mocks.Record())
{
// No mock interactions to record
}
service.CallMethod(BarDescriptor, controller, barRequest, doneHandler);
Assert.IsTrue(doneHandlerCalled);
Assert.IsTrue(barCalled);
mocks.VerifyAll();
}
[TestMethod]
public void GeneratedStubFooCall()
{
IRpcChannel channel = new RpcTestChannel();
IRpcController controller = new RpcTestController();
TestGenericService service = TestGenericService.CreateStub(channel);
FooResponse fooResponse = null;
Action<FooResponse> doneHandler = r => fooResponse = r;
service.Foo(controller, FooRequest.DefaultInstance, doneHandler);
Assert.IsNotNull(fooResponse);
Assert.IsFalse(controller.Failed);
}
[TestMethod]
public void GeneratedStubBarCallFails()
{
IRpcChannel channel = new RpcTestChannel();
IRpcController controller = new RpcTestController();
TestGenericService service = TestGenericService.CreateStub(channel);
BarResponse barResponse = null;
Action<BarResponse> doneHandler = r => barResponse = r;
service.Bar(controller, BarRequest.DefaultInstance, doneHandler);
Assert.IsNull(barResponse);
Assert.IsTrue(controller.Failed);
}
#region RpcTestController
private class RpcTestController : IRpcController
{
public string TestFailedReason { get; set; }
public bool TestCancelled { get; set; }
public Action<object> TestCancelledCallback { get; set; }
void IRpcController.Reset()
{
TestFailedReason = null;
TestCancelled = false;
TestCancelledCallback = null;
}
bool IRpcController.Failed
{
get { return TestFailedReason != null; }
}
string IRpcController.ErrorText
{
get { return TestFailedReason; }
}
void IRpcController.StartCancel()
{
TestCancelled = true;
if (TestCancelledCallback != null)
TestCancelledCallback(this);
}
void IRpcController.SetFailed(string reason)
{
TestFailedReason = reason;
}
bool IRpcController.IsCanceled()
{
return TestCancelled;
}
void IRpcController.NotifyOnCancel(Action<object> callback)
{
TestCancelledCallback = callback;
}
}
#endregion
#region RpcTestChannel
private class RpcTestChannel : IRpcChannel
{
public MethodDescriptor TestMethodCalled { get; set; }
void IRpcChannel.CallMethod(MethodDescriptor method, IRpcController controller, IMessage request, IMessage responsePrototype, Action<IMessage> done)
{
TestMethodCalled = method;
try
{
done(FooResponse.DefaultInstance);
}
catch (Exception e)
{
controller.SetFailed(e.Message);
}
}
}
#endregion
#region TestServiceImpl
private class TestServiceImpl : TestGenericService
{
private readonly Action<FooRequest, Action<FooResponse>> fooHandler;
......@@ -213,5 +257,6 @@ namespace Google.ProtocolBuffers
barHandler(request, done);
}
}
#endregion
}
}
\ No newline at end of file
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "proto", "proto", "{1F896D5C-5FC2-4671-9216-781CB8187EC7}"
ProjectSection(SolutionItems) = preProject
..\protos\tutorial\addressbook.proto = ..\protos\tutorial\addressbook.proto
......
......@@ -43,10 +43,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\NUnit\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Rhino.Mocks, Version=3.5.0.2, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Rhino.Mocks.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Data" />
......
......@@ -43,10 +43,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\NUnit\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Rhino.Mocks, Version=3.5.0.2, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Rhino.Mocks.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Data" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment