public UserAccountModule(IDispatcherFactory dispatcherFactory, IPasswordEncryptor passwordEncryptor)
        {
            Post["/register"] =
                _ =>
                    {
                        var req = this.Bind<NewUserRequest>();
                        var command = new CreateUser(req.Email, passwordEncryptor.Encrypt(req.Password), req.Name, req.PhoneNumber);
                        dispatcherFactory.Create(this.UserSession(), command)
                            .Dispatch(this.UserSession(), command);
                        return null;
                    };

            Post["/password/requestReset"] =
                _ =>
                {
                    var req = this.Bind<ResetPasswordRequest>();
                    var command = new CreatePasswordResetToken(req.Email);
                    dispatcherFactory.Create(this.UserSession(), command)
                        .Dispatch(this.UserSession(),
                                               command );
                    return null;
                };

            Put["/password/reset/{token}"] =
                p =>
                {
                    var newPasswordRequest = this.Bind<NewPasswordRequest>();
                    var token = Guid.Parse((string)p.token);
                    var command = new ResetPassword(token, passwordEncryptor.Encrypt(newPasswordRequest.Password));
                    dispatcherFactory.Create(this.UserSession(), command)
                        .Dispatch(this.UserSession(), command);
                    return null;
                };
        }
        public CollaboratorModule(IDispatcherFactory dispatcherFactory, IProjectRepository projectRepository)
        {
            Post["/projects/{projectId}/collaborators"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var request = this.Bind<AddCollaboratorRequest>();
                    var command = new AddCollaborator(projectId, request.UserId, request.Level);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Get["/projects/{projectId}/collaborators"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Project project = projectRepository.GetById(projectId);
                    IEnumerable<CollaboratorResponse> collaboratorResponses =
                        project.Collaborators.Select(x => new CollaboratorResponse
                                                          {
                                                              UserId = x.UserId,
                                                              Name=x.UserName,
                                                              Level = x.Level.ToString()
                                                          }).ToList();
                    return new CollaboratorListResponse(collaboratorResponses);
                };

            Delete["/projects/{projectId}/collaborators/{userId}"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Guid userId = Guid.Parse((string) p.userId);
                    var command = new RemoveCollaborator(projectId, userId);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };
        }
		public void setup()
		{
			_messagingBase = Substitute.For<IMessagingBase>();
			_sleeper = Substitute.For<ISleepWrapper>();
			_dispatcher = Substitute.For<IDispatch<byte[]>>();
			_dispatcherFactory = Substitute.For<IDispatcherFactory>();
			_dispatcherFactory.Create(Arg.Any<IWorkQueue<byte[]>>(), Arg.Any<IWorkerPool<byte[]>>()).Returns(_dispatcher);

			_queueFactory = Substitute.For<IOutgoingQueueFactory>();

			_eventHook1 = Substitute.For<IEventHook>();
			_eventHook2 = Substitute.For<IEventHook>();
			ObjectFactory.Configure(map => {
				map.For<IEventHook>().Use(_eventHook1);
				map.For<IEventHook>().Use(_eventHook2);
			});

			_subject = new SenderNode(_messagingBase, _dispatcherFactory, _sleeper,_queueFactory);
		}
Exemple #4
0
        public StoryModule(IMappingEngine mappingEngine, IDispatcherFactory dispatcherFactory,
            IReadOnlyRepository readOnlyRepository)
        {
            Delete["{projectId}/stories/{storyId}"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Guid storyId = Guid.Parse((string) p.storyId);
                    var command = new DeleteStory(storyId, projectId);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/stories/{id}/run"] =
                p =>
                {
                    Guid id = Guid.Parse((string) p.id);
                    Guid projectId = Guid.Parse((string) p.projectId);

                    var command = new QueueStory(projectId, id);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Get["{projectId}/stories/{id}"] =
                p =>
                {
                    Guid storyId = Guid.Parse((string) p.id);
                    var story = readOnlyRepository.GetById<Story>(storyId);
                    StoryDetailResponse storyDetailResponse = mappingEngine.Map<Story, StoryDetailResponse>(story);
                    return storyDetailResponse;
                };

            Get["/projects/{projectId}/stories"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var project = readOnlyRepository.GetById<Project>(projectId);
                    IEnumerable<StoryListingResponse> storyListingResponses =
                        mappingEngine.Map<IEnumerable<Story>, IEnumerable<StoryListingResponse>>(project.Stories);
                    return new StoryListResponse(storyListingResponses.ToList());
                };


            Post["/projects/{projectId}/stories"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var projectData = this.Bind<NewStoryRequest>();
                    var command = new CreateNewStory(projectId, Guid.NewGuid(), projectData.Name);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["/projects/{projectId}/stories/{storyId}"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Guid storyId = Guid.Parse((string) p.storyId);
                    var projectData = this.Bind<ChangeNameRequest>();
                    var command = new ChangeStoryName(projectId, storyId, projectData.Name);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(),
                            command);
                    return null;
                };
        }
Exemple #5
0
        void BrowserSteps(IDispatcherFactory dispatcherFactory)
        {
            Put["{projectId}/steps/{stepId}/PressKeyStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdatePressKeyStepRequest>();
                    var command = new ChangePressKeyStep(projectId, stepId, data.Element, data.KeyCode);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/PressKeyStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdatePressKeyStepRequest>();
                    var command = new CreatePressKeyStep(projectId, criteriaId, data.Element, data.KeyCode);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/NavigateStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateNavigateStepRequest>();
                    var command = new ChangeNavigateStep(projectId, stepId, data.Url);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/NavigateStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateNavigateStepRequest>();
                    var command = new CreateNewNavigateStep(projectId, criteriaId, data.Url);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/EnterTextStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateEnterTextStepRequest>();
                    var command = new ChangeEnterTextStep(projectId, stepId, data.Element, data.Text);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/EnterTextStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateEnterTextStepRequest>();
                    var command = new CreateNewEnterTextStep(projectId, criteriaId, data.Element, data.Text);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/SelectOptionStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateSelectOptionStepRequest>();
                    var command = new ChangeSelectOptionStep(projectId, stepId, data.Element, data.Text, data.Value);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/SelectOptionStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateSelectOptionStepRequest>();
                    var command = new CreateNewSelectOptionStep(projectId, criteriaId, data.Element, data.Text,
                        data.Value);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/ClickStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateClickStepRequest>();
                    var command = new ChangeClickStep(projectId, stepId, data.Element);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ClickStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateClickStepRequest>();
                    var command = new CreateNewClickStep(projectId, criteriaId, data.Element);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/WaitSecondsStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateWaitStepRequest>();
                    var command = new ChangeWaitStep(projectId, stepId, data.Seconds);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };


            Post["{projectId}/criteria/{criteriaId}/WaitSecondsStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateWaitStepRequest>();
                    var command = new CreateNewWaitStep(projectId, criteriaId, data.Seconds);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/WaitForElementStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateWaitForElementStepRequest>();
                    var command = new ChangeWaitForElementStep(projectId, stepId, data.Element, data.Seconds);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/WaitForElementStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateWaitForElementStepRequest>();
                    var command = new CreateNewWaitForElementStep(projectId, criteriaId, data.Element, data.Seconds);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/ElementDoesNotExistStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateElementExistsStepRequest>();
                    var command = new ChangeElementDoesNotExistStep(projectId, stepId, data.Element);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ElementDoesNotExistStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateElementExistsStepRequest>();
                    var command = new CreateNewElementDoesNotExistStep(projectId, criteriaId, data.Element);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/ElementExistsStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateElementExistsStepRequest>();
                    var command = new ChangeElementExistsStep(projectId, stepId, data.Element);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ElementExistsStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateElementExistsStepRequest>();
                    var command = new CreateNewElementExistsStep(projectId, criteriaId, data.Element);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/ElementContainsTextStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateTextContainsStepRequest>();
                    var command = new ChangeTextContainsStep(projectId, stepId, data.Element, data.Text);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ElementContainsTextStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateTextContainsStepRequest>();
                    var command = new CreateNewTextContainsStep(projectId, criteriaId, data.Element, data.Text);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/ElementHasClassStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateElementHasCssClassStepRequest>();
                    var command = new ChangeElementHasClassStep(projectId, stepId, data.element, data.className);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ElementHasClassStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateElementHasCssClassStepRequest>();
                    var command = new CreateNewElementHasClassStep(projectId,
                        criteriaId, data.element, data.className);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/ElementHasStyleStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateElementHasStyleStepRequest>();
                    var command = new ChangeElementHasStyleStep(projectId, stepId, data.Element, data.StyleKey,
                        data.StyleValue);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ElementHasStyleStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateElementHasStyleStepRequest>();
                    var command = new CreateNewElementHasStyleStep(projectId,
                        criteriaId, data.Element, data.StyleKey, data.StyleValue);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };
        }
Exemple #6
0
        public StepModule(IDispatcherFactory dispatcherFactory, IMappingEngine mappingEngine,
            IProjectRepository projectRepository)
        {
            Post["/scenarios/{scenarioId}/criteria/{criterionId}/steps/{stepId}/started"] =
                p =>
                {
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    Guid criterionId = Guid.Parse((string) p.criterionId);
                    Guid stepId = Guid.Parse((string) p.stepId);

                    var request = this.Bind<TestStartRequest>();

                    var command = new StartStep(scenarioId, criterionId, stepId, request.Time);
                    dispatcherFactory.Create(this.UserSession(), command)
                        .Dispatch(this.UserSession(),
                            command);
                    return null;
                };

            Post["/scenarios/{scenarioId}/criteria/{criterionId}/steps/{stepId}/stopped"] =
                p =>
                {
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    Guid criterionId = Guid.Parse((string) p.criterionId);
                    Guid stepId = Guid.Parse((string) p.stepId);

                    var testResultData = this.Bind<TestResultData>();

                    var command = new StopStep(scenarioId, criterionId, stepId, testResultData.Passing,
                        testResultData.Duration, testResultData.Time, testResultData.Message,
                        testResultData.Screenshot);
                    dispatcherFactory.Create(this.UserSession(), command)
                        .Dispatch(this.UserSession(),
                            command);

                    return null;
                };

            Delete["{projectId}/steps/{id}"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var command = new DeleteStep(projectId, Guid.Parse((string) p.id));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(),
                            command);
                    return null;
                };

            Get["{projectId}/scenarios/{scenarioId}/steps/{stepId}"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Project project = projectRepository.GetById(projectId);
                    Scenario scenario = project.Stories.SelectMany(x => x.Scenarios)
                        .First(x => x.Id == scenarioId);

                    Step step = scenario
                        .GetLinkedCriteria()
                        .SelectMany(x => x.Criterion.GetSteps())
                        .FirstOrDefault(x => x.Id == stepId);

                    if (step == null) throw new ItemNotFoundException<Step>(stepId);

                    StepDetailResponse stepDetailResponse = mappingEngine.Map<Step, StepDetailResponse>(step);

                    List<LinkedStep> stepRunResults =
                        scenario.GetLinkedCriteria().SelectMany(x => x.GetLinkedSteps()).Where(x => x.Step.Id == stepId)
                            .ToList();

                    stepDetailResponse.Results = stepRunResults.Select(x => new StepResultResponse
                                                                            {
                                                                                Details = x.LastResult().GetDetails(),
                                                                                Duration = x.LastResult().Duration,
                                                                                Message = x.LastResult().GetMessage(),
                                                                                ScreenShotUrl =
                                                                                    x.LastResult().ScreenShotUrl,
                                                                                Time =
                                                                                    x.LastResult().Time.HasValue
                                                                                        ? x.LastResult().Time.Value
                                                                                        : DateTime.MinValue
                                                                            }).ToList();

                    LinkedCriterion linkedCriterion =
                        scenario.GetLinkedCriteria().First(x => x.Criterion.GetSteps().Any(s => s.Id == stepId));
                    LinkedStep linkedStep = linkedCriterion.GetLinkedSteps().First(x => x.Step.Id == stepId);
                    stepDetailResponse.LastRun = linkedStep.LastRun();
                    stepDetailResponse.ScreenShotUrl = linkedStep.GetLastScreenshot();
                    stepDetailResponse.Result = linkedStep.GetTestStatus().ToString();

                    return stepDetailResponse;
                };

            Put["{projectId}/criteria/{criteriaId}/steps/order"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    var orderChangeRequests = this.Bind<List<StepPriorityChangeRequest>>();
                    var command = new ChangeStepOrder(projectId, criteriaId,
                        orderChangeRequests.Select(x => new StepOrderChange(x.StepId, x.Priority)));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(),
                            command);
                    return null;
                };

            BrowserSteps(dispatcherFactory);

            ApiSteps(dispatcherFactory);
        }
Exemple #7
0
        void ApiSteps(IDispatcherFactory dispatcherFactory)
        {
            Put["{projectId}/steps/{stepId}/ApiDeleteStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStep>();
                    var command = new ChangeApiDeleteStep(projectId,
                        stepId, data.host, data.resource, data.payloadKey, RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ApiDeleteStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStep>();
                    var command = new CreateNewApiDeleteStep(projectId,
                        criteriaId, data.host, data.resource, data.payloadKey, RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/ApiGetStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStep>();
                    var command = new ChangeApiGetStep(projectId,
                        stepId, data.host, data.resource, data.payloadKey, RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ApiGetStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStep>();
                    var command = new CreateNewApiGetStep(projectId,
                        criteriaId, data.host, data.resource, data.payloadKey, RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/ApiOptionsStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStep>();
                    var command = new ChangeApiOptionsStep(projectId,
                        stepId, data.host, data.resource, data.payloadKey, RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ApiOptionsStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStep>();
                    var command = new CreateNewApiOptionsStep(projectId,
                        criteriaId, data.host, data.resource, data.payloadKey, RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/ApiPostStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStepWithPayload>();
                    var command = new ChangeApiPostStep(projectId,
                        stepId, data.host, data.resource, data.payloadKey, DeserializePayload(data.payload),
                        RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ApiPostStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStepWithPayload>();
                    var command = new CreateNewApiPostStep(projectId,
                        criteriaId, data.host, data.resource, data.payloadKey, DeserializePayload(data.payload),
                        RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/ApiPutStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStepWithPayload>();
                    var command = new ChangeApiPutStep(projectId,
                        stepId, data.host, data.resource, data.payloadKey, DeserializePayload(data.payload),
                        RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ApiPutStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStepWithPayload>();
                    var command = new CreateNewApiPutStep(projectId,
                        criteriaId, data.host, data.resource, data.payloadKey, DeserializePayload(data.payload),
                        RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/ApiPatchStep"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStepWithPayload>();
                    var command = new ChangeApiPatchStep(projectId,
                        stepId, data.host, data.resource, data.payloadKey, DeserializePayload(data.payload),
                        RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/ApiPatchStep"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateApiStepWithPayload>();
                    var command = new CreateNewApiPatchStep(projectId,
                        criteriaId, data.host, data.resource, data.payloadKey, DeserializePayload(data.payload),
                        RequestOptions(data));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["{projectId}/steps/{stepId}/JavascriptAssert"] =
                p =>
                {
                    Guid stepId = Guid.Parse((string) p.stepId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateJavascriptAssertRequest>();
                    var command = new ChangeJavascriptAssert(projectId, stepId, data.javascriptExpression);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/criteria/{criteriaId}/JavascriptAssert"] =
                p =>
                {
                    Guid criteriaId = Guid.Parse((string) p.criteriaId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<CreateOrUpdateJavascriptAssertRequest>();
                    var command = new CreateNewJavascriptAssert(projectId,
                        criteriaId, data.javascriptExpression);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };
        }
Exemple #8
0
        public ProjectModule(IDispatcherFactory dispatcherFactory,
            IProjectRepository projectRepository, IMappingEngine mappingEngine)
        {
            Post["/projects/{id}/run"] =
                p =>
                {
                    Guid id = Guid.Parse((string) p.id);
                    var command = new QueueProject(id);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Get["/projects"] =
                _ =>
                {
                    User user = this.UserLoginSession().User;
                    IEnumerable<Project> projects = projectRepository.GetForUser(user);
                    IEnumerable<ProjectListingResponse> projectListingResponses =
                        mappingEngine.Map<IEnumerable<Project>, IEnumerable<ProjectListingResponse>>(projects);
                    return new ProjectListResponse(projectListingResponses);
                };

            Get["/projects/{projectId}"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Guid userId = this.UserLoginSession().User.Id;
                    Project project = projectRepository.GetById(projectId);
                    ProjectDetailsResponse response = mappingEngine.Map<Project, ProjectDetailsResponse>(project);
                    if (response == null) throw new ItemNotFoundException<Project>(projectId);
                    return response;
                };

            Get["/projects/{id}/backup"] =
                p =>
                {
                    throw new NotImplementedException();
                    //Guid id = Guid.Parse((string) p.id);
                    //Project project = projectRepository.GetById(id);

                    //if (project.Collaborators.All(x => x.UserId != this.UserLoginSession().User.Id))
                    //{
                    //    throw new UnauthorizedAccessException("That's not your project!");
                    //}

                    //if (project == null) throw new ItemNotFoundException<Project>(id);

                    //var projectBackupResponse = new ProjectBackupResponse
                    //                            {
                    //                                Name = project.Name,
                    //                                Id = project.Id,
                    //                                History = GetFilteredEventd(project)
                    //                            };
                    //return projectBackupResponse;
                };

            Post["/projects/restore"] =
                p =>
                {
                    throw new NotImplementedException();
                    //string body = Request.Body.AsString();
                    //var projectBackupResponse = JsonConvert.DeserializeObject<ProjectBackupResponse>(body,
                    //    new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.Objects});

                    //var command = new RestoreProject(projectBackupResponse.History);
                    //dispatcherFactory.Create(this.UserLoginSession(), command)
                    //    .Dispatch(this.UserLoginSession(), command);
                    //return null;
                };

            Post["/projects"] =
                _ =>
                {
                    var projectData = this.Bind<NewProjectRequest>();
                    var command = new CreateNewProject(Guid.NewGuid(), projectData.Name);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["/projects/{projectId}"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var projectData = this.Bind<ChangeNameRequest>();
                    var command = new ChangeProjectName(projectId, projectData.Name);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Delete["/projects/{id}"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.id);
                    var command = new DeleteProject(projectId);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };
        }
        public ScenarioModule(IMappingEngine mappingEngine, IDispatcherFactory dispatcherFactory,
            IReadOnlyRepository readOnlyRepository)
        {
            Post["/scenarios/{scenarioId}/failed"] =
                p =>
                {
                    Guid scenarioId = Guid.Parse((string)p.scenarioId);
                    var input = this.Bind<ScenarioFailureInput>();
                    var command = new FailScenario(scenarioId, input.Message, input.Time);
                    dispatcherFactory.Create(this.UserSession(), command)
                        .Dispatch(this.UserSession(), command);
                    return null;
                };

            Delete["{projectId}/scenarios/{id}"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var command = new DeleteScenario(projectId, Guid.Parse((string) p.id));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Get["{projectId}/scenarios/{id}"] =
                p =>
                {
                    Guid scenarioId = Guid.Parse((string) p.id);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var scenario = readOnlyRepository.GetById<Scenario>(scenarioId);
                    ScenarioDetailResponse response = mappingEngine.Map<Scenario, ScenarioDetailResponse>(scenario);
                    return response;
                };

            Get["{projectId}/stories/{storyId}/scenarios"] =
                p =>
                {
                    Guid storyId = Guid.Parse((string) p.storyId);
                    var story = readOnlyRepository.GetById<Story>(storyId);
                    IEnumerable<ScenarioListingResponse> scenarioListResponses =
                        mappingEngine.Map<IEnumerable<Scenario>, IEnumerable<ScenarioListingResponse>>(story.Scenarios);
                    return new ScenarioListResponse(scenarioListResponses.ToList());
                };

            Post["{projectId}/scenarios/{id}/run"] =
                p =>
                {
                    Guid id = Guid.Parse((string) p.id);
                    Guid projectId = Guid.Parse((string) p.projectId);

                    var command = new QueueScenario(projectId, id);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/stories/{storyId}/scenarios"] =
                p =>
                {
                    Guid storyId = Guid.Parse((string) p.storyId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<NewScenarioRequest>();
                    var command = new CreateNewScenario(projectId, storyId, Guid.NewGuid(), data.Name);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Put["/projects/{projectId}/scenarios/{scenarioId}"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    var projectData = this.Bind<ChangeNameRequest>();
                    var command = new ChangeScenarioName(projectId, scenarioId, projectData.Name);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };
        }
Exemple #10
0
        public CriteriaModule(IMappingEngine mappingEngine, IDispatcherFactory dispatcherFactory,
            IReadOnlyRepository readOnlyRepository,
            IProjectRepository projectRepository)
        {
            Put["{projectId}/scenarios/{scenarioId}/criteria/order"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    var orderChangeRequests = this.Bind<List<CriterionPriorityChangeRequest>>();
                    var command = new ChangeCriterionOrder(projectId, scenarioId,
                        orderChangeRequests.Select(x => new CriterionOrderChange(x.CriterionId, x.Priority)));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Delete["{projectId}/scenario/{scenarioId}/criteria/{id}"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    var command = new RemoveCriterionFromScenario(projectId, scenarioId, Guid.Parse((string) p.id));
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Get["{projectId}/scenarios/{scenarioId}/criteria"] =
                p =>
                {
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    var scenario = readOnlyRepository.GetById<Scenario>(scenarioId);
                    IEnumerable<CriteriaListingResponse> criteriaListingResponses = mappingEngine
                        .Map<IEnumerable<LinkedCriterion>, IEnumerable<CriteriaListingResponse>>(
                            scenario.GetLinkedCriteria());
                    return new CriteriaListResponse(criteriaListingResponses.ToList());
                };

            Get["{projectId}/scenarios/{scenarioId}/criteria/{criterionId}"] =
                p =>
                {
                    Guid criterionId = Guid.Parse((string) p.criterionId);
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Project project = projectRepository.GetById(projectId);
                    LinkedCriterion linkedCriterion = project.Stories
                        .SelectMany(x => x.Scenarios)
                        .First(x => x.Id == scenarioId).GetLinkedCriteria()
                        .FirstOrDefault(x => x.Criterion.Id == criterionId);

                    if (linkedCriterion == null) throw new ItemNotFoundException<Criterion>(criterionId);

                    CriterionDetailsResponse criterionDetailsResponse =
                        mappingEngine.Map<LinkedCriterion, CriterionDetailsResponse>(linkedCriterion);

                    criterionDetailsResponse.Steps =
                        linkedCriterion.Criterion.GetSteps()
                            .Select(step =>
                                    {
                                        LinkedStep linkedStep =
                                            linkedCriterion.GetLinkedSteps().First(x => x.Step.Id == step.Id);
                                        return new StepListingResponse
                                               {
                                                   StepId = step.Id,
                                                   CriterionId = step.Criterion.Id,
                                                   Priority = step.Priority,
                                                   RunsIn = step.Criterion.RunsIn.ToString(),
                                                   ScreenShotUrl = linkedStep.GetLastScreenshot(),
                                                   Description = step.GetDescription(),
                                                   LastRun = linkedStep.LastRun(),
                                                   Result = linkedStep.GetTestStatus().ToString()
                                               };
                                    }).ToList();

                    return criterionDetailsResponse;
                };

            Get["{projectId}/criteria"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Project project = projectRepository.GetById(projectId);
                    IEnumerable<LinkedCriterion> criteria =
                        project.Stories.SelectMany(x => x.Scenarios).SelectMany(x => x.GetLinkedCriteria())
                            .Distinct(new LinkedCriterionComparer());

                    return
                        new CriteriaListResponse(
                            mappingEngine.Map<IEnumerable<LinkedCriterion>, IEnumerable<CriteriaListingResponse>>(
                                criteria));
                };

            Put["/projects/{projectId}/criteria/{criterionId}"] =
                p =>
                {
                    Guid projectId = Guid.Parse((string) p.projectId);
                    Guid criterionId = Guid.Parse((string) p.criterionId);
                    var projectData = this.Bind<ChangeNameRequest>();
                    var command = new ChangeCriterionName(projectId, criterionId, projectData.Name);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/scenarios/{scenarioId}/link/{criterionId}/{type}"] =
                p =>
                {
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    Guid criterionId = Guid.Parse((string) p.criterionId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    CriterionType type;
                    Enum.TryParse((string) p.type, true, out type);
                    var command = new LinkCriterionToScenario(projectId, scenarioId, criterionId, type);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/scenarios/{scenarioId}/given"] =
                p =>
                {
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<NewCriteriaRequest>();
                    var command = new CreateNewGiven(projectId, scenarioId, Guid.NewGuid(), data.Name, data.RunsIn);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/scenarios/{scenarioId}/when"] =
                p =>
                {
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<NewCriteriaRequest>();
                    var command = new CreateNewWhen(projectId, scenarioId, Guid.NewGuid(), data.Name, data.RunsIn);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };

            Post["{projectId}/scenarios/{scenarioId}/then"] =
                p =>
                {
                    Guid scenarioId = Guid.Parse((string) p.scenarioId);
                    Guid projectId = Guid.Parse((string) p.projectId);
                    var data = this.Bind<NewCriteriaRequest>();
                    var command = new CreateNewThen(projectId, scenarioId, Guid.NewGuid(), data.Name, data.RunsIn);
                    dispatcherFactory.Create(this.UserLoginSession(), command)
                        .Dispatch(this.UserLoginSession(), command);
                    return null;
                };
        }