Exemplo n.º 1
0
        public void Setup_OkState()
        {
            _projectValidatorMock = new Mock <IProjectValidator>();
            _tagValidatorMock     = new Mock <ITagValidator>();
            _tagValidatorMock.Setup(r => r.ExistsAsync(TagId, default)).Returns(Task.FromResult(true));
            _tagValidatorMock.Setup(r => r.IsReadyToBeDuplicatedAsync(TagId, default)).Returns(Task.FromResult(true));

            _command = new DuplicateAreaTagCommand(TagId, TagType.SiteArea, "D", "A", "-01", "Desc", "Rem", "SA");

            _dut = new DuplicateAreaTagCommandValidator(_tagValidatorMock.Object, _projectValidatorMock.Object);
        }
        public async Task <ActionResult <int> > DuplicateAreaTag(
            [FromHeader(Name = CurrentPlantMiddleware.PlantHeader)]
            [Required]
            [StringLength(PlantEntityBase.PlantLengthMax, MinimumLength = PlantEntityBase.PlantLengthMin)]
            string plant,
            [FromBody] DuplicateAreaTagDto dto)
        {
            var command = new DuplicateAreaTagCommand(
                dto.SourceTagId,
                dto.AreaTagType.ConvertToTagType(),
                dto.DisciplineCode,
                dto.AreaCode,
                dto.TagNoSuffix,
                dto.Description,
                dto.Remark,
                dto.StorageArea);

            var result = await _mediator.Send(command);

            return(this.FromResult(result));
        }
        public void Setup()
        {
            var stepMock = new Mock <Step>();

            stepMock.SetupGet(s => s.Plant).Returns(TestPlant);
            stepMock.SetupGet(s => s.Id).Returns(_stepId);

            _journeyRepositoryMock = new Mock <IJourneyRepository>();
            _journeyRepositoryMock
            .Setup(x => x.GetStepByStepIdAsync(_stepId))
            .Returns(Task.FromResult(stepMock.Object));

            _rd1Mock = new Mock <RequirementDefinition>();
            _rd1Mock.SetupGet(rd => rd.Id).Returns(_rdId1);
            _rd1Mock.SetupGet(rd => rd.Plant).Returns(TestPlant);
            _rd2Mock = new Mock <RequirementDefinition>();
            _rd2Mock.SetupGet(rd => rd.Id).Returns(_rdId2);
            _rd2Mock.SetupGet(rd => rd.Plant).Returns(TestPlant);

            _rtRepositoryMock = new Mock <IRequirementTypeRepository>();
            _rtRepositoryMock
            .Setup(r => r.GetRequirementDefinitionsByIdsAsync(new List <int> {
                _rdId1, _rdId2
            }))
            .Returns(Task.FromResult(new List <RequirementDefinition> {
                _rd1Mock.Object, _rd2Mock.Object
            }));

            _req1 = new TagRequirement(TestPlant, _interval1, _rd1Mock.Object);
            _req2 = new TagRequirement(TestPlant, _interval2, _rd2Mock.Object);

            _project   = new Project(TestPlant, "TestProjectName", "");
            _sourceTag = new Tag(
                TestPlant,
                TagType.SiteArea,
                "TagNo",
                "Desc",
                stepMock.Object,
                new List <TagRequirement> {
                _req1, _req2
            });
            _sourceTag.SetArea("AC", "AD");
            _sourceTag.SetDiscipline("DC", "DD");

            _sourceTag.SetProtectedIdForTesting(_sourceTagId);
            _project.AddTag(_sourceTag);

            _projectRepoMock = new Mock <IProjectRepository>();
            _projectRepoMock.Setup(r => r.GetTagByTagIdAsync(_sourceTagId)).Returns(Task.FromResult(_sourceTag));
            _projectRepoMock
            .Setup(r => r.GetProjectOnlyByTagIdAsync(_sourceTagId)).Returns(Task.FromResult(_project));

            var disciplineCode = "D";

            _disciplineApiServiceMock = new Mock <IDisciplineApiService>();
            _disciplineApiServiceMock.Setup(s => s.TryGetDisciplineAsync(TestPlant, disciplineCode))
            .Returns(Task.FromResult(new PCSDiscipline
            {
                Code        = disciplineCode,
                Description = _disciplineDescription
            }));

            var areaCode = "A";

            _areaApiServiceMock = new Mock <IAreaApiService>();
            _areaApiServiceMock.Setup(s => s.TryGetAreaAsync(TestPlant, areaCode))
            .Returns(Task.FromResult(new PCSArea
            {
                Code        = areaCode,
                Description = _areaDescription
            }));

            _command = new DuplicateAreaTagCommand(_sourceTagId, TagType.SiteArea, disciplineCode, areaCode, "-01", "Desc", "Rem", "SA");

            _dut = new DuplicateAreaTagCommandHandler(
                _projectRepoMock.Object,
                _journeyRepositoryMock.Object,
                _rtRepositoryMock.Object,
                UnitOfWorkMock.Object,
                PlantProviderMock.Object,
                _disciplineApiServiceMock.Object,
                _areaApiServiceMock.Object);
        }