コード例 #1
0
 public static TEntity AddOrUpdate <TKey, TEntity>(this IProjectionWriter <TKey, TEntity> writer, TKey key, Func <TEntity> addFactory, Action <TEntity> update)
 {
     return(writer.AddOrUpdate(key, addFactory, entity =>
     {
         update(entity);
         return entity;
     }));
 }
コード例 #2
0
 public static TEntity UpdateOrThrow <TKey, TEntity>(this IProjectionWriter <TKey, TEntity> writer, TKey key, Action <TEntity> change)
 {
     return(writer.AddOrUpdate(key, () =>
     {
         var txt = $"Failed to load '{typeof(TEntity).Name}' with key '{key}'.";
         throw new InvalidOperationException(txt);
     }, change));
 }
コード例 #3
0
 public static TEntity Add <TKey, TEntity>(this IProjectionWriter <TKey, TEntity> writer, TKey key, TEntity newEntity)
 {
     return(writer.AddOrUpdate(key, newEntity, e =>
     {
         var txt = $"Entity '{typeof(TEntity).Name}' with key '{key}' should not exist.";
         throw new InvalidOperationException(txt);
     }));
 }
コード例 #4
0
 public static TEntity AddOrUpdate <TKey, TEntity>(this IProjectionWriter <TKey, TEntity> writer, TKey key, TEntity newView, Action <TEntity> updateViewFactory)
 {
     return(writer.AddOrUpdate(key, () => newView, view =>
     {
         updateViewFactory(view);
         return view;
     }));
 }
コード例 #5
0
 public static TView UpdateEnforcingNew <TKey, TView>(this IProjectionWriter <TKey, TView> writer, TKey key,
                                                      Action <TView> update)
     where TView : new()
 {
     return(writer.AddOrUpdate(key, () =>
     {
         var view = new TView();
         update(view);
         return view;
     }, v =>
     {
         update(v);
         return v;
     }));
 }
コード例 #6
0
        public void When_not_found_key_get_new_view_and_not_call_action()
        {
            Test1 t = new Test1 {
                Value = 555
            };

            var key = Guid.NewGuid();

            var newValue = _guidKeyClassWriter.AddOrUpdate(key, t, tv => { tv.Value += 1; });

            t.Should().Be(newValue);

            555.Should().Be(newValue.Value);
        }
コード例 #7
0
 public static async Task Add <TId, TView>(this IProjectionWriter <TId, TView> writer, TId key, TView item) where TView : class
 {
     await writer.AddOrUpdate(key, () => item, null, false);
 }
コード例 #8
0
 public static async Task UpdateEnforcingNew <TId, TView>(this IProjectionWriter <TId, TView> writer, TId key, Action <TView> update)
     where TView : class, new()
 {
     await writer.AddOrUpdate(key, () => new TView(), x => { update(x); return(x); });
 }
コード例 #9
0
 public static async Task Update <TId, TView>(this IProjectionWriter <TId, TView> writer, TId key, Func <TView, TView> update) where TView : class
 {
     await writer.AddOrUpdate(key, null, update);
 }
コード例 #10
0
 public static async Task Update <TId, TView>(this IProjectionWriter <TId, TView> writer, TId key, Action <TView> update) where TView : class
 {
     await writer.AddOrUpdate(key, null, x => { update(x); return(x); });
 }
コード例 #11
0
 public static async Task Add <TId, TView>(this IProjectionWriter <TId, TView> writer, TId key, Func <TView> addFactory) where TView : class
 {
     await writer.AddOrUpdate(key, addFactory, null, false);
 }