Пример #1
0
        public void Should_allow_chaining_of_asserts_and_still_pass()
        {
            const string input = @"<html><head></head><body><div id='testId' class='myClass'>Test</div></body></html>";
            var document = new DocumentWrapper(input);

            document["#testId"].ShouldExist().And.ShouldBeOfClass("myClass");
        }
        public void Should_allow_byte_array_input()
        {
            // Given
            const string input = @"<html><head></head><body><div id='testId' class='myClass'>Test</div></body></html>";
            var buffer = Encoding.UTF8.GetBytes(input);

            // When
            var document = new DocumentWrapper(buffer);

            // Then
            Assert.NotNull(document["#testId"]);
        }
        public void Should_return_querywrapper_when_indexer_accessed()
        {
            // Given
            const string input = @"<html><head></head><body><div id='testId' class='myClass'>Test</div></body></html>";
            var buffer = Encoding.UTF8.GetBytes(input);
            var document = new DocumentWrapper(buffer);

            // When
            var result = document["#testId"];

            // Then
            Assert.IsType<QueryWrapper>(result);
        }
Пример #4
0
        public void Should_allow_chaining_of_asserts_and_fail_where_appropriate()
        {
            var result = Record.Exception(
                () =>
                    {
                        const string input =
                            @"<html><head></head><body><div id='testId' class='myOtherClass'>Test</div></body></html>";
                        var document = new DocumentWrapper(input);
                        document["#testId"].ShouldExist().And.ShouldBeOfClass("myClass");
                    });

            Assert.IsType<EqualException>(result);
        }
Пример #5
0
        public void Should_allow_chaining_of_asserts_and_still_pass()
        {
            // Given
            const string input = @"<html><head></head><body><div id='testId' class='myClass'>Test</div></body></html>";

            var buffer =
                Encoding.UTF8.GetBytes(input);

            // When
            var document = new DocumentWrapper(buffer);

            // Then
            document["#testId"].ShouldExist().And.ShouldBeOfClass("myClass");
        }
Пример #6
0
        public void Should_allow_chaining_of_asserts_and_fail_where_appropriate()
        {
            // Given
            // When
            var result = Record.Exception(
                () =>
                    {
                        const string input =
                            @"<html><head></head><body><div id='testId' class='myOtherClass'>Test</div></body></html>";

                    var buffer =
                        Encoding.UTF8.GetBytes(input);

                    var document = 
                        new DocumentWrapper(buffer);

                        document["#testId"].ShouldExist().And.ShouldBeOfClass("myClass");
                    });

            Assert.IsType<Nancy.Testing.AssertException>(result);
        }
Пример #7
0
        /// <summary>
        /// Returns the HTTP response body, of the specified <see cref="NancyContext"/>, wrapped in an <see cref="DocumentWrapper"/> instance.
        /// </summary>
        /// <param name="context">The <see cref="NancyContext"/> instance that the HTTP response body should be retrieved from.</param>
        /// <returns>A <see cref="DocumentWrapper"/> instance, wrapping the HTTP response body of the context.</returns>
        public static DocumentWrapper DocumentBody(this NancyContext context)
        {
            // We only really want to generate this once, so we'll stick it in the context
            // This isn't ideal, but we don't want to hide the guts of the context from the
            // tests this will have to do.
            if (context.Items.ContainsKey(DOCUMENT_WRAPPER_KEY_NAME))
            {
                return (DocumentWrapper)context.Items[DOCUMENT_WRAPPER_KEY_NAME];
            }

            DocumentWrapper wrapper;
            using (var contentsStream = new MemoryStream())
            {
                context.Response.Contents.Invoke(contentsStream);
                contentsStream.Position = 0;
                wrapper = new DocumentWrapper(contentsStream);
            }

            context.Items[DOCUMENT_WRAPPER_KEY_NAME] = wrapper;

            return wrapper;
        }
Пример #8
0
        /// <summary>
        /// Returns the HTTP response body, of the specified <see cref="NancyContext"/>, wrapped in an <see cref="DocumentWrapper"/> instance.
        /// </summary>
        /// <param name="context">The <see cref="NancyContext"/> instance that the HTTP response body should be retrieved from.</param>
        /// <returns>A <see cref="DocumentWrapper"/> instance, wrapping the HTTP response body of the context.</returns>
        public static DocumentWrapper DocumentBody(this NancyContext context)
        {
            // We only really want to generate this once, so we'll stick it in the context
            // This isn't ideal, but we don't want to hide the guts of the context from the
            // tests this will have to do.
            if (context.Items.ContainsKey(DOCUMENT_WRAPPER_KEY_NAME))
            {
                return((DocumentWrapper)context.Items[DOCUMENT_WRAPPER_KEY_NAME]);
            }

            DocumentWrapper wrapper;

            using (var contentsStream = new MemoryStream())
            {
                context.Response.Contents.Invoke(contentsStream);
                contentsStream.Position = 0;
                wrapper = new DocumentWrapper(contentsStream);
            }

            context.Items[DOCUMENT_WRAPPER_KEY_NAME] = wrapper;

            return(wrapper);
        }