private static IEnumerable <PortableExecutableReference> GetReferences(MockingFrameworkType mockingFrameworkType) { switch (mockingFrameworkType) { case MockingFrameworkType.NSubstitute: yield return(MetadataReference.CreateFromFile(typeof(Substitute).Assembly.Location)); break; case MockingFrameworkType.Moq: yield return(MetadataReference.CreateFromFile(typeof(Mock).Assembly.Location)); break; case MockingFrameworkType.RhinoMocks: yield return(MetadataReference.CreateFromFile(typeof(Rhino.Mocks.MockRepository).Assembly.Location)); break; case MockingFrameworkType.FakeItEasy: yield return(MetadataReference.CreateFromFile(typeof(A).Assembly.Location)); break; } }
public static void CanCallCreateForMockingFramework(MockingFrameworkType type, Type expectedType) { var options = Substitute.For <IUnitTestGeneratorOptions>(); options.GenerationOptions.TestTypeNaming.Returns("{0}Tests"); options.GenerationOptions.FrameworkType.Returns(TestFrameworkTypes.NUnit2); options.GenerationOptions.MockingFrameworkType.Returns(type); var result = FrameworkSetFactory.Create(options); Assert.That(result.MockingFramework, Is.InstanceOf(expectedType)); }
private static IMockingFramework Create(MockingFrameworkType mockingFrameworkType, IGenerationContext context) { switch (mockingFrameworkType) { case MockingFrameworkType.NSubstitute: return(new NSubstituteMockingFramework(context)); case MockingFrameworkType.Moq: return(new MoqMockingFramework(context)); case MockingFrameworkType.RhinoMocks: return(new RhinoMocksMockingFramework(context)); case MockingFrameworkType.FakeItEasy: return(new FakeItEasyMockingFramework(context)); default: throw new NotSupportedException(Strings.FrameworkSetFactory_Create_Couldn_t_find_the_required_mocking_framework); } }
public GenerationOptions(TestFrameworkTypes testFramework, MockingFrameworkType mockFramework) { FrameworkType = testFramework; MockingFrameworkType = mockFramework; }
public static void CanCallGetReferencedAssemblies(TestFrameworkTypes testFramework, MockingFrameworkType mockingFramework, string expectedTestFramework, string expectedMockingFramework) { var options = Substitute.For <IUnitTestGeneratorOptions>(); options.GenerationOptions.TestTypeNaming.Returns("{0}Tests"); options.GenerationOptions.FrameworkType.Returns(testFramework); options.GenerationOptions.MockingFrameworkType.Returns(mockingFramework); var result = StandardReferenceHelper.GetReferencedNugetPackages(options); Assert.That(result.Any(x => string.Equals(x.Name, expectedTestFramework, StringComparison.OrdinalIgnoreCase))); Assert.That(result.Any(x => string.Equals(x.Name, expectedMockingFramework, StringComparison.OrdinalIgnoreCase))); }
public SetupResult(T result, MockingFrameworkType mockingFrameworkType) { MockingFrameworkType = mockingFrameworkType; Result = result; }
public void GivenISetMyGenerationMockFrameworkTo(MockingFrameworkType mockType) { _context.MockFramework = mockType; }
public static async Task AssertTestGeneration(string resourceName, TestFrameworkTypes testFrameworkTypes, MockingFrameworkType mockingFrameworkType) { var classAsText = TestClasses.ResourceManager.GetString(resourceName, TestClasses.Culture); var tree = CSharpSyntaxTree.ParseText(classAsText, new CSharpParseOptions(LanguageVersion.Latest)); var assemblyPath = Path.GetDirectoryName(typeof(object).Assembly.Location); var references = new List <MetadataReference> { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), MetadataReference.CreateFromFile(typeof(INotifyPropertyChanged).Assembly.Location), MetadataReference.CreateFromFile(typeof(Expression).Assembly.Location), MetadataReference.CreateFromFile(typeof(Brush).Assembly.Location), MetadataReference.CreateFromFile(typeof(Stream).Assembly.Location), MetadataReference.CreateFromFile(typeof(Form).Assembly.Location), MetadataReference.CreateFromFile(typeof(SqlConnection).Assembly.Location), MetadataReference.CreateFromFile(typeof(Window).Assembly.Location), MetadataReference.CreateFromFile(typeof(UIElement).Assembly.Location), MetadataReference.CreateFromFile(typeof(DependencyObject).Assembly.Location), MetadataReference.CreateFromFile(Path.Combine(assemblyPath, "System.dll")), MetadataReference.CreateFromFile(Path.Combine(assemblyPath, "System.Core.dll")), MetadataReference.CreateFromFile(Path.Combine(assemblyPath, "System.Runtime.dll")), MetadataReference.CreateFromFile(Path.Combine(assemblyPath, "System.Threading.Tasks.dll")), }; references.AddRange(GetReferences(mockingFrameworkType)); references.AddRange(GetReferences(testFrameworkTypes)); var compilation = CSharpCompilation.Create( "MyTest", syntaxTrees: new[] { tree }, references: references); var semanticModel = compilation.GetSemanticModel(tree); IUnitTestGeneratorOptions options = Substitute.For <IUnitTestGeneratorOptions>(); options.GenerationOptions.FrameworkType.Returns(testFrameworkTypes); options.GenerationOptions.MockingFrameworkType.Returns(mockingFrameworkType); options.GenerationOptions.TestFileNaming.Returns("{0}Tests"); options.GenerationOptions.TestTypeNaming.Returns("{0}Tests"); options.GenerationOptions.TestProjectNaming.Returns("{0}.Tests"); var core = await CoreGenerator.Generate(semanticModel, null, null, false, options, x => "Tests").ConfigureAwait(true); Assert.IsNotNull(core); Console.WriteLine(core.FileContent); Assert.IsNotNull(core.FileContent); var generatedTree = CSharpSyntaxTree.ParseText(core.FileContent, new CSharpParseOptions(LanguageVersion.Latest)); var syntaxTrees = new List <SyntaxTree> { tree, generatedTree }; if (core.RequiredAssets.Any(x => x == TargetAsset.PropertyTester)) { var testerAsset = AssetFactory.Create(TargetAsset.PropertyTester); var propertyTester = testerAsset.Content("Tests", testFrameworkTypes); syntaxTrees.Add(CSharpSyntaxTree.ParseText(propertyTester, new CSharpParseOptions(LanguageVersion.Latest))); } var validateCompilation = CSharpCompilation.Create( "MyTest", syntaxTrees: syntaxTrees, references: references, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); var stream = new MemoryStream(); var result = validateCompilation.Emit(stream); var streamLength = stream.Length; stream.Dispose(); Assert.IsTrue(result.Success, string.Join(",", result.Diagnostics.Select(x => x.Location.GetLineSpan().StartLinePosition.Line + ": " + x.GetMessage()))); Assert.That(streamLength, Is.GreaterThan(0)); }
public SetupResultBase(MockingFrameworkType mockingFrameworkType) { MockingFrameworkType = mockingFrameworkType; }