├── .gitattributes ├── .gitignore ├── README.md ├── Testura.Code.UnitTestGenerator.sln ├── settings └── Testura.ruleset └── src ├── Testura.Code.UnitTestGenerator.Tests ├── Generators │ ├── MockGenerators │ │ └── MoqGeneratorTests.cs │ └── UnitTestGenerators │ │ └── NUnitGeneratorsTests.cs ├── Helpers │ ├── MyAbstractClass.cs │ └── MyClassWithGeneric.cs ├── Properties │ └── AssemblyInfo.cs ├── Testura.Code.UnitTestGenerator.Tests.csproj └── packages.config ├── Testura.Code.UnitTestGenerator.UI ├── App.config ├── App.xaml ├── App.xaml.cs ├── Dialogs │ ├── InfoDialog.xaml │ └── InfoDialog.xaml.cs ├── FodyWeavers.xml ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Resources │ ├── Entypo.ttf │ ├── Icons │ │ ├── Icons-metro.xaml │ │ ├── Icons.xaml │ │ ├── IconsNonShared.xaml │ │ ├── logo128-new-white.ico │ │ └── logo128-new-white.png │ ├── Licenses │ │ ├── Entypo-license.txt │ │ └── WindowsIcons-license.txt │ ├── Styles │ │ ├── Accents │ │ │ └── testura.xaml │ │ └── Controls │ │ │ ├── Button.xaml │ │ │ ├── Colors.xaml │ │ │ ├── Font.xaml │ │ │ ├── GroupBox.xaml │ │ │ ├── Label.xaml │ │ │ ├── ListBox.xaml │ │ │ ├── ListView.xaml │ │ │ ├── Menu.xaml │ │ │ ├── ScrollBar.xaml │ │ │ ├── Styles.xaml │ │ │ ├── TabControl.xaml │ │ │ ├── TextBox.xaml │ │ │ ├── TreeView.xaml │ │ │ └── Window.xaml │ └── logo.png ├── Services │ ├── DialogService.cs │ ├── FileDialogService.cs │ ├── IDialogService.cs │ └── IFileDialogService.cs ├── Testura.Code.UnitTestGenerator.UI.csproj ├── ViewModel │ ├── MainViewModel.cs │ └── ViewModelLocator.cs ├── favicon.ico └── packages.config └── Testura.Code.UnitTestGenerator ├── Factories ├── MockGeneratorFactory.cs └── UnitTestGeneratorFactory.cs ├── Generators ├── MockGenerators │ ├── IMockGenerator.cs │ └── MoqGenerator.cs └── UnitTestClassGenerators │ ├── IUnitTestClassGenerator.cs │ ├── MsTestClassGenerator.cs │ ├── NunitTestClassGenerator.cs │ └── UnitTestClassGenerator.cs ├── Properties └── AssemblyInfo.cs ├── Services ├── FileService.cs └── IFileService.cs ├── Testura.Code.UnitTestGenerator.csproj ├── UnitTestGenerator.cs ├── Util └── Enums.cs └── packages.config /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Microsoft Azure ApplicationInsights config file 170 | ApplicationInsights.config 171 | 172 | # Windows Store app package directory 173 | AppPackages/ 174 | BundleArtifacts/ 175 | 176 | # Visual Studio cache files 177 | # files ending in .cache can be ignored 178 | *.[Cc]ache 179 | # but keep track of directories ending in .cache 180 | !*.[Cc]ache/ 181 | 182 | # Others 183 | ClientBin/ 184 | [Ss]tyle[Cc]op.* 185 | ~$* 186 | *~ 187 | *.dbmdl 188 | *.dbproj.schemaview 189 | *.pfx 190 | *.publishsettings 191 | node_modules/ 192 | orleans.codegen.cs 193 | 194 | # RIA/Silverlight projects 195 | Generated_Code/ 196 | 197 | # Backup & report files from converting an old project file 198 | # to a newer Visual Studio version. Backup files are not needed, 199 | # because we have git ;-) 200 | _UpgradeReport_Files/ 201 | Backup*/ 202 | UpgradeLog*.XML 203 | UpgradeLog*.htm 204 | 205 | # SQL Server files 206 | *.mdf 207 | *.ldf 208 | 209 | # Business Intelligence projects 210 | *.rdl.data 211 | *.bim.layout 212 | *.bim_*.settings 213 | 214 | # Microsoft Fakes 215 | FakesAssemblies/ 216 | 217 | # GhostDoc plugin setting file 218 | *.GhostDoc.xml 219 | 220 | # Node.js Tools for Visual Studio 221 | .ntvs_analysis.dat 222 | 223 | # Visual Studio 6 build log 224 | *.plg 225 | 226 | # Visual Studio 6 workspace options file 227 | *.opt 228 | 229 | # Visual Studio LightSwitch build output 230 | **/*.HTMLClient/GeneratedArtifacts 231 | **/*.DesktopClient/GeneratedArtifacts 232 | **/*.DesktopClient/ModelManifest.xml 233 | **/*.Server/GeneratedArtifacts 234 | **/*.Server/ModelManifest.xml 235 | _Pvt_Extensions 236 | 237 | # LightSwitch generated files 238 | GeneratedArtifacts/ 239 | ModelManifest.xml 240 | 241 | # Paket dependency manager 242 | .paket/paket.exe 243 | 244 | # FAKE - F# Make 245 | .fake/ 246 | /src/Testura.Android/Testura.Android.nuspec 247 | /src/Testura.Android/nuget.exe 248 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Testura Logo](https://i.ibb.co/z7WTnp2/logo2.png) 2 | 3 | 4 | Testura.Code.UnitTestGenerator is a simple framework/tool to inspect assemblies and generate unit tests from exported types. It's created as a simple example on how you can use [Testura.Code](https://github.com/Testura/Testura.Code) 5 | 6 | # Client 7 | 8 | [https://github.com/Testura/Testura.Code.UnitTestGenerator/releases](https://github.com/Testura/Testura.Code.UnitTestGenerator/releases) 9 | 10 | # Basic info 11 | 12 | ## Supported test frameworks 13 | 14 | * MsTest 15 | * NUnit 16 | 17 | ## Supported mock frameworks 18 | 19 | * Moq 20 | 21 | ## Will generate 22 | 23 | * A unit test file for all types that are exported and isn't static or abstract 24 | * A setUp that initialize the type under test (TuT) by looking at it's first constructor. 25 | * All required parameters will either be mocked, initialized or set to some default value. 26 | * Will generate fields for TuT and required parameters 27 | * All files created will follw your assembly namespace/directory strcture. 28 | 29 | ## Example usage from api 30 | 31 | ```c# 32 | var unitTestGenerator = new UnitTestGenerator(); 33 | unitTestGenerator.GenerateUnitTests(DllPath, TestFrameworks.NUnit, MockFrameworks.Moq, OutputDirectory); 34 | ``` 35 | 36 | ## GUI 37 | 38 | ![Gui](http://i.imgur.com/unqTfan.png) 39 | 40 | ## Example of generation 41 | 42 | ### Type under test 43 | 44 | ```c# 45 | namespace Testura.Android.Device.Services.Default 46 | { 47 | public class UiService 48 | { 49 | public UiService(IScreenDumper screenDumper, SomeClass someClass, string myString, int number) 50 | { 51 | } 52 | } 53 | } 54 | ``` 55 | 56 | ### Generated unit test 57 | 58 | ```c# 59 | namespace Testura.Android.Tests.Device.Services.Default 60 | { 61 | [TestFixture] 62 | public class UiServiceTest 63 | { 64 | private Mock screenDumperMock; 65 | private SomeClass someClass; 66 | private UIService uiService; 67 | 68 | [SetUp] 69 | public SetUp() 70 | { 71 | screenDumperMock = new Mock(); 72 | uiService = new UiService(screenDumperMock.Object, someClass, string.Empty, 0) 73 | } 74 | } 75 | } 76 | ``` 77 | 78 | -------------------------------------------------------------------------------- /Testura.Code.UnitTestGenerator.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26127.3 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testura.Code.UnitTestGenerator", "src\Testura.Code.UnitTestGenerator\Testura.Code.UnitTestGenerator.csproj", "{441975F9-7600-4280-9614-17F2843B1695}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testura.Code.UnitTestGenerator.Tests", "src\Testura.Code.UnitTestGenerator.Tests\Testura.Code.UnitTestGenerator.Tests.csproj", "{2018B986-C520-465B-A0E7-B66C190BA1EC}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testura.Code.UnitTestGenerator.UI", "src\Testura.Code.UnitTestGenerator.UI\Testura.Code.UnitTestGenerator.UI.csproj", "{623D495D-9775-4287-8D2A-1AB5E4718E8C}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Debug|x64 = Debug|x64 16 | Debug|x86 = Debug|x86 17 | Release|Any CPU = Release|Any CPU 18 | Release|x64 = Release|x64 19 | Release|x86 = Release|x86 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {441975F9-7600-4280-9614-17F2843B1695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {441975F9-7600-4280-9614-17F2843B1695}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {441975F9-7600-4280-9614-17F2843B1695}.Debug|x64.ActiveCfg = Debug|Any CPU 25 | {441975F9-7600-4280-9614-17F2843B1695}.Debug|x64.Build.0 = Debug|Any CPU 26 | {441975F9-7600-4280-9614-17F2843B1695}.Debug|x86.ActiveCfg = Debug|Any CPU 27 | {441975F9-7600-4280-9614-17F2843B1695}.Debug|x86.Build.0 = Debug|Any CPU 28 | {441975F9-7600-4280-9614-17F2843B1695}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {441975F9-7600-4280-9614-17F2843B1695}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {441975F9-7600-4280-9614-17F2843B1695}.Release|x64.ActiveCfg = Release|Any CPU 31 | {441975F9-7600-4280-9614-17F2843B1695}.Release|x64.Build.0 = Release|Any CPU 32 | {441975F9-7600-4280-9614-17F2843B1695}.Release|x86.ActiveCfg = Release|Any CPU 33 | {441975F9-7600-4280-9614-17F2843B1695}.Release|x86.Build.0 = Release|Any CPU 34 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Debug|x64.ActiveCfg = Debug|Any CPU 37 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Debug|x64.Build.0 = Debug|Any CPU 38 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Debug|x86.ActiveCfg = Debug|Any CPU 39 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Debug|x86.Build.0 = Debug|Any CPU 40 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Release|x64.ActiveCfg = Release|Any CPU 43 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Release|x64.Build.0 = Release|Any CPU 44 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Release|x86.ActiveCfg = Release|Any CPU 45 | {2018B986-C520-465B-A0E7-B66C190BA1EC}.Release|x86.Build.0 = Release|Any CPU 46 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Debug|x64.ActiveCfg = Debug|Any CPU 49 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Debug|x64.Build.0 = Debug|Any CPU 50 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Debug|x86.ActiveCfg = Debug|Any CPU 51 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Debug|x86.Build.0 = Debug|Any CPU 52 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Release|x64.ActiveCfg = Release|Any CPU 55 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Release|x64.Build.0 = Release|Any CPU 56 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Release|x86.ActiveCfg = Release|Any CPU 57 | {623D495D-9775-4287-8D2A-1AB5E4718E8C}.Release|x86.Build.0 = Release|Any CPU 58 | EndGlobalSection 59 | GlobalSection(SolutionProperties) = preSolution 60 | HideSolutionNode = FALSE 61 | EndGlobalSection 62 | EndGlobal 63 | -------------------------------------------------------------------------------- /settings/Testura.ruleset: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /src/Testura.Code.UnitTestGenerator.Tests/Generators/MockGenerators/MoqGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Microsoft.CodeAnalysis.Semantics; 4 | using NUnit.Framework; 5 | using Testura.Code.Models; 6 | using Testura.Code.UnitTestGenerator.Generators.MockGenerators; 7 | using Testura.Code.UnitTestGenerator.Tests.Helpers; 8 | 9 | namespace Testura.Code.UnitTestGenerator.Tests.Generators.MockGenerators 10 | { 11 | [TestFixture] 12 | public class MoqGeneratorTests 13 | { 14 | private MoqGenerator _moqGenerator; 15 | 16 | [SetUp] 17 | public void SetUp() 18 | { 19 | _moqGenerator = new MoqGenerator(); 20 | } 21 | 22 | [Test] 23 | public void CreateFields_WhenCreatingFieldsWithoutAnyMockTypes_ShouldOnlyContainTypeUnderTest() 24 | { 25 | var fields = _moqGenerator.GenerateFields( 26 | typeof(MoqGeneratorTests), 27 | new List()); 28 | Assert.AreEqual(1, fields.Count()); 29 | } 30 | 31 | [Test] 32 | public void CreateFields_WhenCreatingFieldsWithMockTypes_ShouldContainTypeUnderTestAndMockTypes() 33 | { 34 | var fields = _moqGenerator.GenerateFields( 35 | typeof(MoqGeneratorTests), 36 | new List { new Parameter("test", typeof(MoqGeneratorTests)) }); 37 | Assert.AreEqual(2, fields.Count()); 38 | } 39 | 40 | [Test] 41 | public void CreateFields_WhenCreatingFields_ShouldContainCorrectInformation() 42 | { 43 | var fields = _moqGenerator.GenerateFields( 44 | typeof(MoqGeneratorTests), 45 | new List()); 46 | Assert.AreEqual("privateMoqGeneratorTestsmoqGeneratorTests;", fields.First().ToString()); 47 | } 48 | 49 | [Test] 50 | public void CreateFields_WhenCreatingFieldsWithAbstractParameter_ShoulContainFieldAsMock() 51 | { 52 | var fields = _moqGenerator.GenerateFields( 53 | typeof(MoqGeneratorTests), 54 | new List { new Parameter("myMockClass", typeof(MyAbstractClass)) }); 55 | Assert.AreEqual("privateMockmyMockClassMock;", fields.First().ToString()); 56 | } 57 | 58 | [Test] 59 | public void CreateFields_WhenCreatingFieldsWithArrayParameter_ShoulContainFieldAsArray() 60 | { 61 | var fields = _moqGenerator.GenerateFields( 62 | typeof(MoqGeneratorTests), 63 | new List { new Parameter("myArray", typeof(int[])) }); 64 | Assert.AreEqual("privateint[]myArray;", fields.First().ToString()); 65 | } 66 | 67 | [Test] 68 | public void CreateFields_WhenCreatingFieldsWithIListParameter_ShoulContainFieldAsIList() 69 | { 70 | var fields = _moqGenerator.GenerateFields( 71 | typeof(MoqGeneratorTests), 72 | new List { new Parameter("myList", typeof(IList)) }); 73 | Assert.AreEqual("privateIListmyList;", fields.First().ToString()); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Testura.Code.UnitTestGenerator.Tests/Generators/UnitTestGenerators/NUnitGeneratorsTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.CodeAnalysis; 3 | using Microsoft.CodeAnalysis.CSharp.Syntax; 4 | using Moq; 5 | using NUnit.Framework; 6 | using Testura.Code.UnitTestGenerator.Generators.MockGenerators; 7 | using Testura.Code.UnitTestGenerator.Generators.UnitTestClassGenerators; 8 | using Testura.Code.UnitTestGenerator.Tests.Helpers; 9 | 10 | namespace Testura.Code.UnitTestGenerator.Tests.Generators.UnitTestGenerators 11 | { 12 | [TestFixture] 13 | public class NUnitGeneratorsTests 14 | { 15 | private Mock _mockGeneratorMock; 16 | private NunitTestClassGenerator _nunitTestClassGenerator; 17 | 18 | [SetUp] 19 | public void SetUp() 20 | { 21 | _mockGeneratorMock = new Mock(); 22 | _nunitTestClassGenerator = new NunitTestClassGenerator(_mockGeneratorMock.Object); 23 | } 24 | 25 | [Test] 26 | public void GenerateUnitTests_WhenGenerateUnitTest_ShouldContainSetUp() 27 | { 28 | _mockGeneratorMock.Setup(m => m.GenerateFields(typeof(NUnitGeneratorsTests), It.IsAny>())) 29 | .Returns(new List()); 30 | _mockGeneratorMock.Setup(m => m.GenerateSetUpStatements(typeof(NUnitGeneratorsTests), It.IsAny>())) 31 | .Returns(new List()); 32 | var generatedCode = _nunitTestClassGenerator.GenerateUnitTestClass(typeof(NUnitGeneratorsTests)); 33 | Assert.IsTrue(generatedCode.ToString().Contains("[SetUp]")); 34 | } 35 | 36 | [Test] 37 | public void GenerateUnitTests_WhenGenerateUnitTest_ShouldContainTestFixture() 38 | { 39 | _mockGeneratorMock.Setup(m => m.GenerateFields(typeof(NUnitGeneratorsTests), It.IsAny>())) 40 | .Returns(new List()); 41 | _mockGeneratorMock.Setup(m => m.GenerateSetUpStatements(typeof(NUnitGeneratorsTests), It.IsAny>())) 42 | .Returns(new List()); 43 | var generatedCode = _nunitTestClassGenerator.GenerateUnitTestClass(typeof(NUnitGeneratorsTests)); 44 | Assert.IsTrue(generatedCode.ToString().Contains("[TestFixture]")); 45 | } 46 | 47 | [Test] 48 | public void GenerateUnitTests_WhenGenerateUnitTest_ShouldContainCorrectNamespace() 49 | { 50 | _mockGeneratorMock.Setup(m => m.GenerateFields(typeof(NUnitGeneratorsTests), It.IsAny>())) 51 | .Returns(new List()); 52 | _mockGeneratorMock.Setup(m => m.GenerateSetUpStatements(typeof(NUnitGeneratorsTests), It.IsAny>())) 53 | .Returns(new List()); 54 | var generatedCode = _nunitTestClassGenerator.GenerateUnitTestClass(typeof(NUnitGeneratorsTests)); 55 | 56 | var o = generatedCode.NormalizeWhitespace().ToString(); 57 | Assert.IsTrue(generatedCode.ToString().Contains("Testura.Code.UnitTestGenerator.Tests.Generators.UnitTestGenerators")); 58 | } 59 | 60 | [Test] 61 | public void GenerateUnitTests_WhenGenerateUnitTestWithGenericClass_ShouldHaveCorrectName() 62 | { 63 | _mockGeneratorMock.Setup(m => m.GenerateFields(typeof(MyClassWithGeneric), It.IsAny>())) 64 | .Returns(new List()); 65 | _mockGeneratorMock.Setup(m => m.GenerateSetUpStatements(typeof(MyClassWithGeneric), It.IsAny>())) 66 | .Returns(new List()); 67 | var generatedCode = _nunitTestClassGenerator.GenerateUnitTestClass(typeof(MyClassWithGeneric)); 68 | 69 | var o = generatedCode.NormalizeWhitespace().ToString(); 70 | Assert.IsTrue(generatedCode.ToString().Contains("publicclassMyClassWithGenericTests")); 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /src/Testura.Code.UnitTestGenerator.Tests/Helpers/MyAbstractClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Testura.Code.UnitTestGenerator.Tests.Helpers 8 | { 9 | public abstract class MyAbstractClass 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Testura.Code.UnitTestGenerator.Tests/Helpers/MyClassWithGeneric.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Testura.Code.UnitTestGenerator.Tests.Helpers 8 | { 9 | public class MyClassWithGeneric 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Testura.Code.UnitTestGenerator.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Testura.Code.UnitTests.Tests")] 6 | [assembly: AssemblyDescription("")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany("")] 9 | [assembly: AssemblyProduct("Testura.Code.UnitTests.Tests")] 10 | [assembly: AssemblyCopyright("Copyright © 2017")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: Guid("2018b986-c520-465b-a0e7-b66c190ba1ec")] 17 | 18 | // [assembly: AssemblyVersion("1.0.*")] 19 | [assembly: AssemblyVersion("1.0.0.0")] 20 | [assembly: AssemblyFileVersion("1.0.0.0")] 21 | -------------------------------------------------------------------------------- /src/Testura.Code.UnitTestGenerator.Tests/Testura.Code.UnitTestGenerator.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {2018B986-C520-465B-A0E7-B66C190BA1EC} 8 | Library 9 | Properties 10 | Testura.Code.UnitTestGenerator.Tests 11 | Testura.Code.UnitTestGenerator.Tests 12 | v4.5.2 13 | 512 14 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 15.0 16 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 17 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 18 | False 19 | UnitTest 20 | 21 | 22 | 23 | 24 | true 25 | full 26 | false 27 | bin\Debug\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | 32 | 33 | pdbonly 34 | true 35 | bin\Release\ 36 | TRACE 37 | prompt 38 | 4 39 | 40 | 41 | 42 | ..\..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll 43 | 44 | 45 | ..\..\packages\Microsoft.CodeAnalysis.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.dll 46 | 47 | 48 | ..\..\packages\Microsoft.CodeAnalysis.CSharp.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll 49 | 50 | 51 | ..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll 52 | 53 | 54 | ..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll 55 | 56 | 57 | ..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll 58 | 59 | 60 | ..\..\packages\MSTest.TestFramework.1.0.8-rc2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll 61 | 62 | 63 | ..\..\packages\MSTest.TestFramework.1.0.8-rc2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll 64 | 65 | 66 | ..\..\packages\Moq.4.5.30\lib\net45\Moq.dll 67 | 68 | 69 | ..\..\packages\NUnit.3.6.0\lib\net45\nunit.framework.dll 70 | 71 | 72 | 73 | ..\..\packages\System.Collections.Immutable.1.1.37\lib\dotnet\System.Collections.Immutable.dll 74 | 75 | 76 | ..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll 77 | 78 | 79 | ..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll 80 | 81 | 82 | ..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll 83 | 84 | 85 | ..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll 86 | 87 | 88 | ..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll 89 | 90 | 91 | 92 | ..\..\packages\System.Reflection.Metadata.1.2.0\lib\portable-net45+win8\System.Reflection.Metadata.dll 93 | 94 | 95 | ..\..\packages\Testura.Code.0.5.1\lib\net452\Testura.Code.dll 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | Designer 108 | 109 | 110 | 111 | 112 | {441975f9-7600-4280-9614-17f2843b1695} 113 | Testura.Code.UnitTestGenerator 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /src/Testura.Code.UnitTestGenerator.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/Testura.Code.UnitTestGenerator.UI/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Testura.Code.UnitTestGenerator.UI/App.xaml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 16 18 | 10 19 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/Testura.Code.UnitTestGenerator.UI/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace Testura.Code.UnitTestGenerator.UI 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Testura.Code.UnitTestGenerator.UI/Dialogs/InfoDialog.xaml: -------------------------------------------------------------------------------- 1 |  15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |