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");
}