public EmailProcessingSagaContext()
		{
			ObjectFactory.Configure(x => x.For<EmailProcessingSagaContext>().Use(this));

			_emailMessage = new EmailMessage
			{
				FromDisplayName = "John Smith",
				SendDate = DateTime.Now.AddDays(-1),
				MessageUidDto = new MessageUidDTO {UID = new Random().Next().ToString()}
			};

			_createdMessageDtos = new List<MessageDTO>();

			Transport.On<CreateCommand>(x => x.Dto is RequesterDTO)
				.Reply(x =>
				       {
				       	var emailToCreate = ((RequesterDTO) x.Dto).Email;
				       	if (_createdRequesterEmail == emailToCreate)
				       	{
				       		return new EmptyMessage();
				       	}

				       	_createdRequesterEmail = emailToCreate;
				       	return new RequesterCreatedMessage
				       	{
				       		Dto = new RequesterDTO
				       		{
				       			Email = ((RequesterDTO) x.Dto).Email,
				       			ID = CREATED_REQUESTER_DTO_ID
				       		}
				       	};
				       });

			Transport.On<CreateMessageCommand>()
				.Reply(x =>
				       {
				       	var message = new MessageDTO
				       	{
				       		Subject = x.Dto.Subject,
				       		FromID = x.Dto.FromID,
				       		Body = x.Dto.Body,
				       		ID = CREATED_MESSAGE_DTO_ID
				       	};
				       	_createdMessageDtos.Add(message);
				       	return new MessageCreatedMessage {Dto = message};
				       });

			Transport.On<CreateCommand>(x => x.Dto is CommentDTO).Reply(x => GetCommentCreatedMessage(x));

			Transport.On<CreateCommand>(x => x.Dto is AttachmentDTO)
				.Reply(message => new AttachmentCreatedMessage
				{
					Dto =
						new AttachmentDTO {ID = 11, OriginalFileName = ((AttachmentDTO) message.Dto).OriginalFileName}
				});

			GetCommentCreatedMessage = GetCommentCreateCommandSuccessfulMessage;
		}
		public bool IsMatched(EmailMessage email)
		{
			if (string.IsNullOrEmpty(email.Subject))
			{
				return _keys.Any(x => string.IsNullOrEmpty(x.Trim()));
			}

			return _keys.Any(x => email.Subject.IndexOf(x.Trim(), StringComparison.InvariantCultureIgnoreCase) >= 0);
		}
		public bool IsMatched(EmailMessage email)
		{
			var project =
				_storage.Get<ProjectDTO>().FirstOrDefault(x => x.ProjectID == _projectId && x.DeleteDate == null);
			if (project == null || project.CompanyID == null)
			{
				return false;
			}

			var user = _userRepository.GetByEmail(email.FromAddress).FirstOrDefault(
				x => x.UserType == UserType.Requester);
			if (user == null || user.CompanyId == null)
			{
				return false;
			}

			return project.CompanyID == user.CompanyId;
		}
		public bool IsMatched(EmailMessage emailMessage)
		{
			return _whenClauses.All(whenClause => whenClause.IsMatched(emailMessage));
		}
		public virtual bool IsMatched(EmailMessage message)
		{
			var projects = _storage.Get<ProjectDTO>();
			return projects.Any(x => x.ProjectID == _projectId && x.DeleteDate == null);
		}
		public bool IsMatched(EmailMessage message)
		{
			return _clauses.Any(x => x.IsMatched(message));
		}
		public bool IsMatched(EmailMessage message)
		{
			return _whenClause.IsMatched(message) && _thenClause.IsMatched(message);
		}
        public void ReceiveSeveralMessages(int messageCount)
        {
            for (var i = 0; i < messageCount; i++)
            {
                var message = new EmailMessage
                              	{
                              		FromDisplayName = Context.EmailMessage.FromDisplayName,
                              		SendDate = DateTime.Now.AddDays(-1),
                              		FromAddress = Context.EmailMessage.FromAddress,
                              		Subject = Context.EmailMessage.Subject,
                              		MessageUidDto = new MessageUidDTO {UID = new Random().Next().ToString()}
                              	};

                Context.Transport.HandleLocalMessage(Context.Storage, new EmailReceivedMessage {Mail = message});
            }
        }