daveoftheparty / speedy-moq

Generate boilerplate code for Moq in C#
MIT License
1 stars 0 forks source link

generate using statements #18

Closed daveoftheparty closed 3 years ago

daveoftheparty commented 3 years ago

Our users are going to probably invoke our code generator inside a test file that might look as simple as this:

using NUnit.Framework; // or some other framework

namespace UnitTests.Features.TestData
{
    public class StringAnalyzerTests
    {
        [Test]
        public void HappyPath()
        {
            IStringAnalyzer
        }
    }
}

where IStringAnalyzer is an interface defined in a referenced project. I do not want to expend the time and energy to import all the various user types and libraries, however, I think we should at minimum go ahead and add the following using statements to the file (if they don't already exist) because they are the bare minimum for the generated code to be valid:

using System;
using System.Linq.Expressions;
using Moq;

I don't even really care how they are ordered or formatted except that they should be at the top of the file, before the namespace declaration, and not obliterate any existing using statements the user has already entered.

We can implement this by appending a second TextEdit to the output of IDiagnoser-- we'll still have to do a little file parsing to know where to put the usings, but, we could separate that concern from the concern of generating the "main" code into another service, for example.