Example #1
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));
        }
Example #2
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);
 }
Example #3
0
 public FakeAgent RegisterFunction <TParams, TResult>(string functionDelegate, Func <TParams, Task <TResult> > function)
 {
     functions.Add(functionDelegate, async(input) => FakeConfiguration.Serialize(await function(FakeConfiguration.Deserialize <TParams>(input))));
     return(this);
 }
Example #4
0
 public void SetValue <T>(string key, T value)
 {
     Values[key] = FakeConfiguration.Serialize(value);
 }
Example #5
0
 public T GetValue <T>(string key, Func <T> defaultValueFactory)
 {
     return(FakeConfiguration.Deserialize <T>(Values.GetOrAdd(key, _k => FakeConfiguration.Serialize(defaultValueFactory()))));
 }
Example #6
0
 public async Task AddAsync(T item, CancellationToken cancellationToken = default)
 {
     await _channelWriter.WriteAsync(FakeConfiguration.Serialize(item), cancellationToken);
 }