Skip to content

Commit 0d7ad3a

Browse files
Add sample projects
1 parent d01f955 commit 0d7ad3a

File tree

13 files changed

+248
-0
lines changed

13 files changed

+248
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Ace.CSharp.StructuredAutoMapper.Abstractions.Test;
2+
using Ace.CSharp.StructuredAutoMapper.Sample.Dtos;
3+
using Ace.CSharp.StructuredAutoMapper.Sample.Entities;
4+
using Ace.CSharp.StructuredAutoMapper.Sample.MappingProfiles;
5+
6+
namespace Ace.CSharp.StructuredAutoMapper.Sample.Tests;
7+
8+
public sealed class BarMappingProfileTests
9+
: BaseOneWayProfileTests<BarMappingProfile, BarEntity, BarDto>
10+
{
11+
protected sealed override Func<BarEntity> Left =>
12+
() => new BarEntity(Guid.NewGuid(), "bar");
13+
14+
protected sealed override Action<BarEntity, BarDto> LeftToRightAssertions =>
15+
(entity, dto) =>
16+
{
17+
// FluentAssertions
18+
dto.Id.Should().Be(entity.Id);
19+
dto.Value.Should().Be(entity.Value);
20+
21+
// xUnit Assertions
22+
Assert.Equal(entity.Id, dto.Id);
23+
Assert.Equal(entity.Value, dto.Value);
24+
};
25+
26+
[Fact]
27+
public sealed override void GivenMapFromLeftToRightWhenSourceIsNotNullThenMapsData()
28+
{
29+
base.GivenMapFromLeftToRightWhenSourceIsNotNullThenMapsData();
30+
}
31+
32+
[Fact]
33+
public sealed override void GivenMapFromLeftToRightWhenSourceIsNullThenHandlesGracefully()
34+
{
35+
base.GivenMapFromLeftToRightWhenSourceIsNullThenHandlesGracefully();
36+
}
37+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Ace.CSharp.StructuredAutoMapper.Abstractions.Test;
2+
using Ace.CSharp.StructuredAutoMapper.Sample.Dtos;
3+
using Ace.CSharp.StructuredAutoMapper.Sample.Entities;
4+
using Ace.CSharp.StructuredAutoMapper.Sample.MappingProfiles;
5+
6+
namespace Ace.CSharp.StructuredAutoMapper.Sample.Tests;
7+
8+
public sealed class FooMappingProfileTests
9+
: BaseTwoWayProfileTests<FooMappingProfile, FooEntity, FooDto>
10+
{
11+
protected sealed override Func<FooEntity> Left =>
12+
() => new FooEntity(Guid.NewGuid(), "foo");
13+
14+
protected sealed override Func<FooDto> Right =>
15+
() => new FooDto(Guid.NewGuid(), "foo-dto");
16+
17+
protected sealed override Action<FooEntity, FooDto>? LeftToRightAssertions =>
18+
(entity, dto) =>
19+
{
20+
dto.Id.Should().Be(entity.Id);
21+
dto.Value.Should().Be(entity.Value);
22+
};
23+
24+
protected sealed override Action<FooDto, FooEntity>? RightToLeftAssertions =>
25+
(dto, entity) =>
26+
{
27+
entity.Id.Should().Be(dto.Id);
28+
entity.Value.Should().Be(dto.Value);
29+
};
30+
31+
[Fact]
32+
public sealed override void GivenMapFromLeftToRightWhenSourceIsNullThenHandlesGracefully()
33+
{
34+
base.GivenMapFromLeftToRightWhenSourceIsNullThenHandlesGracefully();
35+
}
36+
37+
[Fact]
38+
public sealed override void GivenMapFromLeftToRightWhenSourceIsNotNullThenMapsData()
39+
{
40+
base.GivenMapFromLeftToRightWhenSourceIsNotNullThenMapsData();
41+
}
42+
43+
[Fact]
44+
public sealed override void GivenMapFromRightToLeftWhenSourceIsNullThenHandlesGracefully()
45+
{
46+
base.GivenMapFromRightToLeftWhenSourceIsNullThenHandlesGracefully();
47+
}
48+
49+
[Fact]
50+
public sealed override void GivenMapFromRightToLeftWhenSourceIsNotNullThenMapsData()
51+
{
52+
base.GivenMapFromRightToLeftWhenSourceIsNotNullThenMapsData();
53+
}
54+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global using FluentAssertions;
2+
global using Xunit;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using Ace.CSharp.StructuredAutoMapper.Abstractions.Test;
2+
using Ace.CSharp.StructuredAutoMapper.Sample.Dtos;
3+
using Ace.CSharp.StructuredAutoMapper.Sample.Entities;
4+
using Ace.CSharp.StructuredAutoMapper.Sample.MappingProfiles;
5+
6+
namespace Ace.CSharp.StructuredAutoMapper.Sample.Tests;
7+
8+
public sealed class TransactionMappingProfileTests
9+
: BaseTwoWayProfileTests<TransactionMappingProfile, TransactionEntity, TransactionDto>
10+
{
11+
protected sealed override Func<TransactionEntity> Left =>
12+
() =>
13+
new TransactionEntity
14+
{
15+
Id = 1,
16+
OperatorId = Guid.Empty,
17+
ProcessedAt = DateTimeOffset.UtcNow,
18+
Amount = 1.2345D
19+
};
20+
21+
protected sealed override Func<TransactionDto> Right =>
22+
() =>
23+
new TransactionDto
24+
{
25+
Id = 1,
26+
ProcessedAt = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
27+
Amount = 9.8765D
28+
};
29+
30+
protected sealed override Action<TransactionEntity, TransactionDto>? LeftToRightAssertions =>
31+
(entity, dto) =>
32+
{
33+
dto.Id.Should().Be(entity.Id);
34+
dto.ProcessedAt.Should().Be(entity.ProcessedAt.ToUnixTimeMilliseconds());
35+
dto.Amount.Should().Be(entity.Amount);
36+
};
37+
38+
protected sealed override Action<TransactionDto, TransactionEntity>? RightToLeftAssertions =>
39+
(dto, entity) =>
40+
{
41+
entity.Id.Should().Be(dto.Id);
42+
entity.OperatorId.Should().BeEmpty();
43+
entity.ProcessedAt.Should().Be(DateTimeOffset.FromUnixTimeMilliseconds(dto.ProcessedAt));
44+
entity.Amount.Should().Be(dto.Amount);
45+
};
46+
47+
[Fact]
48+
public sealed override void GivenMapFromLeftToRightWhenSourceIsNullThenHandlesGracefully()
49+
{
50+
base.GivenMapFromLeftToRightWhenSourceIsNullThenHandlesGracefully();
51+
}
52+
53+
[Fact]
54+
public sealed override void GivenMapFromLeftToRightWhenSourceIsNotNullThenMapsData()
55+
{
56+
base.GivenMapFromLeftToRightWhenSourceIsNotNullThenMapsData();
57+
}
58+
59+
[Fact]
60+
public sealed override void GivenMapFromRightToLeftWhenSourceIsNullThenHandlesGracefully()
61+
{
62+
base.GivenMapFromRightToLeftWhenSourceIsNullThenHandlesGracefully();
63+
}
64+
65+
[Fact]
66+
public sealed override void GivenMapFromRightToLeftWhenSourceIsNotNullThenMapsData()
67+
{
68+
base.GivenMapFromRightToLeftWhenSourceIsNotNullThenMapsData();
69+
}
70+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Ace.CSharp.StructuredAutoMapper.Sample.Dtos;
2+
3+
public sealed record BarDto(Guid Id, string Value);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Ace.CSharp.StructuredAutoMapper.Sample.Dtos;
2+
3+
public sealed record FooDto(Guid Id, string Value);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Ace.CSharp.StructuredAutoMapper.Sample.Dtos;
2+
3+
public sealed class TransactionDto
4+
{
5+
public int Id { get; set; }
6+
7+
public long ProcessedAt { get; set; }
8+
public double Amount { get; set; }
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Ace.CSharp.StructuredAutoMapper.Sample.Entities;
2+
3+
public sealed record BarEntity(Guid Id, string Value);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Ace.CSharp.StructuredAutoMapper.Sample.Entities;
2+
3+
public sealed record FooEntity(Guid Id, string Value);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Ace.CSharp.StructuredAutoMapper.Sample.Entities;
2+
3+
public sealed class TransactionEntity
4+
{
5+
public int Id { get; set; }
6+
public Guid OperatorId { get; set; }
7+
8+
public DateTimeOffset ProcessedAt { get; set; }
9+
public double Amount { get; set; }
10+
}

0 commit comments

Comments
 (0)