Example #1
0
        public void Alternative_views_are_added_to_MailMessage()
        {
            var input = @"
            To: test1@test.com
            From: test2@test.com
            Subject: Test Subject
            Views: Text, Html";
            var text = @"Content-Type: text/plain

            Hello, World!";
            var html = @"Content-Type: text/html

            <p>Hello, World!</p>";

            var email = new Email("Test");
            var renderer = new Mock<IEmailViewRenderer>();
            renderer.Setup(r => r.Render(email, "Test.Text")).Returns(text);
            renderer.Setup(r => r.Render(email, "Test.Html")).Returns(html);

            var parser = new EmailParser(renderer.Object);
            using (var message = parser.Parse(input, email))
            {
                message.AlternateViews[0].ContentType.ShouldEqual(new ContentType("text/plain; charset=utf-16"));
                var textContent = new StreamReader(message.AlternateViews[0].ContentStream).ReadToEnd();
                textContent.ShouldEqual("Hello, World!");

                message.AlternateViews[1].ContentType.ShouldEqual(new ContentType("text/html; charset=utf-16"));
                var htmlContent = new StreamReader(message.AlternateViews[1].ContentStream).ReadToEnd();
                htmlContent.ShouldEqual("<p>Hello, World!</p>");
            }
        }
 public void GivenCombinedStyleSheetBundle_WhenRenderedAndMinified_ThenCssIsProperlyMinifiedAsCssAndNotJavascript()
 {
     CassetteSettings settings = new CassetteSettings("1");
     IBundleProcessor<StylesheetBundle> processor = new StylesheetPipeline();
     underTest.Processor = processor;
     inner.Processor = processor;
     underTest.Process(settings);
     // underTest.Renderer = new StylesheetHtmlRenderer(new UrlGenerator(new UrlPlaceholderWrapper(), ""));
     var cssContent = underTest.OpenStream();
     string output = new StreamReader(cssContent).ReadToEnd();
     output.ShouldEqual(".className{display:none}");
 }
        public void Should_write_string_to_stream()
        {
            var formatter = new PlainTextFormatter();

            var content = new StringContent(string.Empty);
            content.Headers.Clear();
            var memoryStream = new MemoryStream();
            var value = "Hello World";
            var resultTask = formatter.WriteToStreamAsync(typeof(string), value, memoryStream, content, transportContext: null);

            resultTask.Wait();

            memoryStream.Position = 0;
            string serializedString = new StreamReader(memoryStream).ReadToEnd();

            serializedString.ShouldEqual(value);
        }
        public void Should_be_able_to_post_body_to_selfhost()
        {
            using (CreateAndOpenWebServiceHost())
            {
                const string testBody = "This is the body of the request";

                var request =
                    WebRequest.Create(new Uri(BaseUri, "rel"));
                request.Method = "POST";

                var writer =
                    new StreamWriter(request.GetRequestStream()) {AutoFlush = true};
                writer.Write(testBody);

                var responseBody =
                    new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd();

                responseBody.ShouldEqual(testBody);
            }
        }
        public void Should_write_serialized_object_to_stream_using_date_handler()
        {
            var formatter = new ServiceStackTextFormatter(JsonDateHandler.TimestampOffset);
            var value = GetTestObject();

            var content = new StringContent(string.Empty);
            var memoryStream = new MemoryStream();

            var resultTask = formatter.WriteToStreamAsync(typeof(RootClass), value, memoryStream, content, transportContext: null);

            resultTask.Wait();

            memoryStream.Position = 0;
            string serializedString = new StreamReader(memoryStream).ReadToEnd();

            JsConfig.DateHandler = JsonDateHandler.TimestampOffset;
            var expected = value.ToJson();
            JsConfig.Reset();
            serializedString.ShouldEqual(expected);
        }
        public void Should_write_serialized_object_to_stream()
        {
            var formatter = new ServiceStackTextFormatter();
            var value = GetTestObject();

            var content = new StringContent(string.Empty);
            var memoryStream = new MemoryStream();

            var resultTask = formatter.WriteToStreamAsync(typeof(RootClass), value, memoryStream, content, transportContext: null);

            resultTask.Wait();

            memoryStream.Position = 0;
            string serializedString = new StreamReader(memoryStream).ReadToEnd();

            // Formatter uses ISO8601 dates by default
            using (var scope = JsConfig.BeginScope())
            {
                scope.DateHandler = JsonDateHandler.ISO8601;
                var expextedResult = value.ToJson();
                serializedString.ShouldEqual(expextedResult);    
            }
        }
 public void it_should_create_a_json_document_referencing_the_registered_graph_by_internal_id()
 {
     var doc = new StreamReader(actual).ReadToEnd();
     doc.ShouldEqual(@"{""Composed"":{""__StashInternalId"":""" + expectedInternalId + @"""},""AnotherComposed"":null,""AnotherProperty"":""another property""}");
 }
        public void Should_write_serialized_object_to_stream()
        {
            var formatter = new ServiceStackTextFormatter();
            var value = GetTestObject();

            var contentHeader = new StringContent(string.Empty).Headers;
            contentHeader.Clear();
            var memoryStream = new MemoryStream();

            var resultTask = formatter.WriteToStreamAsync(typeof(RootClass), value, memoryStream, contentHeader, new FormatterContext(StandardMediaTypeHeaderValues.ApplicationJson, isRead: false), transportContext: null);

            resultTask.Wait();

            memoryStream.Position = 0;
            string serializedString = new StreamReader(memoryStream).ReadToEnd();

            // Formatter uses ISO8601 dates by default
            JsConfig.DateHandler = JsonDateHandler.ISO8601;
            var expextedResult = value.ToJson();
            JsConfig.Reset();
            serializedString.ShouldEqual(expextedResult);
        }
 public void it_should_create_a_json_document()
 {
     var doc = new StreamReader(actual).ReadToEnd();
     doc.ShouldEqual(@"{""AProperty"":""test property""}");
 }