I have this unit test:

        public void PopulatesPhoneProperty(
          string inputValue,
          string expectedValue)
          Entity source,
          [NoDefaultEnum] ConcreteUserMapper sut,
            source.LogicalName = "user";
            source.Attributes.Add("phone", inputValue);


The problem is that I want my last two test method parameters (sut and source) to be instantiated automatically without explicitly doing so. And right now it does not work (Not enough arguments provided, provide at least 4 arguments). Anyone has any solution for that? I searched for a day and could not find anything that can help me.

internal class PhoneNumberTestCases : IEnumerable
    public IEnumerator GetEnumerator()
        yield return new object[] { "800) 814-1103 ext. 3120 ext.", "80081411033120" };
        yield return new object[] { "80081411033120", "80081411033120" };
        yield return new object[] { "1a2b3cc4dd800", "1234800" };
        yield return new object[] { "555.555.5555", "5555555555" };
        yield return new object[] { "555-555-5555", "5555555555" };
        yield return new object[] { "555.555.5555", "5555555555" };
        yield return new object[] { "555?555!5555", "5555555555" };
        yield return new object[] { "555-555-5555 x6666", "55555555556666" };
        yield return new object[] { string.Empty, string.Empty };
        yield return new object[] { null, null };


New contributor
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Your syntax looks incorrect... how many arguments doe the function really have? – Martin K Feb 14 at 21:06
  • I posted the PhoneNumberTestCases (above). So the first two parameters are from PhoneNumberTestCases and the last two are the ones that I want to use AutoMoq to instantiate them. – Ben Feb 15 at 4:40
  • The arguments go inside the round brackets. public void PopulatesPhoneProperty(string inputValue, string expectedValue) has two arguments. – Martin K 2 days ago
  • Just to clarify, that error is at runtime and not compile time – Ben 2 days ago

I'm a bit rusty on nunit, but I believe the test source attribute needs all the method arguments specified for the method being decorated.

Your simplest option is to remove the automoq attribute from the test and change your test case class to instantiate the mock objects you want to pass into that test.

  • Thanks for your reply. Yes I think you are right.It does need all method arguments. – Ben yesterday

Your Answer

Ben is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.