Exemplo n.º 1
0
            public void GetsObjectFromContextDelegate()
            {
                // Given
                TestExecutionContext context      = new TestExecutionContext();
                TestDocument         document     = new TestDocument();
                GenerateJson         generateJson = new GenerateJson(ctx => _jsonObject);

                // When
                IList <IDocument> results = generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                Assert.That(results.Select(x => x.Content), Is.EquivalentTo(new[] { _jsonContent }));
            }
Exemplo n.º 2
0
            public void GetsObjectFromContextDelegate()
            {
                // Given
                TestExecutionContext context      = new TestExecutionContext();
                TestDocument         document     = new TestDocument();
                GenerateJson         generateJson = new GenerateJson(ctx => _jsonObject);

                // When
                IList <IDocument> results = generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                results.Select(x => x.Content).Single().ShouldBe(_jsonContent, StringCompareShould.IgnoreLineEndings);
            }
Exemplo n.º 3
0
            public void GetsObjectFromContextDelegate()
            {
                // Given
                IExecutionContext context      = Substitute.For <IExecutionContext>();
                IDocument         document     = Substitute.For <IDocument>();
                GenerateJson      generateJson = new GenerateJson(ctx => JsonObject);

                // When
                generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                context.Received(1).GetDocument(Arg.Any <IDocument>(), Arg.Any <string>());
                context.Received().GetDocument(document, Arg.Is(JsonContent));
            }
Exemplo n.º 4
0
        public void GetsObjectFromMetadata()
        {
            // Given
            IDocument document = Substitute.For<IDocument>();
            document.Get("JsonObject").Returns(JsonObject);
            GenerateJson generateJson = new GenerateJson("JsonObject");

            // When
            generateJson.Execute(new[] { document }, null).ToList();  // Make sure to materialize the result list

            // Then
            document.Received(1).Clone(Arg.Any<string>());
            document.Received().Clone(Arg.Is(JsonContent));
        }
Exemplo n.º 5
0
            public void GetsObjectFromContextDelegate()
            {
                // Given
                IExecutionContext context = Substitute.For<IExecutionContext>();
                IDocument document = Substitute.For<IDocument>();
                GenerateJson generateJson = new GenerateJson(ctx => JsonObject);

                // When
                generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                context.Received(1).GetDocument(Arg.Any<IDocument>(), Arg.Any<string>());
                context.Received().GetDocument(document, Arg.Is(JsonContent));
            }
Exemplo n.º 6
0
            public void GeneratesCamelCasePropertyNames()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "JsonObject", _jsonObject }
                });
                GenerateJson generateJson = new GenerateJson("JsonObject").WithCamelCase();

                // When
                IList <IDocument> results = generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                Assert.That(results.Select(x => x.Content), Is.EquivalentTo(new[] { _camelCaseJsonContent }));
            }
Exemplo n.º 7
0
            public void DoesNotIndent()
            {
                // Given
                IExecutionContext context = Substitute.For<IExecutionContext>();
                IDocument document = Substitute.For<IDocument>();
                document.Get("JsonObject").Returns(JsonObject);
                GenerateJson generateJson = new GenerateJson("JsonObject").WithIndenting(false);
                string nonIndentedJsonContent = JsonContent.Replace(" ", "").Replace("\r\n", "");

                // When
                generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                context.Received(1).GetDocument(Arg.Any<IDocument>(), Arg.Any<string>());
                context.Received().GetDocument(document, Arg.Is(nonIndentedJsonContent));
            }
Exemplo n.º 8
0
            public void GeneratesCamelCasePropertyNames()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "JsonObject", _jsonObject }
                });
                GenerateJson generateJson = new GenerateJson("JsonObject").WithCamelCase();

                // When
                IList <IDocument> results = generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                results.Select(x => x.Content).Single().ToString().ShouldBe(_camelCaseJsonContent, StringCompareShould.IgnoreLineEndings);
            }
Exemplo n.º 9
0
            public void DoesNotIndent()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "JsonObject", _jsonObject }
                });
                GenerateJson generateJson           = new GenerateJson("JsonObject").WithIndenting(false);
                string       nonIndentedJsonContent = _jsonContent.Replace(" ", string.Empty).Replace("\r\n", string.Empty);

                // When
                IList <IDocument> results = generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                Assert.That(results.Select(x => x.Content), Is.EquivalentTo(new[] { nonIndentedJsonContent }));
            }
Exemplo n.º 10
0
            public void DoesNotIndent()
            {
                // Given
                IExecutionContext context  = Substitute.For <IExecutionContext>();
                IDocument         document = Substitute.For <IDocument>();

                document.Get("JsonObject").Returns(JsonObject);
                GenerateJson generateJson           = new GenerateJson("JsonObject").WithIndenting(false);
                string       nonIndentedJsonContent = JsonContent.Replace(" ", "").Replace("\r\n", "");

                // When
                generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                context.Received(1).GetDocument(Arg.Any <IDocument>(), Arg.Any <string>());
                context.Received().GetDocument(document, Arg.Is(nonIndentedJsonContent));
            }
