Skip to content

Commit 12dc82f

Browse files
committed
Added more tests and smaller cleanup
1 parent 4c4678e commit 12dc82f

File tree

5 files changed

+81
-8
lines changed

5 files changed

+81
-8
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Bunit;
4+
using FluentAssertions;
5+
using LinkDotNet.Blog.TestUtilities;
6+
using LinkDotNet.Blog.Web;
7+
using LinkDotNet.Blog.Web.Shared;
8+
using LinkDotNet.Domain;
9+
using LinkDotNet.Infrastructure.Persistence;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Moq;
12+
using Xunit;
13+
14+
namespace LinkDotNet.Blog.IntegrationTests.Web.Shared
15+
{
16+
public class ProfileTests : TestContext
17+
{
18+
[Fact]
19+
public void ShouldRenderAllItemsSortedByCreated()
20+
{
21+
var entry1 = new ProfileInformationEntryBuilder().WithKey("key 1").WithCreatedDate(new DateTime(1)).Build();
22+
var entry2 = new ProfileInformationEntryBuilder().WithKey("key 2").WithCreatedDate(new DateTime(2)).Build();
23+
var repoMock = RegisterServices();
24+
repoMock.Setup(r => r.GetAllAsync())
25+
.ReturnsAsync(new List<ProfileInformationEntry> { entry1, entry2 });
26+
var cut = RenderComponent<Profile>();
27+
28+
var items = cut.FindAll(".profile-keypoints li");
29+
30+
items.Should().HaveCount(2);
31+
items[0].TextContent.Should().Contain("key 1");
32+
items[1].TextContent.Should().Contain("key 2");
33+
}
34+
35+
[Fact]
36+
public void ShouldNotShowAdminActions()
37+
{
38+
RegisterServices();
39+
RenderComponent<Profile>().FindComponents<AddProfileShortItem>().Should().HaveCount(0);
40+
}
41+
42+
[Fact]
43+
public void ShouldShowAdminActionsWhenLoggedIn()
44+
{
45+
RegisterServices();
46+
RenderComponent<Profile>(p => p.Add(s => s.IsAuthenticated, true))
47+
.FindComponents<AddProfileShortItem>().Should().HaveCount(1);
48+
}
49+
50+
private static AppConfiguration CreateEmptyConfiguration()
51+
{
52+
return new()
53+
{
54+
ProfileInformation = new ProfileInformation(),
55+
};
56+
}
57+
58+
private Mock<IProfileRepository> RegisterServices()
59+
{
60+
var repoMock = new Mock<IProfileRepository>();
61+
Services.AddScoped(_ => CreateEmptyConfiguration());
62+
Services.AddScoped(_ => repoMock.Object);
63+
repoMock.Setup(r => r.GetAllAsync()).ReturnsAsync(new List<ProfileInformationEntry>());
64+
return repoMock;
65+
}
66+
}
67+
}

LinkDotNet.Blog.TestUtilities/ProfileInformationEntryBuilder.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using LinkDotNet.Domain;
1+
using System;
2+
using LinkDotNet.Domain;
23

34
namespace LinkDotNet.Blog.TestUtilities
45
{
56
public class ProfileInformationEntryBuilder
67
{
78
private string key = "Key";
89
private string value = "Value";
10+
private DateTime? createdDate;
911

1012
public ProfileInformationEntryBuilder WithKey(string key)
1113
{
@@ -19,9 +21,15 @@ public ProfileInformationEntryBuilder WithValue(string value)
1921
return this;
2022
}
2123

24+
public ProfileInformationEntryBuilder WithCreatedDate(DateTime createdDate)
25+
{
26+
this.createdDate = createdDate;
27+
return this;
28+
}
29+
2230
public ProfileInformationEntry Build()
2331
{
24-
return ProfileInformationEntry.Create(key, value);
32+
return ProfileInformationEntry.Create(key, value, createdDate);
2533
}
2634
}
2735
}

LinkDotNet.Blog.Web/Pages/AboutMe.razor

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@using Microsoft.AspNetCore.Http
33
@inject AppConfiguration appConfiguration
44
@inject IHttpContextAccessor httpContextAccessor
5-
/* TODO: Meta Tags About Me - [Name here] */
5+
@* TODO: Meta Tags About Me - [Name here] *@
66

77
@if (appConfiguration.IsAboutMeEnabled)
88
{
@@ -14,7 +14,6 @@
1414
</div>
1515
<div class="col-lg-9 col-md-8 tab-container">
1616
<div class="row">
17-
<em>Stuff</em>
1817
</div>
1918
</div>
2019
</div>

LinkDotNet.Blog.Web/Shared/Profile.razor.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
display: inline-block;
33
box-shadow: 0 3px 7px -1px rgba(0, 0, 0, 0.1);
44
width: 100%;
5-
/* TODO: BETTER COLOR */
65
background: var(--background-gradient-start);
76
}
87

@@ -69,7 +68,7 @@
6968
height: 8px;
7069
}
7170

72-
/* As the Markupcomponent is a base class we have to use deep */
71+
/* As the MarkupComponent is a base class we have to use deep */
7372
::deep .profile-keypoints li p {
7473
display: inline;
7574
}

LinkDotNet.Domain/ProfileInformationEntry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private ProfileInformationEntry()
1616

1717
public DateTime CreatedDate { get; private set; }
1818

19-
public static ProfileInformationEntry Create(string key, string value)
19+
public static ProfileInformationEntry Create(string key, string value, DateTime? createdDate = null)
2020
{
2121
if (string.IsNullOrWhiteSpace(key))
2222
{
@@ -32,7 +32,7 @@ public static ProfileInformationEntry Create(string key, string value)
3232
{
3333
Key = key.Trim(),
3434
Value = value.Trim(),
35-
CreatedDate = DateTime.Now,
35+
CreatedDate = createdDate ?? DateTime.Now,
3636
};
3737
}
3838
}

0 commit comments

Comments
 (0)