summaryrefslogtreecommitdiff
path: root/src/Notepad/Test/Call.cs
blob: 67ab49c0b8d3890b69ea4b907b7c48ca83371c81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Linq.Expressions;

namespace Notepad.Test {
    public class Call {
        public static IActionRecorder To(Expression<Action> actionToRecord) {
            return new ActionRecorder(actionToRecord.Compile());
        }
    }

    public class ActionRecorder : IActionRecorder {
        private readonly Action actionToRecord;

        public ActionRecorder(Action actionToRecord) {
            this.actionToRecord = actionToRecord;
        }

        public Action ActionToRecord() {
            return actionToRecord;
        }
    }

    public interface IActionRecorder {
        Action ActionToRecord();
    }

    public static class ActionRecorderExtensions {
        public static void ShouldThrow<ThisException>(this IActionRecorder recorder) where ThisException : Exception {
            try {
                recorder.ActionToRecord()();
            }
            catch (ThisException) {
                return;
            }
        }
    }
}