Exemplo n.º 11
0
            public void SetsMetadataKey()
            {
                // Given
                IExecutionContext context  = Substitute.For <IExecutionContext>();
                IDocument         document = Substitute.For <IDocument>();

                document.Get("JsonObject").Returns(JsonObject);
                GenerateJson generateJson = new GenerateJson("JsonObject", "OutputKey");

                // When
                generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                context.Received(1).GetDocument(Arg.Any <IDocument>(), Arg.Any <IEnumerable <KeyValuePair <string, object> > >());
                context.Received().GetDocument(document, Arg.Is <IEnumerable <KeyValuePair <string, object> > >(
                                                   x => x.First().Key == "OutputKey" && (string)x.First().Value == JsonContent));
            }
Exemplo n.º 12
0
            public void SetsMetadataKey()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "JsonObject", _jsonObject }
                });
                GenerateJson generateJson = new GenerateJson("JsonObject", "OutputKey");

                // When
                IList <IDocument> results = generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                results.Select(x => x.First(y => y.Key == "OutputKey").Value).Single().ToString()
                .ShouldBe(_jsonContent, StringCompareShould.IgnoreLineEndings);
            }
Exemplo n.º 13
0
            public void DoesNotIndent()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "JsonObject", _jsonObject }
                });
                GenerateJson generateJson           = new GenerateJson("JsonObject").WithIndenting(false);
                string       nonIndentedJsonContent = _jsonContent.Replace(" ", string.Empty).Replace("\r\n", string.Empty);

                // When
                IList <IDocument> results = generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                results.Select(x => x.Content).Single().ToString().ShouldBe(nonIndentedJsonContent, StringCompareShould.IgnoreLineEndings);
            }
Exemplo n.º 14
0
            public void SetsMetadataKey()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "JsonObject", _jsonObject }
                });
                GenerateJson generateJson = new GenerateJson("JsonObject", "OutputKey");

                // When
                IList <IDocument> results = generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                Assert.That(
                    results.Select(x => x.First(y => y.Key == "OutputKey")),
                    Is.EquivalentTo(new[] { new KeyValuePair <string, object>("OutputKey", _jsonContent) }));
            }
Exemplo n.º 15
0
            public void SerializesMetadataObjectWithCamelCase()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "Foo", "fuz" },
                    { "Bar", "baz" }
                });
                GenerateJson generateJson = new GenerateJson((doc, ctx) => doc.GetMetadata("Bar")).WithCamelCase();

                // When
                IList <IDocument> results = generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                Assert.That(results.Select(x => x.Content), Is.EquivalentTo(new[] { @"{
  ""bar"": ""baz""
}" }));
            }
Exemplo n.º 16
0
            public void SerializesMetadataObjectWithCamelCase()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "Foo", "fuz" },
                    { "Bar", "baz" }
                });
                GenerateJson generateJson = new GenerateJson((doc, ctx) => doc.GetMetadata("Bar")).WithCamelCase();

                // When
                IList <IDocument> results = generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                results.Select(x => x.Content).Single().ShouldBe(
                    @"{
  ""bar"": ""baz""
}",
                    StringCompareShould.IgnoreLineEndings);
            }
Exemplo n.º 17
0
            public void SetsMetadataKey()
            {
                // Given
                IExecutionContext context = Substitute.For<IExecutionContext>();
                IDocument document = Substitute.For<IDocument>();
                document.Get("JsonObject").Returns(JsonObject);
                GenerateJson generateJson = new GenerateJson("JsonObject", "OutputKey");

                // When
                generateJson.Execute(new[] { document }, context).ToList();  // Make sure to materialize the result list

                // Then
                context.Received(1).GetDocument(Arg.Any<IDocument>(), Arg.Any<IEnumerable<KeyValuePair<string, object>>>());
                context.Received().GetDocument(document, Arg.Is<IEnumerable<KeyValuePair<string, object>>>(
                    x => x.First().Key == "OutputKey" && (string)x.First().Value == JsonContent));
            }
Exemplo n.º 18
0
        public void SetsMetadataKey()
        {
            // Given
            IDocument document = Substitute.For<IDocument>();
            document.Get("JsonObject").Returns(JsonObject);
            GenerateJson generateJson = new GenerateJson("JsonObject", "OutputKey");

            // When
            generateJson.Execute(new[] { document }, null).ToList();  // Make sure to materialize the result list

            // Then
            document.Received(1).Clone(Arg.Any<MetadataItems>());
            document.Received().Clone(Arg.Is<MetadataItems>(
                x => x.First().Key == "OutputKey" && (string)x.First().Value == JsonContent));
        }