Ejemplo n.º 1
0
        public void Constructor_ShouldSetProperties()
        {
            var dut = new CreateStepCommand(1, "S", 2, "B", AutoTransferMethod.OnRfccSign);

            Assert.AreEqual(1, dut.JourneyId);
            Assert.AreEqual(2, dut.ModeId);
            Assert.AreEqual("S", dut.Title);
            Assert.AreEqual("B", dut.ResponsibleCode);
            Assert.AreEqual(AutoTransferMethod.OnRfccSign, dut.AutoTransferMethod);
        }
Ejemplo n.º 2
0
        public void Setup_OkState()
        {
            _journeyValidatorMock = new Mock <IJourneyValidator>();
            _journeyValidatorMock.Setup(r => r.ExistsAsync(_journeyId, default)).Returns(Task.FromResult(true));
            _modeValidatorMock = new Mock <IModeValidator>();
            _modeValidatorMock.Setup(r => r.ExistsAsync(_modeId, default)).Returns(Task.FromResult(true));
            _responsibleValidatorMock = new Mock <IResponsibleValidator>();
            _command = new CreateStepCommand(_journeyId, _stepTitle, _modeId, _responsibleCode, AutoTransferMethod.None);

            _dut = new CreateStepCommandValidator(_journeyValidatorMock.Object, _modeValidatorMock.Object, _responsibleValidatorMock.Object);
        }
Ejemplo n.º 3
0
        public void Validate_ShouldBeValid_WhenSettingNoneAutoTransferMethod_AndAExistingStepHasNone()
        {
            var autoTransferMethod = AutoTransferMethod.None;

            _journeyValidatorMock.Setup(r => r.HasAnyStepWithAutoTransferMethodAsync(_journeyId, autoTransferMethod, default)).Returns(Task.FromResult(true));

            _command = new CreateStepCommand(_journeyId, _stepTitle, _modeId, _responsibleCode, autoTransferMethod);
            var result = _dut.Validate(_command);

            Assert.IsTrue(result.IsValid);
        }
Ejemplo n.º 4
0
        public void Validate_ShouldFail_WhenSettingSameAutoTransferMethod_AsAExistingStep()
        {
            var autoTransferMethod = AutoTransferMethod.OnRfccSign;

            _journeyValidatorMock.Setup(r => r.HasAnyStepWithAutoTransferMethodAsync(_journeyId, autoTransferMethod, default)).Returns(Task.FromResult(true));

            _command = new CreateStepCommand(_journeyId, _stepTitle, _modeId, _responsibleCode, autoTransferMethod);
            var result = _dut.Validate(_command);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.IsTrue(result.Errors[0].ErrorMessage.StartsWith("Same auto transfer method can not be set on multiple steps in a journey!"));
        }
        public async Task <ActionResult <Step> > AddStep([FromBody] CreateStepCommand createStepCommand)
        {
            try
            {
                var result = await Mediator.Send(createStepCommand);

                return(Ok(result.Step));
            }
            catch (UnauthorizedException e)
            {
                return(StatusCode(401, e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 6
0
        public async Task AddStepSuccessful()
        {
            var name = "test step";

            var request = new CreateStepCommand()
            {
                Name      = name,
                ProjectId = Utilities.Project1.Id
            };

            var response = await Client.PostAsync("/api/Step", Utilities.GetRequestContent(request));

            response.EnsureSuccessStatusCode();

            var responseContent = await Utilities.GetResponseContent <StepDto>(response);

            responseContent.Name.Should().Be(name);
            responseContent.Id.Should().BeGreaterThan(0);
        }
        public void Setup()
        {
            // Arrange
            _journeyRepositoryMock = new Mock <IJourneyRepository>();
            _journey = new Journey(TestPlant, "J");
            _journeyRepositoryMock
            .Setup(r => r.GetByIdAsync(JourneyId))
            .Returns(Task.FromResult(_journey));

            _modeRepositoryMock = new Mock <IModeRepository>();
            _modeMock           = new Mock <Mode>();
            _modeMock.SetupGet(m => m.Plant).Returns(TestPlant);
            _modeMock.SetupGet(x => x.Id).Returns(ModeId);
            _modeRepositoryMock
            .Setup(r => r.GetByIdAsync(ModeId))
            .Returns(Task.FromResult(_modeMock.Object));

            _responsibleRepositoryMock = new Mock <IResponsibleRepository>();
            _responsible = new Responsible(TestPlant, ResponsibleCode, "T");
            _responsible.SetProtectedIdForTesting(ResponsibleId);
            _responsibleRepositoryMock
            .Setup(r => r.GetByCodeAsync(ResponsibleCode))
            .Returns(Task.FromResult(_responsible));
            _responsibleRepositoryMock.Setup(r => r.Add(It.IsAny <Responsible>()))
            .Callback <Responsible>(c => _addedResponsible = c);

            _pcsResponsibleMock = new Mock <PCSResponsible>();

            _responsibleApiServiceMock = new Mock <IResponsibleApiService>();
            _responsibleApiServiceMock.Setup(r => r.TryGetResponsibleAsync(TestPlant, ResponsibleCode))
            .Returns(Task.FromResult(_pcsResponsibleMock.Object));

            _command = new CreateStepCommand(JourneyId, _title, ModeId, ResponsibleCode, _autoTransferMethod);

            _dut = new CreateStepCommandHandler(_journeyRepositoryMock.Object,
                                                _modeRepositoryMock.Object,
                                                _responsibleRepositoryMock.Object,
                                                UnitOfWorkMock.Object,
                                                PlantProviderMock.Object,
                                                _responsibleApiServiceMock.Object);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create(CreateStepCommand command, bool?wait_for_completion, string timeout = "30s")
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                command.CreatedBy = ClaimsUtility.GetId(User);
                var result = await Mediator.Send(command);

                Step step = (await Mediator.Send(new GetEntityQuery <Step>()
                {
                    Expression = s => s.Id == new Guid(result.ObjectRefId),
                    Exclude = (s) => s.Journal
                })).Result;


                if (wait_for_completion.HasValue && wait_for_completion.Value)
                {
                    var ms = DateTimeMathsUtility.GetMs(timeout);

                    while (!StepStatuses.IsCompleteStatus(step.Status) && stopwatch.ElapsedMilliseconds < ms)
                    {
                        step = (await Mediator.Send(new GetEntityQuery <Step>()
                        {
                            Expression = s => s.Id == new Guid(result.ObjectRefId)
                        })).Result;
                    }
                }


                return(Ok(new HttpCommandResult <Step>("step", result, step)));
            }
            catch (BaseException e)
            {
                Logger.LogError(e.Message);
                stopwatch.Stop();
                return(BadRequest(e.ToExceptionResult(stopwatch.ElapsedMilliseconds)));
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> CreateStep(string buildID, [FromBody] CreateStepInputModel inputModel)
        {
            if (TryValidateModel(inputModel))
            {
                try {
                    var command = _mapper.Map <CreateStepInputModel, CreateStepCommand>(inputModel, CreateStepCommand.FromBuild(buildID));
                    var id      = await _mediator.Send(command);

                    return(Ok(id));
                } catch (Exception exception) {
                    return(BadRequest(BadRequestOutputModel.FromException(exception)));
                }
            }
            return(BadRequest(ModelState));
        }
        public async Task <IActionResult> CreateStep(CreateStepCommand createStepCommand)
        {
            var stepId = await Mediator.Send(createStepCommand);

            return(CreatedAtAction(nameof(GetStepById), new { stepId }, null));
        }