0

In my existing project, I am using xunit. Currently, it's very irritating to mock each instant in service. So I decided to use AutoMock but my project is very vast and I have already done a lot of code and assigned a lot of values. So is this any way that without changing existing mock object I can use AutoMock? Below is my existing code sample. I am planning to use AutoFac

Currently, if I want to set up any value I am doing

bordereauFormatsRepositoryMock
    .Setup(x => x.GetBordereauFormats(It.IsAny<List<string>>()))
    .Returns(botFormatsVMList);*

In AutoMock -

mock.Mock<IBordereauFormatsRepository>()
    .Setup(x => x.GetBordereauFormats(It.IsAny<List<string>>()))
    .Returns(botFormatsVMList)*;

So How can I assign bordereauFormatsRepositoryMock to mock.Mock<IBordereauFormatsRepository>()?

public BotMockTest()
{
    #region Object initialization
    botFormatsVMList = new List<BotFormatsVM>();
    botFormatsVM = new BotFormatsVM();
    botService = new BotService(bordereauFormatsRepositoryMock.Object, bordereauFormatColumnRepositoryMock.Object, contractRepository.Object, bordereauxRepositoryMock.Object, exceptionLogServiceMock.Object);
    #endregion
}

[FactWithAutomaticDisplayName]
public void GetBordereauFormats()
{
    //Arrange
    List<string> sheetList = new List<string>() { { "sheet" } };
    botFormatsVM.BordereauFormatId = Guid.Parse("847AE6BD-C20E-4377-8F56-36D58674C961");
    botFormatsVMList.Add(botFormatsVM);
    bordereauFormatsRepositoryMock.Setup(x => x.GetBordereauFormats(It.IsAny<List<string>>())).Returns(botFormatsVMList);

    //Act
    botService.GetBordereauFormats(sheetList);

    //Assert
    Assert.True(botFormatsVM.BordereauFormatName == "UpdatedVal");
}
Nkosi
  • 235,767
  • 35
  • 427
  • 472
Dhanashri
  • 39
  • 5
  • I don't understand this sample. You're setting botFormatsVM.BordereauFormatId to a value and then later on you assert that it is equal to the same value. Of course it's going to be true, you've just set it yourself to that value ... – Andrei Dragotoniu Jun 21 '19 at 12:06
  • Ignore what I have asserted in that. My question is previously I used to mock each and every instance separately. [bordereauFormatsRepositoryMock.Object] How can I use the same instance in AutoFace? Without changing much code I want to use AutoFace? – Dhanashri Jun 21 '19 at 12:17

0 Answers0