Exemplo n.º 1
0
        public async Task DebugConsoleOnReceivedTests(bool connect)
        {
            // Setup
            var env = new Mock<IEnvironment>();
            var tracer = new Mock<ITracer>();
            var settings = new Mock<IDeploymentSettingsManager>();
            var process = new Mock<IProcess>();
            var connectionId = Guid.NewGuid().ToString();
            var data = Guid.NewGuid().ToString() + "\n";
            var mem = new MemoryStream();

            using (var controller = new PersistentCommandTest(env.Object, settings.Object, tracer.Object, process.Object))
            {
                // Setup
                process.SetupGet(p => p.StandardInput)
                       .Returns(new StreamWriter(mem));

                // Test
                if (connect)
                {
                    await controller.Connect(Mock.Of<IRequest>(), connectionId);
                }

                await controller.Receive(Mock.Of<IRequest>(), connectionId, data);

                // Assert
                Assert.Equal(1, PersistentCommandTest.ProcessCount);

                if (connect)
                {
                    Assert.True(mem.Position > 0, "must write data");

                    mem.Position = 0;
                    var result = new StreamReader(mem).ReadToEnd();
                    Assert.True(result.EndsWith("\n"));
                    Assert.Equal(data, result);
                }
                else
                {
                    Assert.True(mem.Position == 0, "must skip data");
                }
            }
        }
        public void WhiteSpaceShouldBeIncludedWhenRequired()
        {
            var mockSender = A.Fake<IMailSender>();
            var attribute = new SmtpMailAttributes();
            var mailer = new TestMailerBase(attribute, mockSender);

            var email = mailer.Email("WhitespaceTrimTest", false);
            var body = new StreamReader(email.Mail.AlternateViews[0].ContentStream).ReadToEnd();

            Assert.True(body.StartsWith(Environment.NewLine));
            Assert.True(body.EndsWith(Environment.NewLine));
        }