コード例 #1
0
        private EventBase CreateEvent <T, TK>() where T : PubSubEvent <TK>
        {
            var sId = typeof(T).FullName;

            if (_events.ContainsKey(sId))
            {
                return(_events[sId]);
            }

            var mockedEvent = new Mock <T>();
            var cont        = new ActionContainer <TK>();

            mockedEvent.Setup(x =>
                              x.Subscribe(
                                  It.IsAny <Action <TK> >(),
                                  It.IsAny <ThreadOption>(),
                                  It.IsAny <bool>(),
                                  It.IsAny <Predicate <TK> >()
                                  ))
            .Callback <Action <TK>, ThreadOption, bool, Predicate <TK> >(
                (a, o, b, p) =>
            {
                cont.Inner = a;
            });

            mockedEvent.Setup(x => x.Publish(It.IsAny <TK>()))
            .Callback <TK>(m =>
            {
                cont.Inner(m);
            });


            _events.Add(sId, mockedEvent.Object);

            return(mockedEvent.Object);
        }