public void WritesOutputForEachTypeToFileWhenPatternUsed()
        {
            var generator = MockRepository.GenerateStub<IOutputGenerator>();
            var writer = MockRepository.GenerateMock<IOutputWriter>();
            var resolver = MockRepository.GenerateStub<IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces = Namespaces("One", "Two");

            Type<First>(namespaces[0]);
            Type<Second>(namespaces[1]);

            resolver.Stub(x => x.Resolve(null, null))
                .IgnoreArguments()
                .Return(new List<TemplateMatch>
                {
                    new TemplateMatch("One.First.htm", "!type.spark", new ViewData()),
                    new TemplateMatch("Two.Second.htm", "!type.spark", new ViewData())
                });

            generator.Stub(x => x.Convert(null, null, null))
                .IgnoreArguments()
                .Return("content");

            transformer.CreatePages("!type.spark", "output", namespaces);

            writer.AssertWasCalled(x => x.WriteFile("output\\One.First.htm", "content"));
            writer.AssertWasCalled(x => x.WriteFile("output\\Two.Second.htm", "content"));
        }
        public void TransformsTemplateInDirectoriesWithNamespacePattern()
        {
            var generator = MockRepository.GenerateStub<IOutputGenerator>();
            var writer = MockRepository.GenerateMock<IOutputWriter>();
            var resolver = MockRepository.GenerateStub<IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces = Namespaces("One", "Two");

            resolver.Stub(x => x.Resolve(null, null))
                .IgnoreArguments()
                .Return(new List<TemplateMatch>
                {
                    new TemplateMatch("One\\template.htm", "!namespace\\template.spark", new ViewData()),
                    new TemplateMatch("Two\\template.htm", "!namespace\\template.spark", new ViewData())
                });

            writer.Stub(x => x.Exists(null))
                .IgnoreArguments()
                .Return(false);

            generator.Stub(x => x.Convert(null, null))
                .IgnoreArguments()
                .Return("content");

            transformer.CreatePages("!namespace\\template.spark", "output", namespaces);

            writer.AssertWasCalled(x => x.CreateDirectory("output\\One"));
            writer.AssertWasCalled(x => x.WriteFile("output\\One\\template.htm", "content"));
            writer.AssertWasCalled(x => x.CreateDirectory("output\\Two"));
            writer.AssertWasCalled(x => x.WriteFile("output\\Two\\template.htm", "content"));
        }
Example #3
0
        public void GeneratesOutputForEachTypeFromTemplateWhenPatternUsed()
        {
            var generator = MockRepository.GenerateMock<IOutputGenerator>();
            var writer = MockRepository.GenerateStub<IOutputWriter>();
            var resolver = MockRepository.GenerateStub<IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces = Namespaces("One", "Two");

            Type<First>(namespaces[0]);
            Type<Second>(namespaces[1]);

            resolver.Stub(x => x.Resolve(null, null))
                .IgnoreArguments()
                .Return(new List<TemplateMatch>
                {
                    new TemplateMatch("One.First.htm", "!type.spark", new ViewData()),
                    new TemplateMatch("Two.Second.htm", "!type.spark", new ViewData())
                });

            transformer.CreatePages("!type.spark", "", namespaces);

            generator.AssertWasCalled(
                x => x.Convert(Arg.Is("!type.spark"), Arg<ViewData>.Is.Anything, Arg<string>.Is.Anything),
                x => x.Repeat.Twice());
        }
        public void GeneratesOutputFromTemplate()
        {
            var generator = MockRepository.GenerateMock<IOutputGenerator>();
            var writer = MockRepository.GenerateStub<IOutputWriter>();
            var resolver = MockRepository.GenerateStub<IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces = new Namespace[0];

            resolver.Stub(x => x.Resolve(null, null))
                .IgnoreArguments()
                .Return(new List<TemplateMatch> { new TemplateMatch("simple.htm", "simple.spark", new ViewData()) });

            transformer.CreatePages("simple.spark", "", namespaces);

            generator.AssertWasCalled(
                x => x.Convert(Arg.Is("simple.spark"), Arg<ViewData>.Is.Anything, Arg<string>.Is.Anything));
        }
        public void TransformsTemplatesInDirectories()
        {
            var generator = MockRepository.GenerateStub<IOutputGenerator>();
            var writer = MockRepository.GenerateMock<IOutputWriter>();
            var resolver = MockRepository.GenerateStub<IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces = new Namespace[0];

            resolver.Stub(x => x.Resolve(null, null))
                .IgnoreArguments()
                .Return(new List<TemplateMatch> { new TemplateMatch("directory\\test.htm", "", new ViewData()) });
            generator.Stub(x => x.Convert(null, null))
                .IgnoreArguments()
                .Return("content");

            transformer.CreatePages("directory\\test.spark", "output", namespaces);

            writer.AssertWasCalled(x => x.WriteFile("output\\directory\\test.htm", "content"));
        }
        public void GeneratesOutputForEachNamespaceFromTemplateWhenPatternUsed()
        {
            var generator = MockRepository.GenerateMock<IOutputGenerator>();
            var writer = MockRepository.GenerateStub<IOutputWriter>();
            var resolver = MockRepository.GenerateStub<IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces = Namespaces("One", "Two");

            resolver.Stub(x => x.Resolve(null, null))
                .IgnoreArguments()
                .Return(new List<TemplateMatch>
                {
                    new TemplateMatch("One.htm", "!namespace.spark", new ViewData()),
                    new TemplateMatch("Two.htm", "!namespace.spark", new ViewData())
                });

            transformer.CreatePages("!namespace.spark", "", namespaces);

            generator.AssertWasCalled(
                x => x.Convert(null, null),
                x => x.Constraints(Is.Equal("!namespace.spark"), Is.Anything())
                         .Repeat.Twice());
        }
        public void when_template_directory_set_propagate_change_to_the_output_generator()
        {
            var generator = MockRepository.GenerateStub<IOutputGenerator>();
            var writer = MockRepository.GenerateMock<IOutputWriter>();
            var resolver = MockRepository.GenerateStub<IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);

            transformer.SetTemplatePath("someTemplatePath");
            generator.AssertWasCalled(g => g.SetTemplatePath("someTemplatePath"));
        }
        public void when_template_directory_set_exclude_directory_from_output()
        {
            var generator = MockRepository.GenerateStub<IOutputGenerator>();
            var writer = MockRepository.GenerateMock<IOutputWriter>();
            var resolver = MockRepository.GenerateStub<IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces = new Namespace[0];

            resolver.Stub(x => x.Resolve(null, null))
                .IgnoreArguments()
                .Return(new List<TemplateMatch> { new TemplateMatch("someTemplatePath\\simple.htm", "someTemplatePath\\simple.spark", new ViewData()) });

            generator.Stub(x => x.Convert(null, null, null))
                .IgnoreArguments()
                .Return("content");

            transformer.SetTemplatePath("someTemplatePath");
            transformer.CreatePages("someTemplatePath\\simple.spark", "output", namespaces);

            writer.AssertWasCalled(x => x.WriteFile("output\\simple.htm", "content"));
        }