-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da7db3e
commit 8620fe1
Showing
9 changed files
with
113 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using Dolittle.SDK.Projections; | ||
using Dolittle.SDK.Testing.Aggregates.Events; | ||
|
||
namespace Dolittle.SDK.Testing.Projections; | ||
|
||
public class ProjectionAssertions<TProjection> | ||
where TProjection : ReadModel, new() | ||
{ | ||
readonly ImmutableDictionary<Key, TProjection> _projections; | ||
|
||
|
||
public ProjectionAssertions(IDictionary<Key, TProjection> projections) | ||
{ | ||
_projections = projections.ToImmutableDictionary(); | ||
} | ||
|
||
public TProjection ReadModel(Key key) | ||
{ | ||
return _projections.GetValueOrDefault(key) ?? throw new ReadModelDidNotExist(key); | ||
} | ||
|
||
public ReadModelValueAssertion<TProjection> HasReadModel(Key key) | ||
{ | ||
return new ReadModelValueAssertion<TProjection>(ReadModel(key)); | ||
} | ||
|
||
public void ReadModelDoesNotExist(Key key) | ||
{ | ||
if (_projections.TryGetValue(key, out var projection)) | ||
{ | ||
throw new ReadModelExistedWhenItShouldNot(key, projection); | ||
} | ||
} | ||
} | ||
|
||
public class ReadModelExistedWhenItShouldNot : DolittleAssertionFailed | ||
{ | ||
public ReadModelExistedWhenItShouldNot(Key key, object projection) | ||
: base($"Read model for {key} existed when it should not. Projection: {projection}") | ||
{ | ||
} | ||
} | ||
|
||
public class ReadModelDidNotExist : DolittleAssertionFailed | ||
{ | ||
public ReadModelDidNotExist(Key key) | ||
: base($"Read model for {key} did not exist") | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
|
||
namespace Dolittle.SDK.Testing.Aggregates.Events; | ||
|
||
/// <summary> | ||
/// Fluent interface element allowing assertions against a specific event. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the event you wish to assert against.</typeparam> | ||
/// <remarks> | ||
/// Initializes a new instance of the <see cref="EventValueAssertion{T}"/> class with the event to assert against. | ||
/// </remarks> | ||
/// <param name="model">The event you wish to assert against.</param> | ||
public class ReadModelValueAssertion<T>(T model) | ||
where T : class | ||
{ | ||
/// <summary> | ||
/// Gets the event that is being asserted against. | ||
/// </summary> | ||
public T ReadModel { get; } = model; | ||
|
||
/// <summary> | ||
/// Asserts that the event passes the specified assertions. | ||
/// </summary> | ||
/// <param name="assertions">>A collection of assertions that you wish to perform.</param> | ||
public void Where(params Action<T>[] assertions) | ||
{ | ||
foreach (var assert in assertions) | ||
{ | ||
assert(ReadModel); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters