Skip to content

Commit

Permalink
Merge pull request #17 from IowaComputerGurus/feature/improvements
Browse files Browse the repository at this point in the history
Code Coverage Improvements
  • Loading branch information
mitchelsellers authored Apr 10, 2022
2 parents 00ec11c + 5d0e55c commit 7f9361f
Show file tree
Hide file tree
Showing 12 changed files with 410 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
<modal-header-dismiss></modal-header-dismiss>
</modal-header>
<modal-body>
<form-text-input asp-for="Name"></form-text-input>
<form-input asp-for="Name"></form-input>
</modal-body>
<modal-footer>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
Expand All @@ -280,7 +280,7 @@
&lt;modal-header-dismiss&gt;&lt;/modal-header-dismiss&gt;
&lt;/modal-header&gt;
&lt;modal-body&gt;
&lt;form-text-input asp-for=&quot;Name&quot;&gt;&lt;/form-text-input&gt;
&lt;form-input asp-for=&quot;Name&quot;&gt;&lt;/form-input&gt;
&lt;/modal-body&gt;
&lt;modal-footer&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-secondary&quot; data-dismiss=&quot;modal&quot;&gt;Close&lt;/button&gt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Xunit;

namespace ICG.AspNetCore.Utilities.BootstrapTagHelpers.Tests;
Expand All @@ -7,15 +8,15 @@ public class AlertTagHelperTests : AbstractTagHelperTest
{

[Fact]
public void Should_NotRender_If_Display_Is_Hidden()
public async Task Should_NotRender_If_Display_Is_Hidden()
{
//Arrange
var context = MakeTagHelperContext();
var output = MakeTagHelperOutput("");

//Act
var helper = new AlertTagHelper() { HideDisplay = true };
helper.Process(context, output);
await helper.ProcessAsync(context, output);

//Assert
Assert.True(output.Content.IsEmptyOrWhiteSpace);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ICG.AspNetCore.Utilities.BootstrapTagHelpers.Card;
using ICG.AspNetCore.Utilities.BootstrapTagHelpers.Contexts;
Expand All @@ -24,6 +25,22 @@ public async Task Should_ThrowException_WhenMissingContext()
Assert.IsType<KeyNotFoundException>(exceptionResult);
}

[Fact]
public async Task Should_ThrowException_WhenContextIsNull()
{
//Arrange
var context = MakeTagHelperContext();
context.Items.Add(typeof(CardContext), null);
var output = MakeTagHelperOutput(" ");

//Act
var helper = new CardHeaderActionsTagHelper();
var exceptionResult = await Record.ExceptionAsync(() => helper.ProcessAsync(context, output));

Assert.NotNull(exceptionResult);
Assert.IsType<ArgumentException>(exceptionResult);
}

[Fact]
public async Task Should_Render_With_ClassAdded()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ICG.AspNetCore.Utilities.BootstrapTagHelpers.Card;
using ICG.AspNetCore.Utilities.BootstrapTagHelpers.Contexts;
Expand All @@ -24,6 +25,22 @@ public async Task Should_ThrowException_WhenMissingContext()
Assert.IsType<KeyNotFoundException>(exceptionResult);
}

[Fact]
public async Task Should_ThrowException_WhenContextIsNull()
{
//Arrange
var context = MakeTagHelperContext();
context.Items.Add(typeof(CardContext), null);
var output = MakeTagHelperOutput(" ");

//Act
var helper = new CardHeaderTagHelper();
var exceptionResult = await Record.ExceptionAsync(() => helper.ProcessAsync(context, output));

Assert.NotNull(exceptionResult);
Assert.IsType<ArgumentException>(exceptionResult);
}

[Fact]
public async Task Should_Render_As_Div_WhenContextAvailable()
{
Expand Down Expand Up @@ -75,4 +92,23 @@ public async Task Should_Render_With_ClassAdded_PreservingCustomClasses()
//Assert
Assert.Equal(expectedClass, output.Attributes["class"].Value.ToString());
}

