Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a class.
public class VoiceElementsLine : ILine
       public Guid LineId { get; set; }
       public TelephonyServer TelephonyServer { get; set; }
       public virtual ChannelResource ChannelResource { get; set; }
       public LanguageData LangInfo { get; set; }

       public string InboundDnis
           get { return _inboundDnis; }

       private readonly Logger _appLog = GetCurrentLogger();
       private SipChannel _incomingSipChannel;
       public VoiceResource IncomingVoiceResource { get; private set; }
       private ServerInfo _serverInfo;
       private string _inboundDnis, _inboundAni, _inboundIp;
       private DateTime _callDate;

       public void RunCallScript()
           var callFlowApp = GetCallFlowApplication();

       private void AnswerSipChannel()

       public ICallFlowApplication GetCallFlowApplication()
           var inboundValues = _inboundDnis.Split('_');
           var appId = byte.Parse(inboundValues[0]);

           var appFactory = GetApplicationFactoryInstance();
           var callFlowApp = appFactory.GetApplication(appId);
           return callFlowApp;

       public IApplicationFactory GetApplicationFactoryInstance()
           return VoiceElementsCallFlowService.Container.GetInstance<IApplicationFactory>();

       public void PlayPromptTextToSpeech(string promptText)

       public void PlayPromptFile(string promptFile)

       public string GetUserInput(int maxDigits)
           IncomingVoiceResource.MaximumDigits = maxDigits;
           return IncomingVoiceResource.DigitBuffer;

       private void in_ChannelResource_Disconnected(object sender, DisconnectedEventArgs e)
           _appLog.Info("Inbound Disconnect Event");

       public void SetupLine()
               _incomingSipChannel = ChannelResource as SipChannel;
               _incomingSipChannel.Disconnected += in_ChannelResource_Disconnected;
               _serverInfo = TelephonyServer.GetServerInfo();
               IncomingVoiceResource = _incomingSipChannel.VoiceResource;
               IncomingVoiceResource.Codec = Codec.PCM_8Khz_8Bit;

               _inboundDnis = ChannelResource.Dnis;
               // Ex: if dialstring is facilityidInmatePIN@
               // then InboundDnis = languagefacilityIdInmatePIN; 1_1_163_1234@
               _inboundAni = ChannelResource.Ani;
               _inboundIp = _incomingSipChannel.RemoteCallControlAddress;
               _callDate = DateTime.Now;

           catch (Exception ee)

The corresponding interface ILine
public interface ILine
       Guid LineId { get; set; }

       void RunCallScript();
       void PlayPromptTextToSpeech(string promptText);
       void PlayPromptFile(string promptFile);
       string GetUserInput(int maxDigits);
       void Hangup();

In my unit tests, first I want to make sure the method SetupLine is executed. So I use Moq.
        public void SetupLine_Should_Properly_Setup_Codec()
            // ARRANGE
            Mock<VoiceElementsLine> voiceElementsLineMock = new Mock<VoiceElementsLine>()
            { CallBase = true};
            Mock<TelephonyServer> telephonyServerMock = new Mock<TelephonyServer>();
            Mock<ChannelResource> channelResourceMock = new Mock<ChannelResource>(telephonyServerMock) ;
            voiceElementsLineMock.SetupGet(x => x.ChannelResource).Returns(channelResourceMock.Object);
            var voiceElementsLine = voiceElementsLineMock.Object;

            // ACT

            // ASSERT
            Assert.True(voiceElementsLine.IncomingVoiceResource.Codec== Codec.PCM_8Khz_8Bit);

Please notice notice ChannelResource has a constructor which is TelephonyServer.
However I got the error
An exception of type 'System.NotSupportedException' occurred in mscorlib.dll but was not handled in user code

Thanks for help with the code and hints.
Updated 10-Jan-23 6:03am
ZurdoDev 15-Oct-15 9:08am    
The error tells you what to do. What exactly is your question?

In your test, you are mocking the concrete class 'VoiceElementsLine'. You should be mocking interfaces - not concrete classes (though you are able to do so in Moq if the concrete class has a public default constructor).

So, in your test you should use:
Mock<ILine> voiceElementsLineMock = new Mock<ILine>() { CallBase = true};
Share this answer
I supose your class
dont have a default constructor or empty,
public void ChannelResource(){}
Share this answer
[no name] 15-Oct-15 9:31am    
But it has a constructor. Even I imagine it doesn't have a default constructor, the error is still there.
you need to implement all mehtos of teh interface, public void Hangup(){} is not implement yet
Share this answer

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