Skip to content

Commit ba7d570

Browse files
authored
Complete server coverage. (#31)
* (#28) Guards moved to new library; reorg of test libraries to compensate for naming. * (#28) Full test coverage (including live tests) for server. * Updated library list for GitHub Actions releases
1 parent 0e310cd commit ba7d570

File tree

21 files changed

+751
-276
lines changed

21 files changed

+751
-276
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
**/CommunityToolkit.Datasync.Common
12
**/CommunityToolkit.Datasync.Server
23
**/CommunityToolkit.Datasync.Server.Abstractions
34
**/CommunityToolkit.Datasync.Server.Automapper
45
**/CommunityToolkit.Datasync.Server.EntityFrameworkCore
56
**/CommunityToolkit.Datasync.Server.InMemory
67
**/CommunityToolkit.Datasync.Server.LiteDb
7-
**/CommunityToolkit.Datasync.Client

src/CommunityToolkit.Datasync.Common/Guards/ParamExtensions.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,6 @@ public static Param<Uri> IsAbsoluteUri(this Param<Uri> param, string? because =
6969
return param;
7070
}
7171

72-
/// <summary>
73-
/// Guards against a string not being a valid Id.
74-
/// </summary>
75-
/// <param name="param">The parameter to check.</param>
76-
/// <param name="because">A reason to use instead of the default reason.</param>
77-
/// <returns>The parameter (for chaining)</returns>
78-
/// <exception cref="ArgumentException">Thrown if the ID is not valid.</exception>
79-
public static Param<string> IsAValidId(this Param<string> param, string? because = null)
80-
{
81-
if (!RegexpConstants.EntityIdentity.IsMatch(param.Value))
82-
{
83-
because ??= $"The parameter '{param.Name}' must be a valid Id";
84-
throw new ArgumentException(because, param.Name);
85-
}
86-
87-
return param;
88-
}
89-
9072
/// <summary>
9173
/// Guards against invalid datasync service endpoint URIs.
9274
/// </summary>
@@ -248,6 +230,24 @@ public static Param<string> IsNotNullOrWhiteSpace(this Param<string> param, stri
248230
return param;
249231
}
250232

233+
/// <summary>
234+
/// Guards against a string not being a valid Id.
235+
/// </summary>
236+
/// <param name="param">The parameter to check.</param>
237+
/// <param name="because">A reason to use instead of the default reason.</param>
238+
/// <returns>The parameter (for chaining)</returns>
239+
/// <exception cref="ArgumentException">Thrown if the ID is not valid.</exception>
240+
public static Param<string> IsValidId(this Param<string> param, string? because = null)
241+
{
242+
if (!RegexpConstants.EntityIdentity.IsMatch(param.Value))
243+
{
244+
because ??= $"The parameter '{param.Name}' must be a valid Id";
245+
throw new ArgumentException(because, param.Name);
246+
}
247+
248+
return param;
249+
}
250+
251251
/// <summary>
252252
/// Checks to ensure that the provided string parameter matches a provided regular expression.
253253
/// </summary>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore;
6+
7+
/// <summary>
8+
/// A version of the <see cref="BaseEntityTableData"/> that updates both the
9+
/// <c>UpdatedAt</c> and <c>Version</c> fields within the repository (instead
10+
/// of relying on the database server to do it).
11+
/// </summary>
12+
public class RepositoryControlledEntityTableData : BaseEntityTableData
13+
{
14+
/// <inheritdoc />
15+
[UpdatedByRepository]
16+
public override DateTimeOffset? UpdatedAt { get; set; } = DateTimeOffset.UnixEpoch;
17+
18+
/// <inheritdoc />
19+
[UpdatedByRepository]
20+
public override byte[] Version { get; set; } = [];
21+
}

tests/CommunityToolkit.Datasync.Common.Test/CommunityToolkit.Datasync.Common.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\Shared.Build.props" />
33
<ItemGroup>
44
<ProjectReference Include="..\..\src\CommunityToolkit.Datasync.Common\CommunityToolkit.Datasync.Common.csproj" />

tests/CommunityToolkit.Datasync.Common.Test/Ensure_Tests.cs

Lines changed: 0 additions & 139 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using CommunityToolkit.Datasync.TestCommon.Models;
6+
7+
using TestData = CommunityToolkit.Datasync.TestCommon.TestData;
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
14+
namespace CommunityToolkit.Datasync.Common.Test.Extensions;
15+
16+
[ExcludeFromCodeCoverage]
17+
public class Clone_Tests
18+
{
19+
[Fact]
20+
public void Clone_Null_Works()
21+
{
22+
object obj = null;
23+
object result = obj.Clone();
24+
result.Should().BeNull();
25+
}
26+
27+
[Fact]
28+
public void Clone_Works()
29+
{
30+
MovieBase sut = TestData.Movies.BlackPanther;
31+
MovieBase b = sut.Clone();
32+
b.Should().NotBeSameAs(sut).And.BeEquivalentTo(sut);
33+
}
34+
}

0 commit comments

Comments
 (0)