[Theory]
[InlineData("", "", "<div class=\"d-md-flex align-items-center w-100\"></div>")]
[InlineData("Testing", "", "<div class=\"d-md-flex align-items-center w-100\"><h5>Testing</h5></div>")]
[InlineData("Testing", "myCard", "<div class=\"d-md-flex align-items-center w-100\"><h5 id=\"myCardLabel\">Testing</h5></div>")]
public async Task Should_Render_WithProper_InnerHtmlContent(string title, string contextId, string expectedOutput)
{
//Arrange
var context = MakeTagHelperContext();
context.Items.Add(typeof(CardContext), new CardContext{Id = contextId});
var output = MakeTagHelperOutput(" ");

//Act
var helper = new CardHeaderTagHelper{Title = title};
await helper.ProcessAsync(context, output);

//Assert
Assert.Equal(expectedOutput, output.Content.GetContent());
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using ICG.AspNetCore.Utilities.BootstrapTagHelpers.Card;
using ICG.AspNetCore.Utilities.BootstrapTagHelpers.Contexts;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Xunit;

namespace ICG.AspNetCore.Utilities.BootstrapTagHelpers.Tests.Card;

public class CardTagHelperTests : AbstractTagHelperTest
{
[Fact]
public async Task Should_Not_Error_With_Missing_Id_Attribute()
{
//Arrange
var context = MakeTagHelperContext();
var output = MakeTagHelperOutput(" ");

//Act
var helper = new CardTagHelper();
var exception = await Record.ExceptionAsync(() => helper.ProcessAsync(context, output));

//Assert
Assert.Null(exception);
}

[Fact]
public async Task Should_Add_Context_Object_With_Provided_Id()
{
//Arrange
var context = MakeTagHelperContext();
var providedId = "testingCarg";
var existingAttributes = new TagHelperAttributeList(new List<TagHelperAttribute>
{new("id", providedId)});
var output = MakeTagHelperOutput(" ", existingAttributes);

//Act
var helper = new CardTagHelper();
await helper.ProcessAsync(context, output);

//Assert
var generatedContext = Assert.IsType<CardContext>(context.Items[typeof(CardContext)]);
Assert.Equal(providedId, generatedContext.Id);
}

[Fact]
public async Task Should_Render_As_Div()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,82 +1,130 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ICG.AspNetCore.Utilities.BootstrapTagHelpers.Contexts;
using ICG.AspNetCore.Utilities.BootstrapTagHelpers.Modal;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Xunit;

namespace ICG.AspNetCore.Utilities.BootstrapTagHelpers.Tests.Modal
namespace ICG.AspNetCore.Utilities.BootstrapTagHelpers.Tests.Modal;

public class ModalHeaderTagHelperTests : AbstractTagHelperTest
{
public class ModalHeaderTagHelperTests : AbstractTagHelperTest
[Fact]
public async Task Should_ThrowException_WhenMissingContext()
{
//Arrange
var context = MakeTagHelperContext();
var output = MakeTagHelperOutput(" ");

//Act
var helper = new ModalHeaderTagHelper();
var exceptionResult = await Record.ExceptionAsync(() => helper.ProcessAsync(context, output));

Assert.NotNull(exceptionResult);
Assert.IsType<KeyNotFoundException>(exceptionResult);
}

[Fact]
public async Task Should_ThrowException_WhenContextIsNull()
{
//Arrange
var context = MakeTagHelperContext();
context.Items.Add(typeof(ModalContext), null);
var output = MakeTagHelperOutput(" ");

//Act
var helper = new ModalHeaderTagHelper();
var exceptionResult = await Record.ExceptionAsync(() => helper.ProcessAsync(context, output));

Assert.NotNull(exceptionResult);
Assert.IsType<ArgumentException>(exceptionResult);
}

[Fact]
public async Task Should_Render_As_Div()
{
//Arrange
var context = MakeTagHelperContext();
context.Items.Add(typeof(ModalContext), new ModalContext());
var output = MakeTagHelperOutput(" ");

//Act
var helper = new ModalHeaderTagHelper();
await helper.ProcessAsync(context, output);

//Assert
Assert.Equal("div", output.TagName);
}

[Fact]
public async Task Should_Render_With_ClassAdded()
{
[Fact]
public async Task Should_ThrowException_WhenMissingContext()
{
//Arrange
var context = MakeTagHelperContext();
var output = MakeTagHelperOutput(" ");

//Act
var helper = new ModalHeaderTagHelper();
var exceptionResult = await Record.ExceptionAsync(() => helper.ProcessAsync(context, output));

Assert.NotNull(exceptionResult);
Assert.IsType<KeyNotFoundException>(exceptionResult);
}

[Fact]
public async Task Should_Render_As_Div()
{
//Arrange
var context = MakeTagHelperContext();
context.Items.Add(typeof(ModalContext), new ModalContext());
var output = MakeTagHelperOutput(" ");

//Act
var helper = new ModalHeaderTagHelper();
await helper.ProcessAsync(context, output);

//Assert
Assert.Equal("div", output.TagName);
}

[Fact]
public async Task Should_Render_With_ClassAdded()
{
//Arrange
var context = MakeTagHelperContext();
context.Items.Add(typeof(ModalContext), new ModalContext());
var output = MakeTagHelperOutput(" ");

//Act
var helper = new ModalHeaderTagHelper();
await helper.ProcessAsync(context, output);

//Assert
Assert.Equal("modal-header", output.Attributes["class"].Value);
}

[Fact]
public async Task Should_Render_With_ClassAdded_PreservingCustomClasses()
{
//Arrange
var customClass = "testing-out";
var expectedClass = $"{customClass} modal-header";
var existingAttributes = new TagHelperAttributeList(new List<TagHelperAttribute>
{new("class", customClass)});
var context = MakeTagHelperContext();
context.Items.Add(typeof(ModalContext), new ModalContext());
var output = MakeTagHelperOutput(" ", existingAttributes);

//Act
var helper = new ModalHeaderTagHelper();
await helper.ProcessAsync(context, output);

//Assert
Assert.Equal(expectedClass, output.Attributes["class"].Value.ToString());
}
//Arrange
var context = MakeTagHelperContext();
context.Items.Add(typeof(ModalContext), new ModalContext());
var output = MakeTagHelperOutput(" ");

//Act
var helper = new ModalHeaderTagHelper();
await helper.ProcessAsync(context, output);

//Assert
Assert.Equal("modal-header", output.Attributes["class"].Value);
}

[Fact]
public async Task Should_Render_With_ClassAdded_PreservingCustomClasses()
{
//Arrange
var customClass = "testing-out";
var expectedClass = $"{customClass} modal-header";
var existingAttributes = new TagHelperAttributeList(new List<TagHelperAttribute>
{new("class", customClass)});
var context = MakeTagHelperContext();
context.Items.Add(typeof(ModalContext), new ModalContext());
var output = MakeTagHelperOutput(" ", existingAttributes);

//Act
var helper = new ModalHeaderTagHelper();
await helper.ProcessAsync(context, output);

//Assert
Assert.Equal(expectedClass, output.Attributes["class"].Value.ToString());
}

[Fact]
public async Task Should_NotRender_InnerContent_When_Title_Missing()
{
//Arrange
var context = MakeTagHelperContext();
context.Items.Add(typeof(ModalContext), new ModalContext());
var output = MakeTagHelperOutput(" ");

//Act
var helper = new ModalHeaderTagHelper();
await helper.ProcessAsync(context, output);

//Assert
Assert.Equal("", output.Content.GetContent());
}

[Theory]
[InlineData("My Title", "", "<h5 class=\"modal-title\">My Title</h5>")]
[InlineData("My Title", "myModal", "<h5 class=\"modal-title\" id=\"myModalLabel\">My Title</h5>")]
public async Task Should_Render_InnerContent_Title_When_Title_Provided(string title, string id, string expectedHtml)
{
//Arrange
var context = MakeTagHelperContext();
context.Items.Add(typeof(ModalContext), new ModalContext{Id = id});
var output = MakeTagHelperOutput(" ");

//Act
var helper = new ModalHeaderTagHelper{Title = title};
await helper.ProcessAsync(context, output);

//Assert
Assert.Equal(expectedHtml, output.Content.GetContent());
}
}
}
Loading

0 comments on commit 7f9361f

Please sign in to comment.