Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix mutation score #69

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions SO/Api/Args/Post/GetArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed record GetArgs
public int Offset { get; init; }
[Required]
public int Limit { get; init; }
public SearchArgs[]? SearchArgs { get; init; }
public SortArgs? SortArgs { get; init; }
public SearchArgs[] SearchArgs { get; init; }
public SortArgs SortArgs { get; init; }
}
}
2 changes: 1 addition & 1 deletion SO/Logic/BoundedContexts/Posts/Entities/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static Result<Post, Error> Create(string title, string body, DateTime cre
return Errors.General.InvalidLength(nameof(body));

var trimmedTags = tags?.Trim() ?? string.Empty;
if (trimmedTags?.Length > 100)
if (trimmedTags.Length > 100)
return Errors.General.InvalidLength(nameof(tags));

if (createDate == DateTime.MinValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static bool IsBoolOperation(SearchOperation operation)

private Nest.QueryContainer BuildQuery(IEnumerable<SearchArgs> searchArgs)
{
Nest.QueryContainer queryContainer = null;
Nest.QueryContainer? queryContainer = null;
foreach (var arg in searchArgs)
queryContainer &= CreateFieldQuery(arg.Field, arg.Operation, arg.Value);

Expand Down
31 changes: 31 additions & 0 deletions SO/Tests/UnitTests/Logic/Posts/PostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ public void Should_CreateSucceed_WhenAllPropertiesMaxLength()
Assert.NotNull(result.Value);
}

[Fact]
public void Should_CreateSucceed_WhenTagsIsNull()
{
var result = Post.Create
(
tags: null,
title: CreateString(5),
body: CreateString(50),
createDate: _sut.CreateDate,
author: _user
);

Assert.True(result.IsSuccess);
Assert.NotNull(result.Value);
}

[Theory]
[InlineData(null)]
[InlineData("")]
Expand All @@ -178,6 +194,21 @@ public void Should_CreateFail_WhenTitleIsInvalid(string invalidTitle)
Assert.Contains("title", result.Error.Message);
}

[Fact]
public void Should_CreateThrowAnException_WhenUserIsNull()
{
var exception = Assert.Throws<ArgumentNullException>(() => Post.Create
(
author: null,
title: CreateString(250),
body: CreateString(1000),
tags: CreateString(100),
createDate: _sut.CreateDate
));

Assert.Equal("Value cannot be null. (Parameter 'author')", exception.Message);
}

[Theory]
[InlineData(null)]
[InlineData("")]
Expand Down