I'm unsure of what else can be tested for my method TranslateResponse()
.
It basically checks the type of translator and calls the translator's associated set()
method.
public async Task TranslateResponse(Policy response)
{
foreach (var t in await _translatorFactory.BuildTranslators())
{
var policyTranslator = t as IPolicyAwareTranslator;
policyTranslator?.SetPolicy(response);
var additionalInterestTranslator = t as IAdditionalInterestAwareTranslator;
additionalInterestTranslator?.SetAdditionalInterests(response.AdditionalInterests);
var locationsTranslator = t as ILocationsAwareTranslator;
locationsTranslator?.SetLocations(response.Locations);
}
}
I'm writing test cases for the TranslateResponse()
method. As far as I figured out, I'm verifying that the calls to respective methods happens based on the provided type of translator.
The test case lines
Mock<ITranslator> mockedTranslator = new Mock<ITranslator>();
mockedTranslator.Setup(t => t.Translate(_translatorDataAccessor.Object));
var mockedPolicyTranslator = mockedTranslator.As<IPolicyAwareTranslator>();
mockedPolicyTranslator.Setup(t => t.SetPolicy(It.IsAny<Policy>()));
mockedPolicyTranslator.Verify(t => t.SetPolicy(It.IsAny<Policy>()), Times.AtLeastOnce);
My concerns are
I'm curious to know whether I can test something more than verifying calls?
Should I test for the logic of the set() method here or in it's own class? Even, then I'm not able to figure out what to Assert in the test case for the
Set()
which will set the private field with the passed in argument.
public class PolicyTranslator : ITranslator, IPolicyAwareTranslator
{
private Policy _policy;
public void SetPolicy(Policy policy)
{
_policy = policy;
}
//translate()
}