Пример #1
0
        protected override void Arrange()
        {
            _book   = Book.Create(_bookId);
            _lender = Lender.Create(_lenderId, new FullName("Tony", "Stark"));

            _timeMock.Setup(x => x.Now()).Returns(_now);

            _bookForRentRepositoryMock = new Mock <IBookForRentRepository>();
            _bookForRentRepositoryMock.Setup(x => x.Get(It.IsAny <BookId>())).Returns(Task.Run(() => _book));

            _lenderRepositoryMock = new Mock <ILenderRepository>();
            _lenderRepositoryMock.Setup(x => x.Get(It.IsAny <LenderId>())).Returns(Task.Run(() => _lender));

            _handler = new RentBookUseCase(_bookForRentRepositoryMock.Object, _timeMock.Object, _lenderRepositoryMock.Object);
        }
        private static (Type requestType, ExecutionContext ctx) HandlerMethodSelector(
            IInputPortHandler portHandler)
        {
            var type = portHandler.GetType();

            var methodInfo = type.GetMethod(HANDLER_METHOD_NAME);
            var @interface = type.GetInterfaces()
                             .FirstOrDefault(x => x.IsGenericType && typeof(IInputPortHandler <>) == x.GetGenericTypeDefinition());
            var genericParameter = @interface?.GetGenericArguments()
                                   .FirstOrDefault();

            if (methodInfo == null || genericParameter == null)
            {
                throw new ArchitectureVolationException(
                          $"Every {nameof(IInputPortHandler)} should implement generic interface with \"Handle\" method");
            }

            return(genericParameter, new ExecutionContext(methodInfo, portHandler));
        }
 public ExecutionContext(MethodInfo method, IInputPortHandler executionObject)
 {
     _method          = method;
     _executionObject = executionObject;
 }