This is the code To test:
public short GetNextAvilableControllerAddress(Guid networkUID)
{
return this.Client.GetNextAvilAddress(networkUID);
}
In the ControllerClientRepository class.
The Test class is this:
namespace AM6.DDServer.Client.Test.Common.Repository
{
using System;
using AM6.DDServer.Client.Common.BaseTypes;
using AM6.DDServer.Client.Common.Interfaces;
using AM6.DDServer.Client.GUI.Repository;
using DDS.AM6.Common.Data.Client;
using DDS.AM6.Common.Interfaces.WebServices;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TypeMock.ArrangeActAssert;
using WcfHelper.Common;
using ObjectState = TypeMock.ObjectState;
[TestClass]
[Isolated]
public class ControllerClientRepositoryTest
{
private ControllersClientRepository _repository;
private IControllerWebService _client;
[TestInitialize]
public void init()
{
Isolate.Fake.StaticConstructor<ControllersClientRepository>();
Isolate.Fake.StaticConstructor<ClientRepositoryGeneralBase>();
this._repository = Isolate.Fake.Instance<ControllersClientRepository>(Members.CallOriginal, ConstructorWillBe.Ignored);
AM6DataEntitiesContext fakeContext = Isolate.Fake.Instance<AM6DataEntitiesContext>();
Isolate.Swap.NextInstance<AM6DataEntitiesContext>().With(fakeContext);
var fakeCache = Isolate.Fake.Instance<IAmCache>();
ObjectState.SetField(this._repository, "_cache", fakeCache);
_client = Isolate.Fake.Instance<IControllerWebService>();
Isolate.WhenCalled(() => ServiceLocator.GetProxy<IControllerWebService>()).WillReturn(_client);
}
[TestMethod]
public void GetNextAvilableControllerAddress_ProxyMethodReturnTwo_ReturnsTwo()
{
//Arrange
Isolate.WhenCalled(() => _client.GetNextAvilAddress(Guid.Empty)).WillReturn(2);
//Act
var res = _repository.GetNextAvilableControllerAddress(Guid.Empty);
//Assert
Assert.AreEqual(2, res);
}
}
}
When running this test with Resharper I' getting this 2 optional results:
a. Test success - While running this test alone or the test-class alone
b. This Exception -
Initialization method AM6.DDServer.Client.Test.Common.Repository.ControllerClientRepositoryTest.init threw exception. System.Reflection.TargetInvocationException: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> TypeMock.TypeMockException:
*** No method with name init>b__0 in type AM6.DDServer.Client.Test.Common.Repository.ControllerClientRepositoryTest exists..
at f8.b(Type A_0, String A_1)
at et.a(Mock A_0, Object A_1, MethodBase A_2, Object A_3, Object[] A_4)
at gc.b(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
at TypeMock.MockManager.getReturn(Object context, String typeName, String methodName, Object methodGenericParams, Boolean isDecorated, Boolean isInterceptedType, Object[] methodArguments)
at Typemock.Interceptors.Profiler.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Boolean isInterceptedType)
at AM6.DDServer.Client.Test.Common.Repository.ControllerClientRepositoryTest.<init>b__0() in ControllerClientRepositoryTest.cs: line 39
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.UnsafeInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at gj.c()
at bh.a(Boolean A_0)
at dl.b(Boolean A_0)
at ik.b(Boolean A_0)
at ik.a(Object A_0, Boolean A_1, Func`1 A_2, Action A_3, Action A_4, Action A_5, Boolean A_6)
at ik.e(Object A_0)
at AM6.DDServer.Client.Test.Common.Repository.ControllerClientRepositoryTest.init() in ControllerClientRepositoryTest.cs: line 39
at TypeMock.MockManager.getReturn(Object context, String typeName, String methodName, Object methodGenericParams, Boolean isDecorated, Boolean isInterceptedType, Object[] methodArguments)
at Typemock.Interceptors.Profiler.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Boolean isInterceptedType)
at AM6.DDServer.Client.Test.Common.Repository.ControllerClientRepositoryTest.init() in ControllerClientRepositoryTest.cs: line 30
while running the whole assmbly tests or upper level.
this behavior is happen in 3 tests! is there somthing in Isolation I'm doing wrong?