Ejemplo n.º 1
0
            public async Task IgnoresUnderscoresByDefault()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context   = GetExecutionContext(engine);
                TestDocument         document1 = GetDocument(
                    "/IgnoreUnderscores/Test.cshtml",
                    @"@{
	Layout = ""_Layout.cshtml"";
}
<p>This is a test</p>");
                TestDocument document2 = GetDocument(
                    "/IgnoreUnderscores/_Layout.cshtml",
                    @"LAYOUT4
@RenderBody()");
                RenderRazor razor = new RenderRazor();

                // When
                TestDocument result = await ExecuteAsync(new[] { document1, document2 }, context, razor).SingleAsync();

                // Then
                result.Content.ShouldBe(
                    @"LAYOUT4
<p>This is a test</p>",
                    StringCompareShould.IgnoreLineEndings);
            }
Ejemplo n.º 2
0
            public async Task RenderLayoutSection()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context  = GetExecutionContext(engine);
                TestDocument         document = GetDocument(
                    "/LayoutWithSection/Test.cshtml",
                    @"@{
	Layout = ""_Layout.cshtml"";
}
@section MySection {
<p>Section Content</p>
}
<p>This is a test</p>");
                RenderRazor razor = new RenderRazor();

                // When
                TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync();

                // Then
                result.Content.ShouldBe(
                    @"LAYOUT5

<p>Section Content</p>

<p>This is a test</p>",
                    StringCompareShould.IgnoreLineEndings);
            }
Ejemplo n.º 3
0
        public async Task <object> Register([FromBody] UserRegister userRegister)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(start => start.Errors).Select(error => error.ErrorMessage).Take(1).ElementAt(0)));
            }

            // Google Recaptcha Validation
            if (WebConfigurationManager.AppSettings["GoogleRecaptcha"] == "true")
            {
                GoogleResponse googleResponse = await _google.ValidateRecaptcha <GoogleResponse>(userRegister.Token);

                if (!googleResponse.Success)
                {
                    return(BadRequest("error.validation.invalid-recaptcha"));
                }
            }

            // HCaptcha Validation
            if (WebConfigurationManager.AppSettings["HCaptcha"] == "true")
            {
                HCaptchaResponse hCaptchaResponse = await _hCaptcha.Validate <HCaptchaResponse>(userRegister.Token);

                if (!hCaptchaResponse.Success)
                {
                    return(BadRequest("error.validation.invalid-hcaptcha"));
                }
            }

            UserRegisterResponse user = await _userService.Register(userRegister);

            if (user.ErrorEmail)
            {
                return(BadRequest("error.user.email-exists"));
            }

            if (user.ErrorCpf)
            {
                return(BadRequest("error.user.cpf-exists"));
            }

            // Register Mail
            if (WebConfigurationManager.AppSettings["Mail"] == "true")
            {
                string message = RenderRazor.RenderView("~/Views/MailTemplates/Register.cshtml", userRegister, null);
                MailService.SendMailAsync(userRegister.Email, new string[] { }, "Register", message);
            }


            return(Ok(user));
        }
Ejemplo n.º 4
0
            public async Task DocumentAsModel()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context  = GetExecutionContext(engine);
                TestDocument         document = GetDocument("/Temp/temp.txt", "<p>@Model.Source</p>");
                RenderRazor          razor    = new RenderRazor();

                // When
                TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync();

                // Then
                result.Content.ShouldBe("<p>/Temp/temp.txt</p>");
            }
Ejemplo n.º 5
0
            public async Task SimpleTemplate()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context  = GetExecutionContext(engine);
                TestDocument         document = new TestDocument("@for(int c = 0 ; c < 5 ; c++) { <p>@c</p> }");
                RenderRazor          razor    = new RenderRazor();

                // When
                TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync();

                // Then
                result.Content.ShouldBe(" <p>0</p>  <p>1</p>  <p>2</p>  <p>3</p>  <p>4</p> ");
            }
Ejemplo n.º 6
0
            public async Task Document()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context  = GetExecutionContext(engine);
                TestDocument         document = new TestDocument(new NormalizedPath("/Temp/temp.txt"), (NormalizedPath)null, "<p>@Document.Source</p>");
                RenderRazor          razor    = new RenderRazor();

                // When
                TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync();

                // Then
                result.Content.ShouldBe("<p>/Temp/temp.txt</p>");
            }
