Can you explain the purpose of the test?  I see that in the test setup
(Setup()) you're calling .Open() after setting an endpoint to
http://localhost:9090

This seems odd to me, but I don't know exactly what you're trying to test in
order to be able to give useful feedback.

If you give me more info I can dig in.

Tim

On Wed, Sep 8, 2010 at 2:36 PM, Tim Barcz <[email protected]> wrote:

> What error do you get, when I copy/paste the code above I get (is this what
> you're seeing):
>
> Test 'Rhino.Mocks.Tests.FieldsProblem.Tester.Test' failed:
> System.ServiceModel.AddressAccessDeniedException : HTTP could not register
> URL http://+:9090/. Your process does not have access rights to this
> namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).
>   ----> System.Net.HttpListenerException : Access is denied
> TearDown : System.ServiceModel.CommunicationObjectFaultedException : The
> communication object, System.ServiceModel.ServiceHost, cannot be used for
> communication because it is in the Faulted state.
>  at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
> at
> System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener
> channelListener)
>  at
> System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback
> selectTransportManagerCallback)
> at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan
> timeout)
>  at System.ServiceModel.Channels.HttpChannelListener.OnOpen(TimeSpan
> timeout)
> at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
>  at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan
> timeout)
> at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
>  at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
> at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
>  at System.ServiceModel.Channels.CommunicationObject.Open()
> FieldsProblem\FieldProblem_ Edward.cs(85,0): at
> Rhino.Mocks.Tests.FieldsProblem.Tester.Setup()
>  --HttpListenerException
> at System.Net.HttpListener.AddAll()
> at System.Net.HttpListener.Start()
>  at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
> --TearDown
>  at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan
> timeout)
> at System.ServiceModel.Channels.CommunicationObject.Close()
>  FieldsProblem\FieldProblem_ Edward.cs(91,0): at
> Rhino.Mocks.Tests.FieldsProblem.Tester.TearDown()
>
>
>
> On Tue, Sep 7, 2010 at 5:16 AM, Edward <[email protected]> wrote:
>
>> Hi, i have the following problem: i want to test an abstract class
>> that contains a method that calls a wcf service. I mock the wcf
>> service and use a partial mock to mock the abstract class. The problem
>> is that the wcf service throws a timeout exception when i set an
>> expectation to the abstract class.The example below replicates the
>> issue.
>>
>> using System;
>> using System.Collections.Generic;
>> using System.Linq;
>> using System.Text;
>> using NUnit.Framework;
>> using Rhino.Mocks;
>> using System.ServiceModel;
>> using Rhino.Mocks.Interfaces;
>> using System.ServiceModel.Channels;
>>
>> namespace TestLib
>> {
>>
>>  
>> //-------------------------------------------------------------------------------
>>
>>    [ServiceContract]
>>    public interface ICalculatorService
>>    {
>>        [OperationContract]
>>        [FaultContract(typeof(ArgumentNullException))]
>>        double Multiply(double x, double y);
>>    }
>>
>>    public abstract class AbstractShape
>>    {
>>        protected internal abstract double CalculateArea();
>>
>>        public double GetArea()
>>        {
>>            //Do some other stuff...
>>            return CalculateArea();
>>        }
>>    }
>>
>>    public abstract class Circle : AbstractShape
>>    {
>>        //This method should be abstract, i made it virtual just to
>> see
>>        //that when not setting an expectation the test will pass.
>>        protected internal virtual double GetRadius()
>>        {
>>            return 15;
>>        }
>>
>>        protected internal override double CalculateArea()
>>        {
>>            ICalculatorService client =
>> ChannelFactory<ICalculatorService>
>>                .CreateChannel(new BasicHttpBinding(), new
>> EndpointAddress("http://localhost:9090";));
>>
>>            double radius = GetRadius();
>>            double result = client.Multiply(radius, radius);
>>
>>            result = client.Multiply(Math.PI, result);
>>
>>            ((IChannel)client).Close();
>>
>>            return result;
>>        }
>>    }
>>
>>
>>  
>> //-----------------------------------------------------------------------------------------------------
>>
>>    [TestFixture]
>>    public class Tester
>>    {
>>        private MockRepository _mocks;
>>        private ICalculatorService _calculatorServiceMock;
>>        private ServiceHost _calculatorServiceHost;
>>        private Circle _circleMock;
>>
>>        [SetUp]
>>        public void Setup()
>>        {
>>
>>
>> Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add(typeof(ServiceContractAttribute));
>>
>>
>> Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add(typeof(OperationContractAttribute));
>>
>>            _mocks = new MockRepository();
>>            _calculatorServiceMock =
>> _mocks.DynamicMock<ICalculatorService>();
>>            _circleMock = _mocks.PartialMock<Circle>();
>>
>>            _calculatorServiceHost = new
>> ServiceHost(_calculatorServiceMock, new Uri[] { new Uri("http://
>> localhost:9090") });
>>
>> _calculatorServiceHost.AddServiceEndpoint(typeof(ICalculatorService),
>> new BasicHttpBinding(), String.Empty);
>>
>>
>> _calculatorServiceHost.Description.Behaviors.Find<ServiceBehaviorAttribute>().InstanceContextMode
>> = InstanceContextMode.Single;
>>            _calculatorServiceHost.Open();
>>        }
>>
>>        [TearDown]
>>        public void TearDown()
>>        {
>>            _calculatorServiceHost.Close();
>>        }
>>
>>        [Test]
>>
>> [ExpectedException(typeof(FaultException<ArgumentNullException>))]
>>        public void Test()
>>        {
>>            using (_mocks.Record())
>>            {
>>                //If we don't set this expectation the test will pass.
>>                Expect.Call(_circleMock.GetRadius()).Return(17);
>>
>>                Expect.Call(_calculatorServiceMock.Multiply(0,
>> 0)).IgnoreArguments()
>>                    .Throw(new
>> FaultException<ArgumentNullException>(new
>> ArgumentNullException("Forced Exception!")));
>>            }
>>
>>            _mocks.ReplayAll();
>>
>>            try
>>            {
>>                _circleMock.GetArea();
>>            }
>>            finally
>>            {
>>                _mocks.VerifyAll();
>>            }
>>        }
>>    }
>>
>>
>>  
>> //---------------------------------------------------------------------------------------------------
>> }
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Rhino.Mocks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<rhinomocks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/rhinomocks?hl=en.
>>
>>
>
>
> --
> Tim Barcz
> Microsoft C# MVP
> Microsoft ASPInsider
> http://timbarcz.devlicio.us
> http://www.twitter.com/timbarcz
>
>


-- 
Tim Barcz
Microsoft C# MVP
Microsoft ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en.

Reply via email to