0

my class is like:

public class BillingAccountBLService : IBillingAccountBLService
{
    [SetterProperty]
    public IContractService ContractService { get; set; }

    public BillingAccountBLService()
    {
        ObjectFactory.BuildUp(this);
     }
}

in my test:

[Test]
public void ContractDoesNotExist()
{
   var mocks = new RhinoAutoMocker<BillingAccountBLService>();
   var service = mocks.ClassUnderTest;
   ...

on this row exception thrown "StructureMap.StructureMapConfigurationException : No default Instance is registered and cannot be automatically determined for type..." (type of first injected service)

how should i fix this?

thanks!

Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
arielorvits
  • 5,235
  • 8
  • 36
  • 61
  • Try mocking your Interface instead of your implementation, not sure if that will work as I am not familiar with how RhinoAutoMocker works but with Moq I typically mock the interface. I also am unsure what you are trying to test here. – JCisar May 03 '16 at 21:56
  • @JCisar, I cant mock the interface "public class RhinoAutoMocker : AutoMocker where T : class" https://github.com/structuremap/structuremap/blob/master/src/StructureMap.AutoMocking/RhinoAutoMocker.cs what i'm trying to test isn't rellevant. – arielorvits May 04 '16 at 07:21
  • I assume that `ObjectFactory` is StructureMap, if so the problem is you didn't register `BillingAccountBLService` in your IOC container. – Old Fox May 04 '16 at 10:26
  • I has this row - "For().Use();" in my registry file. it cant be the problem, because the class working OK, just the test not working – arielorvits May 04 '16 at 10:45
  • @user3202422 so you didn't call the registration method before `var mocks = new RhinoAutoMocker(); var service = mocks.ClassUnderTest;`.... – Old Fox May 04 '16 at 14:01
  • it also cant be the problem, since this test work perfect before i tried automocking. it had in the beginning of it: `**public Mock MockContractService { get; set; } [SetUp] public void Setup() { **MockContractService = new Mock(); **ObjectFactory.Inject(MockContractService.Object); }` then i deleted this rows with **, and try using automocking, but didnt succeeded – arielorvits May 04 '16 at 16:25

0 Answers0