Skip to content

Commit

Permalink
Migrated Domain to nullable enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Aug 31, 2024
1 parent 0a61b3a commit 26becfb
Show file tree
Hide file tree
Showing 29 changed files with 162 additions and 114 deletions.
22 changes: 9 additions & 13 deletions src/LinkDotNet.Blog.Domain/BlogPost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,29 @@ namespace LinkDotNet.Blog.Domain;

public sealed partial class BlogPost : Entity
{
private BlogPost()
{
}

public string Title { get; private set; }
public string Title { get; private set; } = default!;

public string ShortDescription { get; private set; }
public string ShortDescription { get; private set; } = default!;

public string Content { get; private set; }
public string Content { get; private set; } = default!;

public string PreviewImageUrl { get; private set; }
public string PreviewImageUrl { get; private set; } = default!;

public string PreviewImageUrlFallback { get; private set; }
public string? PreviewImageUrlFallback { get; private set; }

public DateTime UpdatedDate { get; private set; }

public DateTime? ScheduledPublishDate { get; private set; }

public IList<string> Tags { get; private set; }
public IList<string> Tags { get; private set; } = [];

public bool IsPublished { get; private set; }

public int Likes { get; set; }

public bool IsScheduled => ScheduledPublishDate is not null;

public string TagsAsString => string.Join(",", Tags ?? []);
public string TagsAsString => string.Join(",", Tags);

public int ReadingTimeInMinutes { get; private set; }

Expand Down Expand Up @@ -95,8 +91,8 @@ public static BlogPost Create(
bool isPublished,
DateTime? updatedDate = null,
DateTime? scheduledPublishDate = null,
IEnumerable<string> tags = null,
string previewImageUrlFallback = null)
IEnumerable<string>? tags = null,
string? previewImageUrlFallback = null)
{
if (scheduledPublishDate is not null && isPublished)
{
Expand Down
2 changes: 1 addition & 1 deletion src/LinkDotNet.Blog.Domain/BlogPostRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LinkDotNet.Blog.Domain;

public class BlogPostRecord : Entity
{
public string BlogPostId { get; init; }
public required string BlogPostId { get; init; }

public DateOnly DateClicked { get; init; }

Expand Down
2 changes: 1 addition & 1 deletion src/LinkDotNet.Blog.Domain/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public abstract class Entity
{
public string Id { get; set; }
public string? Id { get; set; }
}
8 changes: 2 additions & 6 deletions src/LinkDotNet.Blog.Domain/Enumeration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ public abstract class Enumeration<TEnumeration>
where TEnumeration : Enumeration<TEnumeration>
#pragma warning restore
{
protected Enumeration()
{
}

protected Enumeration(string key)
{
ArgumentException.ThrowIfNullOrWhiteSpace(key);
Expand All @@ -35,7 +31,7 @@ public static TEnumeration Create(string key)

public override int GetHashCode() => Key.GetHashCode(StringComparison.Ordinal);

public override bool Equals(object obj) => obj?.GetType() == typeof(TEnumeration) && ((TEnumeration)obj).Key == Key;
public override bool Equals(object? obj) => obj?.GetType() == typeof(TEnumeration) && ((TEnumeration)obj).Key == Key;

public override string ToString() => Key;

Expand All @@ -46,7 +42,7 @@ private static FrozenSet<TEnumeration> GetEnumerations()
return enumerationType
.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
.Where(info => info.FieldType == typeof(TEnumeration))
.Select(info => (TEnumeration)info.GetValue(null))
.Select(info => (TEnumeration)info.GetValue(null)!)
.ToFrozenSet();
}
}
6 changes: 3 additions & 3 deletions src/LinkDotNet.Blog.Domain/Introduction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ public sealed record Introduction
{
public const string IntroductionSection = "Introduction";

public string BackgroundUrl { get; init; }
public string? BackgroundUrl { get; init; }

public string ProfilePictureUrl { get; init; }
public required string ProfilePictureUrl { get; init; }

public string Description { get; init; }
public required string Description { get; init; }
}
2 changes: 1 addition & 1 deletion src/LinkDotNet.Blog.Domain/LinkDotNet.Blog.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>disable</Nullable>
<Nullable>enable</Nullable>
<AssemblyName>LinkDotNet.Blog.Domain</AssemblyName>
<RootNamespace>LinkDotNet.Blog.Domain</RootNamespace>
</PropertyGroup>
Expand Down
6 changes: 1 addition & 5 deletions src/LinkDotNet.Blog.Domain/ProficiencyLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ public sealed class ProficiencyLevel : Enumeration<ProficiencyLevel>
public static readonly ProficiencyLevel Proficient = new(nameof(Proficient));
public static readonly ProficiencyLevel Expert = new(nameof(Expert));

private ProficiencyLevel()
{
}

private ProficiencyLevel(string key)
: base(key)
{
}
}
}
7 changes: 4 additions & 3 deletions src/LinkDotNet.Blog.Domain/ProfileInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
public sealed record ProfileInformation
{
public const string ProfileInformationSection = "ProfileInformation";
public string Name { get; init; }

public string Heading { get; init; }
public required string Name { get; init; }

public string ProfilePictureUrl { get; init; }
public required string Heading { get; init; }

public required string ProfilePictureUrl { get; init; }
}
6 changes: 1 addition & 5 deletions src/LinkDotNet.Blog.Domain/ProfileInformationEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ namespace LinkDotNet.Blog.Domain;
[DebuggerDisplay("{Content} with sort order {SortOrder}")]
public sealed class ProfileInformationEntry : Entity
{
private ProfileInformationEntry()
{
}

public string Content { get; private init; }
public string Content { get; private init; } = default!;

public int SortOrder { get; set; }

Expand Down
10 changes: 3 additions & 7 deletions src/LinkDotNet.Blog.Domain/Skill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@ namespace LinkDotNet.Blog.Domain;

public sealed class Skill : Entity
{
private Skill()
{
}

private Skill(string name, string iconUrl, string capability, ProficiencyLevel proficiencyLevel)
private Skill(string name, string? iconUrl, string capability, ProficiencyLevel proficiencyLevel)
{
IconUrl = iconUrl;
Name = name;
Capability = capability;
ProficiencyLevel = proficiencyLevel;
}

public string IconUrl { get; private set; }
public string? IconUrl { get; private set; }

public string Name { get; private set; }

public string Capability { get; private set; }

public ProficiencyLevel ProficiencyLevel { get; private set; }

public static Skill Create(string name, string iconUrl, string capability, string proficiencyLevel)
public static Skill Create(string name, string? iconUrl, string capability, string proficiencyLevel)
{
ArgumentException.ThrowIfNullOrWhiteSpace(name);
ArgumentException.ThrowIfNullOrWhiteSpace(capability);
Expand Down
8 changes: 4 additions & 4 deletions src/LinkDotNet.Blog.Domain/Social.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ public sealed record Social
{
public const string SocialSection = "Social";

public string LinkedinAccountUrl { get; init; }
public string? LinkedinAccountUrl { get; init; }

public bool HasLinkedinAccount => !string.IsNullOrEmpty(LinkedinAccountUrl);

public string GithubAccountUrl { get; init; }
public string? GithubAccountUrl { get; init; }

public bool HasGithubAccount => !string.IsNullOrEmpty(GithubAccountUrl);

public string TwitterAccountUrl { get; init; }
public string? TwitterAccountUrl { get; init; }

public bool HasTwitterAccount => !string.IsNullOrEmpty(TwitterAccountUrl);
}
}
10 changes: 3 additions & 7 deletions src/LinkDotNet.Blog.Domain/Talk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ namespace LinkDotNet.Blog.Domain;

public sealed class Talk : Entity
{
private Talk()
{
}

public string PresentationTitle { get; private set; }
public string PresentationTitle { get; private set; } = default!;

public string Place { get; private set; }
public string Place { get; private set; } = default!;

public string Description { get; private set; }
public string Description { get; private set; } = default!;

public DateTime PublishedDate { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion src/LinkDotNet.Blog.Domain/UserRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public sealed class UserRecord : Entity
{
public DateOnly DateClicked { get; init; }

public string UrlClicked { get; init; }
public required string UrlClicked { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public async Task ShouldCreateRssFeed()
{
HttpContext = httpContext,
};
var config = Options.Create<ApplicationConfiguration>(new ApplicationConfiguration
var config = Options.Create(new ApplicationConfiguration
{
BlogName = "Test"
});
var introductionConfig = Options.Create<Introduction>(new Introduction
{
Description = "Description",
});

var introduction = new IntroductionBuilder()
.WithDescription("Description")
.Build();
var introductionConfig = Options.Create(introduction);
var blogPost1 = new BlogPostBuilder()
.WithTitle("1")
.WithShortDescription("Short 1")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using AngleSharp.Html.Dom;
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web;
using LinkDotNet.Blog.Web.Features.Home.Components;
using Microsoft.AspNetCore.Components;
Expand All @@ -20,7 +21,7 @@ public NavMenuTests()
public void ShouldNavigateToSearchPage()
{
Services.AddScoped(_ => Options.Create(new ApplicationConfiguration()));
this.AddAuthorization();
AddAuthorization();
var navigationManager = Services.GetRequiredService<NavigationManager>();
var cut = Render<NavMenu>();
cut.FindComponent<SearchInput>().Find("input").Change("Text");
Expand All @@ -38,7 +39,7 @@ public void ShouldDisplayAboutMePage()
IsAboutMeEnabled = true
});
Services.AddScoped(_ => config);
this.AddAuthorization();
AddAuthorization();

var cut = Render<NavMenu>();

Expand All @@ -51,9 +52,9 @@ public void ShouldDisplayAboutMePage()
[Fact]
public void ShouldPassCorrectUriToComponent()
{
var config = Options.Create(new ProfileInformation());
var config = Options.Create(new ProfileInformationBuilder().Build());
Services.AddScoped(_ => config);
this.AddAuthorization();
AddAuthorization();
var cut = Render<NavMenu>();

Services.GetRequiredService<NavigationManager>().NavigateTo("test");
Expand All @@ -70,10 +71,10 @@ public void ShouldShowBrandImageIfAvailable()
});
Services.AddScoped(_ => config);

var profileInfoConfig = Options.Create(new ProfileInformation());
var profileInfoConfig = Options.Create(new ProfileInformationBuilder().Build());
Services.AddScoped(_ => profileInfoConfig);

this.AddAuthorization();
AddAuthorization();

var cut = Render<NavMenu>();

Expand All @@ -95,10 +96,10 @@ public void ShouldShowBlogNameWhenNotBrand(string brandUrl)
});
Services.AddScoped(_ => config);

var profileInfoConfig = Options.Create(new ProfileInformation());
var profileInfoConfig = Options.Create(new ProfileInformationBuilder().Build());
Services.AddScoped(_ => profileInfoConfig);

this.AddAuthorization();
AddAuthorization();

var cut = Render<NavMenu>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ private static void SetupGetAll(
}

private RenderedComponent<Profile> RenderProfileWithEmptyInformation()
=> Render<Profile>(p => p.Add(s => s.ProfileInformation, new()));
=> Render<Profile>(p => p.Add(s => s.ProfileInformation, new ProfileInformationBuilder().Build()));

private RenderedComponent<Profile> RenderProfileInAdmin()
=> Render<Profile>(p => p
.Add(s => s.ProfileInformation, new())
.Add(s => s.ProfileInformation, new ProfileInformationBuilder().Build())
.Add(s => s.ShowAdminActions, true));
}
4 changes: 2 additions & 2 deletions tests/LinkDotNet.Blog.TestUtilities/BlogPostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class BlogPostBuilder
private string shortDescription = "Some Text";
private string content = "Some Content";
private string previewImageUrl = "localhost";
private string previewImageUrlFallback;
private string? previewImageUrlFallback;
private bool isPublished = true;
private string[] tags;
private string[] tags = [];
private int likes;
private DateTime? updateDate;
private DateTime? scheduledPublishDate;
Expand Down
11 changes: 5 additions & 6 deletions tests/LinkDotNet.Blog.TestUtilities/Fakes/MarkdownFake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ namespace LinkDotNet.Blog.TestUtilities.Fakes;

public sealed class MarkdownFake : ComponentBase
{
[Parameter]
public string Value { get; set; }
[Parameter] public string Value { get; set; } = string.Empty;

[Parameter]
public EventCallback<string> ValueChanged { get; set; }

[Parameter]
public string Class { get; set; }
public string Class { get; set; } = string.Empty;

[Parameter]
public string Id { get; set; }
public string Id { get; set; } = string.Empty;

[Parameter]
public int Rows { get; set; }

[Parameter]
public string Placeholder { get; set; }
public string Placeholder { get; set; } = string.Empty;

protected override void BuildRenderTree(RenderTreeBuilder builder)
{
Expand All @@ -31,7 +30,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
builder.AddAttribute(3, "rows", Rows);
builder.AddAttribute(4, "oninput", EventCallback.Factory.Create<ChangeEventArgs>(this, async args =>
{
Value = args.Value.ToString();
Value = args.Value!.ToString()!;
await ValueChanged.InvokeAsync(Value);
}));
builder.AddContent(5, Value);
Expand Down
Loading

0 comments on commit 26becfb

Please sign in to comment.