Esempio n. 1
0
            private async IAsyncEnumerable <T> Impl([EnumeratorCancellation] CancellationToken cancellationToken = default)
            {
                if (Replay)
                {
                    for (var i = 0; i < _stream.StoredData.Count; i++) // Not using foreach, as StoredData can change asynchronously
                    {
                        var value = FakeConfiguration.Deserialize <T>(_stream.StoredData[i]);
                        if (Filter(value))
                        {
                            // NOTE: We are not saving state entries here
                            yield return(value);
                        }
                    }
                }

                // NOTE: Race condition: can miss elements while switching from replay to realtime

                await foreach (var i in _stream.GetChannel().ReadAllAsync())
                {
                    var value = FakeConfiguration.Deserialize <T>(_stream.StoredData[i]);

                    if (Filter(value))
                    {
                        // NOTE: We are not saving state entries here
                        yield return(value);
                    }
                }
            }
Esempio n. 2
0
        internal async Task <TResult> CallAsync <TParams, TResult>(string functionDelegate, TParams parameters)
        {
            if (!functions.TryGetValue(functionDelegate, out var function))
            {
                throw new IndexOutOfRangeException("Function '" + functionDelegate + "' is not registered.");
            }
            var input  = FakeConfiguration.Serialize(parameters);
            var result = await function(input);

            return(FakeConfiguration.Deserialize <TResult>(result));
        }
Esempio n. 3
0
        public static (IStream <T>, string) CreateBlankStream <T>()
        {
            var channel = Channel.CreateUnbounded <object?>();
            var stream  = new FakeStream <T>(channel.Reader.ReadAllAsync().Select(x => FakeConfiguration.Deserialize <T>(x)));
            var name    = $"-{Guid.NewGuid()}";

            blankStreams[name] = channel.Writer;
            return(stream, name);
        }
Esempio n. 4
0
 public FakeAgent RegisterFunction <TParams>(string functionDelegate, Func <TParams, Task> function)
 {
     functions.Add(functionDelegate, async(input) => { await function(FakeConfiguration.Deserialize <TParams>(input)); return(null); });
     return(this);
 }
Esempio n. 5
0
 public FakeAgent RegisterFunction <TParams>(string functionDelegate, Action <TParams> function)
 {
     functions.Add(functionDelegate, (input) => { function(FakeConfiguration.Deserialize <TParams>(input)); return(Task.FromResult <object?>(null)); });
     return(this);
 }
Esempio n. 6
0
 public FakeAgent RegisterFunction <TParams, TResult>(string functionDelegate, Func <TParams, TResult> function)
 {
     functions.Add(functionDelegate, (input) => Task.FromResult(FakeConfiguration.Serialize(function(FakeConfiguration.Deserialize <TParams>(input)))));
     return(this);
 }
Esempio n. 7
0
 public void SetValue <T>(string key, T value)
 {
     Values[key] = FakeConfiguration.Serialize(value);
 }
Esempio n. 8
0
 public T GetValue <T>(string key, Func <T> defaultValueFactory)
 {
     return(FakeConfiguration.Deserialize <T>(Values.GetOrAdd(key, _k => FakeConfiguration.Serialize(defaultValueFactory()))));
 }
Esempio n. 9
0
 public T GetValue <T>(string key)
 {
     return(FakeConfiguration.Deserialize <T>(Values[key]));
 }
Esempio n. 10
0
 public async Task AddAsync(T item, CancellationToken cancellationToken = default)
 {
     await _channelWriter.WriteAsync(FakeConfiguration.Serialize(item), cancellationToken);
 }