string[] SplitCommandStatement(string code) { int i = 0; bool d = false; code = code.TrimStart(Spaces); for (; i < code.Length; i++) { if (code[i] == Multicast) break; else if (IsSpace(code[i])) d = true; else if (d) { i--; break; } } int n = i + 1; var parts = new[] { code.Substring(0, i).TrimEnd(Spaces), n >= code.Length ? string.Empty : code.Substring(n).TrimStart(Spaces) }; return parts; }
public void CallsMemberGenerators() { var spies = new[] { new SpyGenerator(), new SpyGenerator() }; var memberGenerators = spies.Cast<CodeGeneratorBase>().ToArray(); Generator = new ClassGenerator(Configuration, new EntityDescriptionGenerator(Configuration), memberGenerators); Generate(); Assert.That(spies.All(s => s.Called)); }
public void WordCounter_IgnoresCase() { string[] inputData = new[] { "one", "two", "three", "One" }; IWordCounter counter = new WordCounter(); var result = counter.Count(inputData); Assert.AreEqual(3, result.Keys.Count); Assert.AreEqual(2, result["one"]); Assert.AreEqual(1, result["two"]); Assert.AreEqual(1, result["three"]); }
public void Generate_CallsPropertyGeneratorsForAllProperties() { var spies = new[] {new SpyGenerator(), new SpyGenerator()}; var memberGenerators = spies.Cast<CodeGeneratorBase>().ToArray(); var generator = new PropertiesGenerator(null, memberGenerators); generator.Generate(type, contentType); Assert.That(spies.All(spy => spy.Called)); Assert.That( spies.All(spy => spy.CodeObjects.SequenceEqual( type.Members.OfType<CodeMemberProperty>() ) ) ); }
protected virtual void AddAssemblyReferences(CodeCompileUnit codeCompileUnit) { IEnumerable<string> referencedAssemblies = new[] { // .NET Framework Assemblies (by name) "System.dll", "System.Core.dll", "System.Net.dll", "System.Web.dll", "Microsoft.CSharp.dll", // For dynamic stuff } // "Third party" assemblies (by location) .Union(new[] { Assembly.ReflectionOnlyLoad("System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"), Assembly.ReflectionOnlyLoad("System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"), }.Select(x => x.Location)); codeCompileUnit.ReferencedAssemblies.AddRange(referencedAssemblies.ToArray()); }
public void SetTestMethodCategories(TechTalk.SpecFlow.Generator.TestClassGenerationContext generationContext, System.CodeDom.CodeMemberMethod testMethod, IEnumerable<string> scenarioCategories) { this.codeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, scenarioCategories.Where(cat => !cat.StartsWith("Browser:"))); var sauceLabConfigTag = scenarioCategories.SingleOrDefault(x => x == "SauceLabConfig"); if (sauceLabConfigTag != null) { this.sauceLabSettings = (SauceLabSettingsSection)ConfigurationManager.GetSection("sauceLabSettings"); this.sauce = true; } if (this.sauce) { var settings = this.sauceLabSettings; foreach (var config in settings.ConfigurationElementCollection) { var sauceLabConfig = (SauceLabTestConfigurationElement) config; testMethod.UserData.Add("Browser:" + sauceLabConfig.Browser, sauceLabConfig.Browser); var testName = string.Format("{0} on {1} version {2} on {3}", testMethod.Name, sauceLabConfig.Browser, sauceLabConfig.Version, sauceLabConfig.Platform); var withBrowserArgs = new[] { new CodeAttributeArgument(new CodePrimitiveExpression(sauceLabConfig.Browser)), new CodeAttributeArgument(new CodePrimitiveExpression(sauceLabConfig.Version)), new CodeAttributeArgument(new CodePrimitiveExpression(sauceLabConfig.Platform)), new CodeAttributeArgument(new CodePrimitiveExpression(settings.Credentials.Url)), new CodeAttributeArgument(new CodePrimitiveExpression(testName)) } .Concat(new[] { new CodeAttributeArgument("Category", new CodePrimitiveExpression(sauceLabConfig.Browser)), new CodeAttributeArgument("TestName", new CodePrimitiveExpression(testName)) }) .ToArray(); this.codeDomHelper.AddAttribute(testMethod, ROW_ATTR, withBrowserArgs); } if (!scenarioSetupMethodsAdded) { generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" if(this.driver != null)")); generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Add(\"Driver\", this.driver);")); generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" if(this.container != null)")); generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Add(\"Container\", this.container);")); scenarioSetupMethodsAdded = true; } testMethod.Statements.Insert(0, new CodeSnippetStatement(" InitializeSeleniumSauce(browser, version, platform, name, url);")); testMethod.Parameters.Insert(0, new System.CodeDom.CodeParameterDeclarationExpression("System.string", "browser")); testMethod.Parameters.Insert(1, new System.CodeDom.CodeParameterDeclarationExpression("System.string", "version")); testMethod.Parameters.Insert(2, new System.CodeDom.CodeParameterDeclarationExpression("System.string", "platform")); testMethod.Parameters.Insert(3, new System.CodeDom.CodeParameterDeclarationExpression("System.string", "url")); testMethod.Parameters.Insert(4, new System.CodeDom.CodeParameterDeclarationExpression("System.string", "testName")); return; } bool hasBrowser = false; foreach(var browser in scenarioCategories.Where(cat => cat.StartsWith("Browser:")).Select(cat => cat.Replace("Browser:", ""))) { testMethod.UserData.Add("Browser:" + browser, browser); var withBrowserArgs = new[] { new CodeAttributeArgument(new CodePrimitiveExpression(browser)) } .Concat(new[] { new CodeAttributeArgument("Category", new CodePrimitiveExpression(browser)), new CodeAttributeArgument("TestName", new CodePrimitiveExpression(string.Format("{0} on {1}", testMethod.Name, browser))) }) .ToArray(); this.codeDomHelper.AddAttribute(testMethod, ROW_ATTR, withBrowserArgs); hasBrowser = true; } if (hasBrowser) { if (!scenarioSetupMethodsAdded) { generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" if(this.driver != null)")); generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Add(\"Driver\", this.driver);")); generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" if(this.container != null)")); generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Add(\"Container\", this.container);")); scenarioSetupMethodsAdded = true; } testMethod.Statements.Insert(0, new CodeSnippetStatement(" InitializeSelenium(browser);")); testMethod.Parameters.Insert(0, new System.CodeDom.CodeParameterDeclarationExpression("System.string" , "browser")); } }
public void SetRow(TechTalk.SpecFlow.Generator.TestClassGenerationContext generationContext, System.CodeDom.CodeMemberMethod testMethod, IEnumerable<string> arguments, IEnumerable<string> tags, bool isIgnored) { var args = arguments.Select( arg => new CodeAttributeArgument(new CodePrimitiveExpression(arg))).ToList(); // addressing ReSharper bug: TestCase attribute with empty string[] param causes inconclusive result - https://github.com/techtalk/SpecFlow/issues/116 var exampleTagExpressionList = tags.Select(t => new CodePrimitiveExpression(t)).ToArray(); CodeExpression exampleTagsExpression = exampleTagExpressionList.Length == 0 ? (CodeExpression)new CodePrimitiveExpression(null) : new CodeArrayCreateExpression(typeof(string[]), exampleTagExpressionList); args.Add(new CodeAttributeArgument(exampleTagsExpression)); if (isIgnored) args.Add(new CodeAttributeArgument("Ignored", new CodePrimitiveExpression(true))); var browsers = testMethod.UserData.Keys.OfType<string>() .Where(key => key.StartsWith("Browser:")) .Select(key => (string) testMethod.UserData[key]).ToArray(); if (browsers.Any()) { foreach (var codeAttributeDeclaration in testMethod.CustomAttributes.Cast<CodeAttributeDeclaration>().Where(attr => attr.Name == ROW_ATTR && attr.Arguments.Count == 3).ToList()) { testMethod.CustomAttributes.Remove(codeAttributeDeclaration); } foreach (var browser in browsers) { var argsString = string.Concat(args.Take(args.Count - 1).Select(arg => string.Format("\"{0}\" ,", ((CodePrimitiveExpression)arg.Value).Value))); argsString = argsString.TrimEnd(' ', ','); var withBrowserArgs = new[] { new CodeAttributeArgument(new CodePrimitiveExpression(browser)) } .Concat(args) .Concat(new [] { new CodeAttributeArgument("Category", new CodePrimitiveExpression(browser)), new CodeAttributeArgument("TestName", new CodePrimitiveExpression(string.Format("{0} on {1} with: {2}", testMethod.Name, browser, argsString))) }) .ToArray(); this.codeDomHelper.AddAttribute(testMethod, ROW_ATTR, withBrowserArgs); } } else { this.codeDomHelper.AddAttribute(testMethod, ROW_ATTR, args.ToArray()); } }
protected virtual void AddAssemblyReferences(CodeCompileUnit codeCompileUnit) { IEnumerable<Assembly> defaultIncludes = new[] { typeof(TemplateBase).Assembly, typeof(DynamicAttribute).Assembly, typeof(INotifyPropertyChanged).Assembly, typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly, }; IEnumerable<string> referencedAssemblies = defaultIncludes.Select(x => x.Location); codeCompileUnit.ReferencedAssemblies.AddRange(referencedAssemblies.ToArray()); }
public void SearchUserStoryByTeamAfterTeamUpdateToNull() { var indexer = GetInstance<IEntityIndexer>(); const int targetTeamId = 1; const int assignableIdWithNullSquad = 5; var expectedAssignablesIds = new[] { 1, 4 }; int userStoryTypeId = QueryEntityTypeProvider.USERSTORY_TYPE_ID; var target = new AssignableDTO { ID = expectedAssignablesIds[0], Name = "zagzag", Description = "", EntityTypeID = userStoryTypeId, SquadID = targetTeamId }; indexer.AddAssignableIndex(target); indexer.AddAssignableIndex(new AssignableDTO { ID = 2, Name = "zagzag", Description = "", EntityTypeID = userStoryTypeId, SquadID = 2 }); indexer.AddAssignableIndex(new AssignableDTO { ID = 3, Name = "qqqqq", Description = "wwww", EntityTypeID = userStoryTypeId, SquadID = targetTeamId }); indexer.AddAssignableIndex(new AssignableDTO { ID = expectedAssignablesIds[1], Name = "zagzag qwerty", Description = "", EntityTypeID = userStoryTypeId, SquadID = targetTeamId }); indexer.AddAssignableIndex(new AssignableDTO { ID = assignableIdWithNullSquad, Name = "zagzag qwerty blabla", Description = "", EntityTypeID = userStoryTypeId, }); var queryRunner = GetInstance<QueryRunner>(); var result = queryRunner.Run(new QueryData { Query = "zagzag", TeamIds = new[] { targetTeamId } }); result.Total.Should(Be.EqualTo(2), "result.Total.Should(Be.EqualTo(2))"); result.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Select(s => s.ToString()).ToArray()), "result.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Select(s => s.ToString()).ToArray()))"); indexer.RemoveAssignableSquadIndex(new AssignableSquadDTO { AssignableSquadID = 1, AssignableID = target.AssignableID, SquadID = targetTeamId }); target.SquadID = null; indexer.UpdateAssignableIndex(target, new[] { AssignableField.SquadID }, isIndexing: false); var newResult = queryRunner.Run(new QueryData { Query = "zagzag", TeamIds = new[] { targetTeamId } }); newResult.Total.Should(Be.EqualTo(1), "newResult.Total.Should(Be.EqualTo(1))"); newResult.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Skip(1).Select(s => s.ToString()).ToArray()), "newResult.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Skip(1).Select(s => s.ToString()).ToArray()))"); var lastResult = queryRunner.Run(new QueryData { Query = "zagzag", TeamIds = null, IncludeNoTeam = true }); lastResult.Total.Should(Be.EqualTo(2), "lastResult.Total.Should(Be.EqualTo(2))"); lastResult.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Take(1).Concat(new[]{assignableIdWithNullSquad}).Select(s => s.ToString()).ToArray()), "lastResult.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Take(1).Concat(new[]{assignableIdWithNullSquad}).Select(s => s.ToString()).ToArray()))"); }
public void SearchUserStoryByTeam() { var indexer = GetInstance<IEntityIndexer>(); const int targetTeamId = 1; var expectedAssignablesIds = new[] { 1, 4 }; int userStoryTypeId = QueryEntityTypeProvider.USERSTORY_TYPE_ID; indexer.AddAssignableIndex(new AssignableDTO { ID = expectedAssignablesIds[0], Name = "zagzag", Description = "", EntityTypeID = userStoryTypeId, SquadID = targetTeamId }); indexer.AddAssignableIndex(new AssignableDTO { ID = 2, Name = "zagzag", Description = "", EntityTypeID = userStoryTypeId, SquadID = 2 }); indexer.AddAssignableIndex(new AssignableDTO { ID = 3, Name = "qqqqq", Description = "wwww", EntityTypeID = userStoryTypeId, SquadID = targetTeamId }); indexer.AddAssignableIndex(new AssignableDTO { ID = expectedAssignablesIds[1], Name = "zagzag qwerty", Description = "", EntityTypeID = userStoryTypeId, SquadID = targetTeamId }); indexer.AddAssignableIndex(new AssignableDTO { ID = 5, Name = "zagzag qwerty blabla", Description = "", EntityTypeID = userStoryTypeId, }); var queryRunner = GetInstance<QueryRunner>(); var result = queryRunner.Run(new QueryData { Query = "zagzag", TeamIds = new[] { targetTeamId } }); result.Total.Should(Be.EqualTo(2), "result.Total.Should(Be.EqualTo(2))"); result.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Select(s => s.ToString()).ToArray()), "result.AssignableIds.Should(Be.EquivalentTo(expectedAssignablesIds.Select(s => s.ToString()).ToArray()))"); }
public void SearchUserStoryByNameWithAtSymbolc() { var indexer = GetInstance<IEntityIndexer>(); var ids = new[] { 1, 2 }; indexer.AddGeneralIndex(new GeneralDTO { ID = ids[0], Name = "test", Description = "", EntityTypeID = 4, ParentProjectID = 1 }); indexer.AddGeneralIndex(new GeneralDTO { ID = ids[1], Name = "@test", Description = "", EntityTypeID = 4, ParentProjectID = 1 }); var queryRunner = GetInstance<QueryRunner>(); var result = queryRunner.Run(new QueryData { Query = "\"@test\"", ProjectIds = new[] { 1 } }); result.Total.Should(Be.EqualTo(2), "result.Total.Should(Be.EqualTo(2))"); result.AssignableIds.Should(Be.EquivalentTo(ids.Select(x => x.ToString()).ToArray()), "result.AssignableIds.Should(Be.EquivalentTo(ids.Select(x => x.ToString()).ToArray()))"); }
public void SearchUserStoryByProject() { var indexer = GetInstance<IEntityIndexer>(); var ids = new[] { 1, 2, 3, 4, 5 }; const int projectId = 918; indexer.AddAssignableIndex(new AssignableDTO { ID = ids[0], Name = "zag zag. xxx", Description = "bla bla bla", EntityTypeID = 4, ProjectID = 1 }); indexer.AddAssignableIndex(new AssignableDTO { ID = ids[1], Name = "zag zag. xxx", Description = "bla bla bla", EntityTypeID = 4, ProjectID = 2 }); indexer.AddAssignableIndex(new AssignableDTO { ID = ids[2], Name = "zag zag. xxx", Description = "bla bla bla", EntityTypeID = 4, ProjectID = projectId }); indexer.AddAssignableIndex(new AssignableDTO { ID = ids[3], Name = "zag zag. xxx", Description = "bla bla bla", EntityTypeID = 4, ProjectID = 4 }); indexer.AddAssignableIndex(new AssignableDTO { ID = ids[4], Name = "zag zag. xxx", Description = "bla bla bla", EntityTypeID = 4, ProjectID = 5 }); var queryRunner = GetInstance<QueryRunner>(); var result = queryRunner.Run(new QueryData { Query = "*zag.xxx", ProjectIds = new[] { projectId, 5 } }); result.Total.Should(Be.EqualTo(2), "result.Total.Should(Be.EqualTo(2))"); result.AssignableIds.Should(Be.EquivalentTo(new[] { ids[2].ToString(), ids[4].ToString() }), "result.AssignableIds.Should(Be.EquivalentTo(new[] { ids[2].ToString(), ids[4].ToString() }))"); }
public void SearchCommentByTeamAndProject() { var indexer = GetInstance<IEntityIndexer>(); const int targetProjectId = 1; const int targetSquadId = 1; var expectedAssignablesIds = new[] { 1, 3, 4 }; var expectedCommentIds = new[] { 2, 4, 8 }; int userStoryTypeId = QueryEntityTypeProvider.USERSTORY_TYPE_ID; indexer.AddAssignableIndex(new AssignableDTO { ID = expectedAssignablesIds[0], Name = "zagzag", Description = "", EntityTypeID = userStoryTypeId, ProjectID = targetProjectId }); indexer.AddCommentIndex(new CommentDTO { CommentID = expectedCommentIds[0], GeneralID = expectedAssignablesIds[0], Description = "qwerty ffff" }); indexer.AddAssignableIndex(new AssignableDTO { ID = 2, Name = "zagzag", Description = "", EntityTypeID = userStoryTypeId, ProjectID = 2 }); indexer.AddCommentIndex(new CommentDTO { CommentID = 2, GeneralID = 2, Description = "qwerty wert" }); indexer.AddAssignableIndex(new AssignableDTO { ID = expectedAssignablesIds[1], Name = "qqqqq", Description = "zagzag", EntityTypeID = userStoryTypeId, SquadID = targetSquadId }); indexer.AddCommentIndex(new CommentDTO { CommentID = expectedCommentIds[1], GeneralID = expectedAssignablesIds[1], Description = "qwerty bla bla" }); indexer.AddAssignableIndex(new AssignableDTO { ID = expectedAssignablesIds[2], Name = "zagzag qwerty", Description = "", EntityTypeID = userStoryTypeId, ProjectID = targetProjectId, SquadID = targetSquadId }); indexer.AddCommentIndex(new CommentDTO { CommentID = expectedCommentIds[2], GeneralID = expectedAssignablesIds[2], Description = " qwerty" }); var queryRunner = GetInstance<QueryRunner>(); var result = queryRunner.Run(new QueryData { Query = "qwerty", ProjectIds = new[] { targetProjectId }, TeamIds = new[] { targetSquadId }, }); result.Total.Should(Be.EqualTo(2), "result.Total.Should(Be.EqualTo(2))"); result.AssignableIds.Should(Be.EquivalentTo(new[] { expectedAssignablesIds[2] }.Select(s => s.ToString()).ToArray()), "result.AssignableIds.Should(Be.EquivalentTo(new[] { expectedAssignablesIds[2] }.Select(s => s.ToString()).ToArray()))"); result.CommentIds.Should(Be.EquivalentTo(new[] { expectedCommentIds[2] }.Select(s => s.ToString()).ToArray()), "result.CommentIds.Should(Be.EquivalentTo(new[] { expectedCommentIds[2] }.Select(s => s.ToString()).ToArray()))"); }
public void SearchUserStoryByNameWithSeveralSpacebarInQuotes3() { var indexer = GetInstance<IEntityIndexer>(); var ids = new[]{1,2}; indexer.AddGeneralIndex(new GeneralDTO { ID = ids[0], Name = "zagzag", Description = "local@time", EntityTypeID = 4, ParentProjectID = 1 }); indexer.AddGeneralIndex(new GeneralDTO { ID = ids[1], Name = "zagzag", Description = "zagzaglocal@time", EntityTypeID = 4, ParentProjectID = 1 }); var queryRunner = GetInstance<QueryRunner>(); var result = queryRunner.Run(new QueryData { Query = "local@time", ProjectIds = new[] { 1 } }); result.Total.Should(Be.EqualTo(2)); result.AssignableIds.Should(Be.EquivalentTo(ids.Select(x => x.ToString()).ToArray())); }