public string GenerateFixture(Story story, StoryContext context) { var tests = new StringBuilder(); var contextSet = new TestContextSet(); IEnumerable<string> namespaces = new string[0]; foreach (var scenario in story.Scenarios) { foreach (var s in _preprocessor.Preprocess(scenario)) { NUnitTest test = MethodGenerator.GetTestFromScenario(s, context); tests.Append(" " + test.Body); tests.AppendLine(); contextSet.AddRange(test.ContextTypes); namespaces = namespaces.Union(test.Namespaces).Distinct(); } } var usingStatements = namespaces.Select(x => string.Format("using {0};", x)); var usings = string.Join("\r\n", usingStatements.ToArray()); var writeStoryToConsole = "Console.WriteLine(@\"" + story.Summary.Replace("\"", "\"\"") + "\r\n" + " \");"; const string ns = "StorEvilSpecifications"; var categories = string.Join("", (story.Tags ?? new string[0]).Select(t => string.Format(@"[Category(""{0}"")]", t)).ToArray()); return string.Format(FixtureFormat, ns, usings, GetFixtureName(story), tests, writeStoryToConsole, categories, story.Id); }
private void AppendDisposeCalls(StringBuilder codeBuilder, TestContextSet contexts) { foreach (var context in contexts.Where(c => c.Type.GetInterfaces().Contains(typeof (IDisposable)))) { codeBuilder.AppendLine(" " + context.Name + ".Dispose();"); } }