Beispiel #1
0
        public void CreateRequest(Request request)
        {
            if (request == null)
                throw new ArgumentNullException("request");

            using (IUnitOfWork unitOfWork = _unitOfWorkFactory.Create())
            {
                var requestEntity = unitOfWork.CreateEntity<Domain.Entities.Request>();

                string requestResult;

                // TODO: Add exception handling
                switch (request.Type)
                {
                    case RequestType.Operation:
                        //requestResult = _tuWebService.Operation(request.RequestString);
                        break;
                    case RequestType.Train:
                        //requestResult = _tuWebService.Operation(request.RequestString);
                        break;
                    default:
                        throw new UnsupportedRequestException(request.Type);
                }

                //var map = Mapper.Map<Request>();
                requestEntity.RequestDate = _dateTimeService.GetCurrentDateAndTime();
                requestEntity.RequestType = (Domain.Entities.RequestType) request.Type;
                //requestEntity.RequestText = request.RequestString;
                //requestEntity.RequestState = requestResult;
                //requestEntity.RequestId = ???;

                unitOfWork.Commit();
            }
        }
        public void SendRequest_Request_NonEmpty_Passes()
        {
            // Arrange
            _autoMockContainer
                .Register<IRequestService, RequestService>();

            var mockUnitOfWork = _autoMockContainer
                .GetMock<IUnitOfWork>();

            var requestEntity = new Domain.Entities.Request();

            mockUnitOfWork
                .Setup(uow => uow.CreateEntity<Domain.Entities.Request>())
                .Returns(requestEntity);

            _autoMockContainer
                .GetMock<IUnitOfWorkFactory>().Setup(uowf => uowf.Create())
                .Returns(mockUnitOfWork.Object);

            _autoMockContainer
                .GetMock<IDateTimeService>()
                .Setup(dts => dts.GetCurrentDateAndTime())
                .Returns(DateTime.Now);

            // Act
            Request request = new Request
                                  {
                                      Type = RequestType.Operation,
                                      //RequestString = "Test operation"
                                  };

            Assert.ThrowsDelegate sendRequestAction = () => _autoMockContainer.Resolve<IRequestService>().CreateRequest(request);

            // Assert
            Assert.DoesNotThrow(sendRequestAction);
            //Assert.Equal(requestEntity.RequestText, request.RequestString);
            Assert.Equal(requestEntity.RequestType, (Domain.Entities.RequestType)request.Type);
        }