-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorder Source/FlowWithContext type parameters
- Loading branch information
1 parent
39d6c10
commit fb5abff
Showing
9 changed files
with
209 additions
and
128 deletions.
There are no files selected for viewing
67 changes: 35 additions & 32 deletions
67
src/core/Akka.API.Tests/CoreAPISpec.ApproveStreams.approved.txt
Large diffs are not rendered by default.
Oops, something went wrong.
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,80 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="FlowWithContextSpec.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2021 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Linq; | ||
using Akka.Streams.Dsl; | ||
using Akka.Streams.TestKit; | ||
using Akka.TestKit; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Akka.Streams.Tests.Dsl | ||
{ | ||
public class FlowWithContextSpec : AkkaSpec | ||
{ | ||
private ActorMaterializer Materializer { get; } | ||
|
||
public FlowWithContextSpec(ITestOutputHelper helper) : base(helper) | ||
{ | ||
var settings = ActorMaterializerSettings.Create(Sys); | ||
Materializer = ActorMaterializer.Create(Sys, settings); | ||
} | ||
|
||
[Fact] | ||
public void A_FlowWithContext_must_get_created_from_FlowAsFlowWithContext() | ||
{ | ||
var flow = Flow.Create<Message>().Select(m => m.Copy(data: m.Data + "z")); | ||
var flowWithContext = flow.AsFlowWithContext<Message, long, Message, long, NotUsed, Message>((m, o) => new Message(m.Data, o), m => m.Offset); | ||
|
||
Source.From(new[] { new Message("a", 1L) }) | ||
.AsSourceWithContext(m => m.Offset) | ||
.Via(flowWithContext) | ||
.AsSource() | ||
.RunWith(this.SinkProbe<(Message, long)>(), Materializer) | ||
.Request(1) | ||
.ExpectNext((new Message("az", 1L), 1L)) | ||
.ExpectComplete(); | ||
} | ||
} | ||
|
||
sealed class Message : IEquatable<Message> | ||
{ | ||
public string Data { get; } | ||
public long Offset { get; } | ||
|
||
public Message(string data, long offset) | ||
{ | ||
Data = data; | ||
Offset = offset; | ||
} | ||
|
||
public Message Copy(string data = null, long? offset = null) => new Message(data ?? Data, offset ?? Offset); | ||
|
||
public bool Equals(Message other) | ||
{ | ||
if (other is null) return false; | ||
if (ReferenceEquals(this, other)) return true; | ||
return string.Equals(Data, other.Data) && Offset == other.Offset; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (obj is null) return false; | ||
if (ReferenceEquals(this, obj)) return true; | ||
return obj is Message other && Equals(other); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
return ((Data != null ? Data.GetHashCode() : 0) * 397) ^ Offset.GetHashCode(); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.