Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test run button that you can point to a unit test class #256

Open
philcarbone opened this issue Jun 5, 2019 · 3 comments · May be fixed by christian7877/try#5
Open

Add unit test run button that you can point to a unit test class #256

philcarbone opened this issue Jun 5, 2019 · 3 comments · May be fixed by christian7877/try#5

Comments

@philcarbone
Copy link

Is your feature request related to a problem? Please describe.
As a person teaching .NET, I would appriciate the ability to ask a question and have the user "try" something in C# to answer the question or fulfill the requirement, and get feedback (success or fail) and maybe a message.

Describe the solution you'd like
It would be nice to write unit tests against a class or method that could be used as a way to provide feedback to the learner. This would be a great way to make this a powerhouse learning/teaching tool.

Describe alternatives you've considered
None yet

(I apologize I wrote this on my phone. I will provide examples once I'm on a large screen again)

@LadyNaggaga
Copy link
Collaborator

LadyNaggaga commented Jun 5, 2019

Hi! Have a look at this issue #123 . Is this the kind of experience you are describing ?

@rchande
Copy link

rchande commented Jun 5, 2019

@philcarbone You can also accomplish something like this using our "regions" functionality. If you try the below example, the user gets a compilation error if they don't return a boolean, a success message if they return true, and a failure message if they return false.

Here's what the markdown file would contain (replace quote chars with backticks)

Change your code to return a value. Specifically, you should return a true boolean.

'''cs --source-file ./Program.cs --project ./tutorial.csproj --region TestUserCode
'''

And here's what Program.cs would contain:

using System;
using System.Threading.Tasks;

namespace tutorial
{
    public class Program
    {
        static int Main(
            string region = null,
            string session = null,
            string package = null,
            string project = null,
            string[] args = null)
        {
            return region switch
            {
                "TestUserCode" => TestUserCode(),
                _ => 0
            };
        }

        public static int TestUserCode()
        {
           var result = UserCodeGoesHere();
           if (result)
           {
               Console.WriteLine("Good job!");
           }
           else
           {
               Console.WriteLine("Try again :(");
           }
            return 0;
        }

        private static bool UserCodeGoesHere()
        {
            #region TestUserCode
            #endregion
        }
    }
}

@rchande
Copy link

rchande commented Jun 5, 2019

Oh, and here's the contents of tutorial.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <LangVersion>8.0</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.CommandLine.DragonFruit" Version="0.2.0-alpha.19226.1" />
    <PackageReference Include="System.CommandLine.Experimental" Version="0.2.0-alpha.19226.1" />
  </ItemGroup>

</Project>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants