public void Setup() { _field = new Field(TestPlant, "L", FieldType.Info, 1); _rd1 = new RequirementDefinition(TestPlant, "RD1", 1, RequirementUsage.ForAll, 1); _rd1.SetProtectedIdForTesting(_reqDefId); _rd1.AddField(_field); var rd2 = new RequirementDefinition(TestPlant, "RD2", 1, RequirementUsage.ForAll, 2); var rd3 = new RequirementDefinition(TestPlant, "RD3", 1, RequirementUsage.ForAll, 3); var requirementType = new RequirementType(TestPlant, "C1", "T1", _reqIconOther, 0); requirementType.AddRequirementDefinition(_rd1); requirementType.AddRequirementDefinition(rd2); requirementType.AddRequirementDefinition(rd3); _requirementTypes = new List <RequirementType> { requirementType, new RequirementType(TestPlant, "C2", "T2", _reqIconOther, 0), new RequirementType(TestPlant, "C3", "T3", _reqIconOther, 0) }; _rtSetMock = _requirementTypes.AsQueryable().BuildMockDbSet(); ContextHelper .ContextMock .Setup(x => x.RequirementTypes) .Returns(_rtSetMock.Object); var requirementDefinitions = new List <RequirementDefinition> { _rd1, rd2, rd3 }; _rdSetMock = requirementDefinitions.AsQueryable().BuildMockDbSet(); ContextHelper .ContextMock .Setup(x => x.RequirementDefinitions) .Returns(_rdSetMock.Object); var fields = new List <Field> { _field }; _fieldSetMock = fields.AsQueryable().BuildMockDbSet(); ContextHelper .ContextMock .Setup(x => x.Fields) .Returns(_fieldSetMock.Object); _dut = new RequirementTypeRepository(ContextHelper.ContextMock.Object); }
public void Setup() { // Arrange var reqTypeRepositoryMock = new Mock <IRequirementTypeRepository>(); var requirementTypeId = 1; var requirementDefinitionId = 2; var requirementType = new RequirementType(TestPlant, "TestCode", "ReqTypeTitle", _reqIconOther, 99); requirementType.SetProtectedIdForTesting(requirementTypeId); _requirementDefinition = new RequirementDefinition(TestPlant, "ReqDefinitionTitle", 4, RequirementUsage.ForAll, 88); _requirementDefinition.SetProtectedIdForTesting(requirementDefinitionId); requirementType.AddRequirementDefinition(_requirementDefinition); reqTypeRepositoryMock.Setup(m => m.GetByIdAsync(requirementTypeId)) .Returns(Task.FromResult(requirementType)); _command = new VoidRequirementDefinitionCommand(requirementTypeId, requirementDefinitionId, _rowVersion); _dut = new VoidRequirementDefinitionCommandHandler( reqTypeRepositoryMock.Object, UnitOfWorkMock.Object); }
public void Setup() { // Arrange var requirementTypeId = 1; var requirementDefinitionId = 2; _fieldId = 3; var requirementTypeRepositoryMock = new Mock <IRequirementTypeRepository>(); _requirementType = new RequirementType(TestPlant, "Req type code", "Req type title", RequirementTypeIcon.Other, 10); _requirementType.SetProtectedIdForTesting(requirementTypeId); _requirementDefinition = new RequirementDefinition(TestPlant, _oldTitle, _oldDefaultWeeks, _oldUsage, _oldSortKey); _requirementDefinition.SetProtectedIdForTesting(requirementDefinitionId); _field = new Field(TestPlant, _oldLabel, _oldFieldType, _oldSortKey, _oldUnit, _oldShowPrevious); _field.SetProtectedIdForTesting(_fieldId); _requirementDefinition.AddField(_field); _requirementType.AddRequirementDefinition(_requirementDefinition); requirementTypeRepositoryMock.Setup(j => j.GetByIdAsync(requirementTypeId)) .Returns(Task.FromResult(_requirementType)); _updateCommandWithUpdateField = new UpdateRequirementDefinitionCommand( requirementTypeId, requirementDefinitionId, _newSortKey1, _newUsage, _newTitle, _newDefaultWeeks, _rowVersion, new List <UpdateFieldsForCommand> { new UpdateFieldsForCommand(_fieldId, _newLabel1, FieldType.Number, _newSortKey1, true, _rowVersion, _newUnit1, _newShowPrevious1) }, new List <FieldsForCommand>() ); _updateCommandWithDeleteField = new UpdateRequirementDefinitionCommand( requirementTypeId, requirementDefinitionId, _newSortKey1, _newUsage, _newTitle, _newDefaultWeeks, _rowVersion, new List <UpdateFieldsForCommand>(), new List <FieldsForCommand>() ); _updateCommandWithUpdateAndAddField = new UpdateRequirementDefinitionCommand( requirementTypeId, requirementDefinitionId, _newSortKey1, _newUsage, _newTitle, _newDefaultWeeks, _rowVersion, new List <UpdateFieldsForCommand> { new UpdateFieldsForCommand(_fieldId, _newLabel1, FieldType.Number, _newSortKey1, true, _rowVersion, _newUnit1, _newShowPrevious1) }, new List <FieldsForCommand> { new FieldsForCommand(_newLabel2, _newFieldType2, _newSortKey2, _newUnit2, _newShowPrevious2) } ); _dut = new UpdateRequirementDefinitionCommandHandler( requirementTypeRepositoryMock.Object, UnitOfWorkMock.Object, PlantProviderMock.Object); }
public void Setup() { var reqDefId = 0; _modeRepository = new ModeRepository(_plantProvider, _sourceModes); _sourceModes.Add(new Mode(_sourcePlant, "ModeA", false)); _sourceModes.Add(new Mode(_sourcePlant, "ModeB", false)); _requirementTypeRepository = new RequirementTypeRepository(_plantProvider, _sourceRequirementTypes); var requirementTypeA = new RequirementType(_sourcePlant, "RequirementTypeCodeA", "RequirementTypeTitleA", _requirementIconOther, 1); var reqDefA1 = new RequirementDefinition(_sourcePlant, "RequirementDefCodeA1", 1, RequirementUsage.ForAll, 2); reqDefA1.SetProtectedIdForTesting(++reqDefId); requirementTypeA.AddRequirementDefinition(reqDefA1); var reqDefA2 = new RequirementDefinition(_sourcePlant, "RequirementDefCodeA2", 3, RequirementUsage.ForAll, 4); reqDefA2.SetProtectedIdForTesting(++reqDefId); requirementTypeA.AddRequirementDefinition(reqDefA2); reqDefA1.AddField(new Field(_sourcePlant, "LabelA", FieldType.Number, 1, "UnitA", true)); var requirementTypeB = new RequirementType(_sourcePlant, "RequirementTypeCodeB", "RequirementTypeTitleB", _requirementIconOther, 2); _sourceRequirementTypes.Add(requirementTypeA); _sourceRequirementTypes.Add(requirementTypeB); _tagFunctionRepository = new TagFunctionRepository(_plantProvider, _sourceTagFunctions); var tagFunctionA = new TagFunction(_sourcePlant, _tfCodeA, "TagFunctionDescA", _regCodeA); tagFunctionA.AddRequirement(new TagFunctionRequirement(_sourcePlant, 1, reqDefA1)); tagFunctionA.AddRequirement(new TagFunctionRequirement(_sourcePlant, 2, reqDefA2)); var tagFunctionB = new TagFunction(_sourcePlant, _tfCodeB, "TagFunctionDescB", _regCodeB); _sourceTagFunctions.Add(tagFunctionA); _sourceTagFunctions.Add(tagFunctionB); _tagFunctionApiServiceMock = new Mock <ITagFunctionApiService>(); _tagFunctionApiServiceMock .Setup(t => t.TryGetTagFunctionAsync(TestPlant, _tfCodeA, _regCodeA)) .Returns(Task.FromResult(new PCSTagFunction { Code = _tfCodeA, RegisterCode = _regCodeA })); _tagFunctionApiServiceMock .Setup(t => t.TryGetTagFunctionAsync(TestPlant, _tfCodeB, _regCodeB)) .Returns(Task.FromResult(new PCSTagFunction { Code = _tfCodeB, RegisterCode = _regCodeB })); _command = new CloneCommand(_sourcePlant, TestPlant); _dut = new CloneCommandHandler( _plantProvider, _plantProvider, UnitOfWorkMock.Object, _modeRepository, _requirementTypeRepository, _tagFunctionRepository, _tagFunctionApiServiceMock.Object); UnitOfWorkMock .Setup(uiw => uiw.SaveChangesAsync(It.IsAny <CancellationToken>())) .Callback(() => { // Need this to simulate what EF Core do with Ids upon saving new Items _requirementTypeRepository.Save(); }); }