Ejemplo n.º 7
0
            public async Task AlternateModel()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context  = GetExecutionContext(engine);
                TestDocument         document = GetDocument("/Temp/temp.txt", @"@model IList<int>
<p>@Model.Count</p>");
                IList <int>          model    = new[] { 1, 2, 3 };
                RenderRazor          razor    = new RenderRazor().WithModel(Config.FromValue(model));

                // When
                TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync();

                // Then
                result.Content.ShouldBe("<p>3</p>");
            }
Ejemplo n.º 8
0
            public async Task Metadata()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context  = GetExecutionContext(engine);
                TestDocument         document = new TestDocument(@"<p>@Metadata[""MyKey""]</p>")
                {
                    { "MyKey", "MyValue" }
                };
                RenderRazor razor = new RenderRazor();

                // When
                TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync();

                // Then
                result.Content.ShouldBe("<p>MyValue</p>");
            }
Ejemplo n.º 9
0
            public async Task AlternateIgnorePrefix()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context   = GetExecutionContext(engine);
                TestDocument         document1 = GetDocument(
                    "/AlternateIgnorePrefix/Test.cshtml",
                    "<p>This is a test</p>");
                TestDocument document2 = GetDocument(
                    "/AlternateIgnorePrefix/IgnoreMe.cshtml",
                    "<p>Ignore me</p>");
                RenderRazor razor = new RenderRazor().IgnorePrefix("Ignore");

                // When
                TestDocument result = await ExecuteAsync(new[] { document1, document2 }, context, razor).SingleAsync();

                // Then
                result.Content.ShouldBe("<p>This is a test</p>");
            }
Ejemplo n.º 10
0
            public async Task AlternateRelativeViewStartPathWithRelativeLayout()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context  = GetExecutionContext(engine);
                TestDocument         document = GetDocument(
                    "/AlternateViewStartPath/Test.cshtml",
                    "<p>This is a test</p>");
                RenderRazor razor = new RenderRazor().WithViewStart((FilePath)"AlternateViewStart/_ViewStartRelativeLayout.cshtml");

                // When
                TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync();

                // Then
                result.Content.ShouldBe(
                    @"LAYOUT3
<p>This is a test</p>",
                    StringCompareShould.IgnoreLineEndings);
            }
Ejemplo n.º 11
0
            public async Task LoadViewStartAndLayoutFile()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context  = GetExecutionContext(engine);
                TestDocument         document = GetDocument(
                    "/ViewStartAndLayout/Test.cshtml",
                    "<p>This is a test</p>");
                RenderRazor razor = new RenderRazor();

                // When
                TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync();

                // Then
                result.Content.ShouldBe(
                    @"LAYOUT2
<p>This is a test</p>",
                    StringCompareShould.IgnoreLineEndings);
            }
Ejemplo n.º 12
0
            public async Task RenderModuleDefinedLayoutFile()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context  = GetExecutionContext(engine);
                TestDocument         document = GetDocument(
                    "/Layout/Test.cshtml",
                    "<p>This is a test</p>");
                RenderRazor razor = new RenderRazor().WithLayout((NormalizedPath)"_Layout.cshtml");

                // When
                TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync();

                // Then
                result.Content.ShouldBe(
                    @"LAYOUT
<p>This is a test</p>",
                    StringCompareShould.IgnoreLineEndings);
            }
Ejemplo n.º 13
0
            public async Task RenderLayoutSectionOnMultipleExecution()
            {
                // Given
                Engine engine = new Engine();
                TestExecutionContext context  = GetExecutionContext(engine);
                TestDocument         document = GetDocument(
                    "/LayoutWithSection/Test.cshtml",
                    @"@{
	Layout = ""_Layout.cshtml"";
}
@section MySection {
<p>Section Content</p>
}
<p>This is a test</p>");
                RenderRazor razor = new RenderRazor();

                // When
                IReadOnlyList <IDocument> results1 = await ExecuteAsync(document, context, razor);

                IReadOnlyList <IDocument> results2 = await ExecuteAsync(document, context, razor);

                // Then
                (await results1.Single().GetStringAsync()).ShouldBe(
                    @"LAYOUT5

<p>Section Content</p>

<p>This is a test</p>",
                    StringCompareShould.IgnoreLineEndings);

                (await results2.Single().GetStringAsync()).ShouldBe(
                    @"LAYOUT5

<p>Section Content</p>

<p>This is a test</p>",
                    StringCompareShould.IgnoreLineEndings);
            }