Click here to Skip to main content
15,889,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Say I have the class.
C#
public class FundsTransferAuthorization
    {
        public decimal MaxAmount { get; set; }
        public decimal MinAmount { get; set; }
        
        private readonly IPromptPlayer _promptPlayer;
        public FundsTransferAuthorization(IPromptPlayer promptPlayer)
        {
            _promptPlayer = promptPlayer;
            GetAuthorizationParameters();
        }

        private void GetAuthorizationParameters()
        {
            _maxDigit = _promptPlayer.MaxDigit;
             MaxAmount = Convert.ToDecimal(GetMaximumAmount());
             MinAmount = Convert.ToDecimal(GetMinimumAmount());
        }
        public virtual string GetMinimumAmount()
        {
            return ConfigurationManager.AppSettings["minimumAmount"];
        }
        public virtual string GetMaximumAmount()
        {
            return ConfigurationManager.AppSettings["maximumAmount"];
        }

I want to mock up two values in app.config with Moq. How?
Posted

1 solution

You cannot Mock a class so you may need to inject the configuration via constructor and redesign the class and its usage accordingly.
 
Share this answer
 
Comments
[no name] 10-Nov-15 10:07am    
In theory, I know. But I just want a sample code for that. Say the example at http://stackoverflow.com/questions/9486087/how-to-mock-configurationmanager-appsettings-with-moq. If a similar one for my case could be provided, it would be great.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900