JRockFL
asked on
Unit testing, moq, best practices
I have a setting repository that contains application settings that are stored in the database.
I currently have no unit test code coverage. The IService interface only contains one method for Get()
Get() returns a collection of Setting.
1. What should I be testing?
2.. What should I be naming the tests?
I currently have no unit test code coverage. The IService interface only contains one method for Get()
Get() returns a collection of Setting.
1. What should I be testing?
2.. What should I be naming the tests?
public class SettingServiceTest
{
private Mock<ISettingRepository> mockRepository;
private ISettingService service;
[TestInitialize]
public void Inititalize()
{
mockRepository = new Mock<ISettingRepository>();
service = new SettingService(mockRepository.Object);
}
[TestMethod]
public void Test_Get_Settings()
{
mockRepository
.Setup(x => x.Get())
.Returns(It.IsAny<List<Setting>>);
var result = service.Get();
mockRepository.Verify(x => x.Get());
}
}
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER