public void Setup() { var modeMock = new Mock <Mode>(); modeMock.SetupGet(m => m.Plant).Returns(TestPlant); var respMock = new Mock <Responsible>(); respMock.SetupGet(m => m.Plant).Returns(TestPlant); // Arrange var fromStep = new Step(TestPlant, FromStep, modeMock.Object, respMock.Object); fromStep.SetProtectedIdForTesting(FromStepId); var toStepInJourney1 = new Step(TestPlant, ToStepInJourney1, modeMock.Object, respMock.Object); toStepInJourney1.SetProtectedIdForTesting(ToStepIdInJourney1); var toStepInJourney2 = new Step(TestPlant, ToStepInJourney2, modeMock.Object, respMock.Object); toStepInJourney2.SetProtectedIdForTesting(ToStepIdInJourney2); var journey1 = new Journey(TestPlant, Journey1); journey1.SetProtectedIdForTesting(Journey1Id); journey1.AddStep(fromStep); journey1.AddStep(toStepInJourney1); var journey2 = new Journey(TestPlant, Journey2); journey2.SetProtectedIdForTesting(Journey2Id); journey2.AddStep(toStepInJourney2); _historyRepositoryMock = new Mock <IHistoryRepository>(); _historyRepositoryMock .Setup(repo => repo.Add(It.IsAny <History>())) .Callback <History>(history => { _historyAdded = history; }); _journeyRepositoryMock = new Mock <IJourneyRepository>(); _journeyRepositoryMock .Setup(repo => repo.GetJourneysByStepIdsAsync(new List <int> { FromStepId, ToStepIdInJourney1 })) .Returns(Task.FromResult(new List <Journey> { journey1, journey1 })); _journeyRepositoryMock .Setup(repo => repo.GetJourneysByStepIdsAsync(new List <int> { FromStepId, ToStepIdInJourney2 })) .Returns(Task.FromResult(new List <Journey> { journey1, journey2 })); _dut = new StepChangedEventHandler(_historyRepositoryMock.Object, _journeyRepositoryMock.Object); }
public async Task HandlingAutoTransferCommand_ForRfocCertificate_ShouldTransferToNextStep_WhenNextStepExists() { // Arrange var step3OnJourneyId = 3; var step3OnJourney = new Step( TestPlant, "Step3", new Mode(TestPlant, "M3", false), new Responsible(TestPlant, "RC3", "RD3")); step3OnJourney.SetProtectedIdForTesting(step3OnJourneyId); _journey.AddStep(step3OnJourney); await _dut.Handle(_commandForRfcc, default); _projectRepoMock .Setup(r => r.GetStandardTagsInProjectInStepsAsync(_testProjectName, new List <string> { _testTagNo }, new List <int> { _tag.StepId })) .Returns(Task.FromResult(new List <Tag> { _tag })); // Act var result = await _dut.Handle(_commandForRfoc, default); // Assert Assert.AreEqual(step3OnJourneyId, _tag.StepId); Assert.AreEqual(0, result.Errors.Count); }
public void Setup() { var modeMock = new Mock <Mode>(); modeMock.SetupGet(m => m.Plant).Returns(TestPlant); var responsibleMock = new Mock <Responsible>(); responsibleMock.SetupGet(x => x.Plant).Returns(TestPlant); _step = new Step(TestPlant, "S", modeMock.Object, responsibleMock.Object); _step.SetProtectedIdForTesting(StepId); _journey = new Journey(TestPlant, "J"); _journey.SetProtectedIdForTesting(5); _journey.AddStep(_step); _journeys = new List <Journey> { _journey }; _dbSetMock = _journeys.AsQueryable().BuildMockDbSet(); ContextHelper .ContextMock .Setup(x => x.Journeys) .Returns(_dbSetMock.Object); _dut = new JourneyRepository(ContextHelper.ContextMock.Object); }
protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions) { using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { _supplierMode = AddMode(context, "M", true); _journey1 = AddJourneyWithStep(context, "J1", StepTitle1InJourney1, _supplierMode, AddResponsible(context, "R1")); _step1InJourney1ForSupplier = _journey1.Steps.Single(); _step2InJourney1 = new Step(TestPlant, StepTitle2InJourney1, AddMode(context, "M2", false), AddResponsible(context, "R2")); _step3InJourney1 = new Step(TestPlant, StepTitle3InJourney1, AddMode(context, "M3", false), AddResponsible(context, "R3")); _journey1.AddStep(_step2InJourney1); _journey1.AddStep(_step3InJourney1); context.SaveChangesAsync().Wait(); } }
public async Task <Result <int> > Handle(DuplicateJourneyCommand request, CancellationToken cancellationToken) { var journey = await _journeyRepository.GetByIdAsync(request.JourneyId); var responsibleIds = journey.Steps.Select(s => s.ResponsibleId).Distinct(); var modeIds = journey.Steps.Select(s => s.ModeId).Distinct(); var responsibles = await _responsibleRepository.GetByIdsAsync(responsibleIds); var modes = await _modeRepository.GetByIdsAsync(modeIds); var plant = _plantProvider.Plant; var newJourney = new Journey(plant, $"{journey.Title}{Journey.DuplicatePrefix}"); foreach (var step in journey.OrderedSteps()) { var responsible = responsibles.Single(r => r.Id == step.ResponsibleId); var mode = modes.Single(m => m.Id == step.ModeId); var newStep = new Step(plant, step.Title, mode, responsible); newJourney.AddStep(newStep); } _journeyRepository.Add(newJourney); await _unitOfWork.SaveChangesAsync(cancellationToken); return(new SuccessResult <int>(newJourney.Id)); }
public void Setup() { _modeMock = new Mock <Mode>(); _modeMock.SetupGet(m => m.Plant).Returns(TestPlant); _modeMock.SetupGet(x => x.Id).Returns(ModeId); var journeyRepositoryMock = new Mock <IJourneyRepository>(); _journey = new Journey(TestPlant, "J"); _journey.SetProtectedIdForTesting(JourneyId); _step = new Step(TestPlant, "S", _modeMock.Object, new Responsible(TestPlant, "RC", "RD")); _step.SetProtectedIdForTesting(StepId); _journey.AddStep(_step); journeyRepositoryMock .Setup(r => r.GetByIdAsync(JourneyId)) .Returns(Task.FromResult(_journey)); _command = new VoidStepCommand(JourneyId, StepId, _rowVersion); _dut = new VoidStepCommandHandler( journeyRepositoryMock.Object, UnitOfWorkMock.Object); }
private (Project, Action) CreateAction(PreservationContext context, string projectName, bool closeProject) { var plantId = _plantProvider.Plant; var mode = new Mode(plantId, "M1", false); context.Modes.Add(mode); var responsible = new Responsible(plantId, "Resp1", "Resp1-Desc"); context.Responsibles.Add(responsible); context.SaveChangesAsync().Wait(); var journey = new Journey(plantId, "J1"); var step = new Step(plantId, "S1", mode, responsible); journey.AddStep(step); context.Journeys.Add(journey); context.SaveChangesAsync().Wait(); var requirementType = new RequirementType(plantId, "RT", "RT title", RequirementTypeIcon.Other, 1); context.RequirementTypes.Add(requirementType); var requirementDefinition = new RequirementDefinition(plantId, "RD", 2, RequirementUsage.ForAll, 1); requirementType.AddRequirementDefinition(requirementDefinition); context.SaveChangesAsync().Wait(); var project = new Project(plantId, projectName, $"{projectName} Desc") { IsClosed = closeProject }; context.Projects.Add(project); var tag = new Tag( plantId, TagType.Standard, "Tag A", "Tag desc", step, new List <TagRequirement> { new TagRequirement(plantId, 2, requirementDefinition) }); project.AddTag(tag); context.SaveChangesAsync().Wait(); var action = new Action(plantId, "A", "D", null); tag.AddAction(action); var attachment = new ActionAttachment(plantId, Guid.Empty, "fil.txt"); action.AddAttachment(attachment); context.SaveChangesAsync().Wait(); return(project, action); }
private static Step SeedStep(PreservationContext dbContext, Journey journey, string title, Mode mode, Responsible responsible) { var step = new Step(journey.Plant, title, mode, responsible); journey.AddStep(step); dbContext.SaveChangesAsync().Wait(); return(step); }
protected Journey AddJourneyWithStep(PreservationContext context, string journeyTitle, string stepTitle, Mode mode, Responsible responsible) { var journey = new Journey(TestPlant, journeyTitle); journey.AddStep(new Step(TestPlant, stepTitle, mode, responsible)); context.Journeys.Add(journey); context.SaveChangesAsync().Wait(); return(journey); }
public void Setup() { // Arrange var journeyRepositoryMock = new Mock <IJourneyRepository>(); var modeMock = new Mock <Mode>(); modeMock.SetupGet(s => s.Plant).Returns(TestPlant); var responsibleMock = new Mock <Responsible>(); responsibleMock.SetupGet(s => s.Plant).Returns(TestPlant); var journeyId = 1; var stepAId = 2; var stepBId = 3; var journey = new Journey(TestPlant, "TestJourney"); journey.SetProtectedIdForTesting(journeyId); _stepA = new Step(TestPlant, _stepATitle, modeMock.Object, responsibleMock.Object); _stepA.SetProtectedIdForTesting(stepAId); journey.AddStep(_stepA); _sortKeyA = _stepA.SortKey; _stepB = new Step(TestPlant, _stepBTitle, modeMock.Object, responsibleMock.Object); _stepB.SetProtectedIdForTesting(stepBId); journey.AddStep(_stepB); _sortKeyB = _stepB.SortKey; journeyRepositoryMock.Setup(s => s.GetByIdAsync(journeyId)) .Returns(Task.FromResult(journey)); _command = new SwapStepsCommand(journeyId, stepAId, _rowVersionA, stepBId, _rowVersionB); _dut = new SwapStepsCommandHandler( journeyRepositoryMock.Object, UnitOfWorkMock.Object); }
public static void AddJourneys(this IJourneyRepository journeyRepository, int entryCount, string plant, List <Mode> modes, List <Responsible> responsibles) { var rand = new Random(); for (var i = 0; i < entryCount; i++) { var journey = new Journey(plant, $"Journey-{i}"); var step = new Step(plant, $"Step-{i}", modes[rand.Next(modes.Count)], responsibles[rand.Next(responsibles.Count)]); journey.AddStep(step); journeyRepository.Add(journey); } }
public void Setup() { _dutWithNoSteps = new Journey(TestPlant, "TitleA"); _dutWith3Steps = new Journey(TestPlant, "TitleB"); _stepAId = 10033; _stepBId = 3; _stepCId = 967; _mode = new Mode(TestPlant, "M", false); _responsible = new Responsible(TestPlant, "RC", "RD"); _stepA = new Step(TestPlant, "SA", _mode, _responsible); _stepA.SetProtectedIdForTesting(_stepAId); _stepB = new Step(TestPlant, "SB", _mode, _responsible); _stepB.SetProtectedIdForTesting(_stepBId); _stepC = new Step(TestPlant, "SC", _mode, _responsible); _stepC.SetProtectedIdForTesting(_stepCId); _dutWith3Steps.AddStep(_stepA); _dutWith3Steps.AddStep(_stepB); _dutWith3Steps.AddStep(_stepC); }
public void AddStep_ShouldSetNextAvailableSortKey_AfterDeletingSteps() { // Arrange var stepA = _dutWith3Steps.Steps.ElementAt(0); Assert.AreEqual(1, stepA.SortKey); var stepB = _dutWith3Steps.Steps.ElementAt(1); Assert.AreEqual(2, stepB.SortKey); var stepC = _dutWith3Steps.Steps.ElementAt(2); Assert.AreEqual(3, stepC.SortKey); stepA.IsVoided = true; _dutWith3Steps.RemoveStep(stepA); var stepD = new Step(TestPlant, "SD", _mode, _responsible); // Act _dutWith3Steps.AddStep(stepD); // Arrange Assert.AreEqual(4, stepD.SortKey); }
public void Setup() { var rdId1 = 17; var rdId2 = 18; var tagId1 = 7; var tagId2 = 8; var stepId1 = 9; var stepId2 = 10; var step1Mock = new Mock <Step>(); step1Mock.SetupGet(s => s.Plant).Returns(TestPlant); step1Mock.SetupGet(s => s.Id).Returns(stepId1); var step2Mock = new Mock <Step>(); step2Mock.SetupGet(s => s.Plant).Returns(TestPlant); step2Mock.SetupGet(s => s.Id).Returns(stepId2); var journey = new Journey(TestPlant, "D"); journey.AddStep(step1Mock.Object); journey.AddStep(step2Mock.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); _req1OnTag1 = new TagRequirement(TestPlant, 2, _rd1Mock.Object); _req2OnTag1 = new TagRequirement(TestPlant, 2, _rd2Mock.Object); _req1OnTag2 = new TagRequirement(TestPlant, 2, _rd1Mock.Object); _req2OnTag2 = new TagRequirement(TestPlant, 2, _rd2Mock.Object); _tag1 = new Tag(TestPlant, TagType.Standard, "", "", step2Mock.Object, new List <TagRequirement> { _req1OnTag1, _req2OnTag1 }); _tag1.StartPreservation(); _tag1.SetProtectedIdForTesting(tagId1); _tag2 = new Tag(TestPlant, TagType.Standard, "", "", step2Mock.Object, new List <TagRequirement> { _req1OnTag2, _req2OnTag2 }); _tag2.StartPreservation(); _tag2.SetProtectedIdForTesting(tagId2); var tags = new List <Tag> { _tag1, _tag2 }; var tagIds = new List <int> { tagId1, tagId2 }; var tagIdsWithRowVersion = new List <IdAndRowVersion> { new IdAndRowVersion(tagId1, _rowVersion1), new IdAndRowVersion(tagId2, _rowVersion2) }; _projectRepoMock = new Mock <IProjectRepository>(); _projectRepoMock.Setup(r => r.GetTagsByTagIdsAsync(tagIds)).Returns(Task.FromResult(tags)); var journeyRepoMock = new Mock <IJourneyRepository>(); journeyRepoMock .Setup(r => r.GetJourneysByStepIdsAsync(new List <int> { stepId2 })) .Returns(Task.FromResult(new List <Journey> { journey })); _command = new CompletePreservationCommand(tagIdsWithRowVersion); _dut = new CompletePreservationCommandHandler(_projectRepoMock.Object, journeyRepoMock.Object, UnitOfWorkMock.Object); }
public void Setup() { var mode = new Mode(TestPlant, "M", false); var responsible = new Responsible(TestPlant, "RC", "RD"); var step1OnJourney = new Step(TestPlant, "Step1", mode, responsible) { AutoTransferMethod = AutoTransferMethod.OnRfccSign }; step1OnJourney.SetProtectedIdForTesting(_step1OnJourneyId); var step2OnJourney = new Step(TestPlant, "Step2", mode, responsible) { AutoTransferMethod = AutoTransferMethod.OnRfocSign }; step2OnJourney.SetProtectedIdForTesting(_step2OnJourneyId); _journey = new Journey(TestPlant, "J1"); _journey.AddStep(step1OnJourney); _journey.AddStep(step2OnJourney); var journeyRepoMock = new Mock <IJourneyRepository>(); journeyRepoMock .Setup(r => r.GetJourneysWithAutoTransferStepsAsync(AutoTransferMethod.OnRfccSign)) .Returns(Task.FromResult(new List <Journey> { _journey })); journeyRepoMock .Setup(r => r.GetJourneysWithAutoTransferStepsAsync(AutoTransferMethod.OnRfocSign)) .Returns(Task.FromResult(new List <Journey> { _journey })); var reqMock = new Mock <TagRequirement>(); reqMock.SetupGet(r => r.Plant).Returns(TestPlant); _tag = new Tag(TestPlant, TagType.Standard, _testTagNo, "", step1OnJourney, new List <TagRequirement> { reqMock.Object }); _tag.StartPreservation(); _rfcc = "RFCC"; var rfoc = "RFOC"; var tac = "TAC"; _commandForRfcc = new AutoTransferCommand(_testProjectName, _certificateNo, _rfcc); _commandForRfoc = new AutoTransferCommand(_testProjectName, _certificateNo, rfoc); _commandForOther = new AutoTransferCommand(_testProjectName, _certificateNo, tac); _procosysCertificateTagsModel = new PCSCertificateTagsModel() { CertificateIsAccepted = true, Tags = new List <PCSCertificateTag> { new PCSCertificateTag { TagNo = _testTagNo } } }; _certificateApiServiceMock = new Mock <ICertificateApiService>(); _certificateApiServiceMock.Setup(c => c.TryGetCertificateTagsAsync(TestPlant, _testProjectName, _certificateNo, _rfcc)) .Returns(Task.FromResult(_procosysCertificateTagsModel)); _certificateApiServiceMock.Setup(c => c.TryGetCertificateTagsAsync(TestPlant, _testProjectName, _certificateNo, rfoc)) .Returns(Task.FromResult(_procosysCertificateTagsModel)); _certificateApiServiceMock.Setup(c => c.TryGetCertificateTagsAsync(TestPlant, _testProjectName, _certificateNo, tac)) .Returns(Task.FromResult(_procosysCertificateTagsModel)); _projectRepoMock = new Mock <IProjectRepository>(); _projectRepoMock .Setup(r => r.GetProjectOnlyByNameAsync(_testProjectName)) .Returns(Task.FromResult(new Project(TestPlant, _testProjectName, "Desc"))); _projectRepoMock .Setup(r => r.GetStandardTagsInProjectInStepsAsync(_testProjectName, new List <string> { _testTagNo }, new List <int> { _step1OnJourneyId })) .Returns(Task.FromResult(new List <Tag> { _tag })); _projectRepoMock .Setup(r => r.GetStandardTagsInProjectInStepsAsync(_testProjectName, new List <string> { _testTagNo }, new List <int> { _step2OnJourneyId })) .Returns(Task.FromResult(new List <Tag> { _tag })); _loggerMock = new Mock <ILogger <AutoTransferCommandHandler> >(); _dut = new AutoTransferCommandHandler( _projectRepoMock.Object, journeyRepoMock.Object, UnitOfWorkMock.Object, PlantProviderMock.Object, _certificateApiServiceMock.Object, _loggerMock.Object); }
public void Setup() { // Arrange var mode = new Mode(TestPlant, "M", false); mode.SetProtectedIdForTesting(_modeId); _modeRepositoryMock = new Mock <IModeRepository>(); _modeRepositoryMock .Setup(m => m.GetByIdsAsync(new List <int> { _modeId })) .Returns(Task.FromResult(new List <Mode> { mode })); var responsible = new Responsible(TestPlant, "RC", "RD"); responsible.SetProtectedIdForTesting(_responsibleId); _responsibleRepositoryMock = new Mock <IResponsibleRepository>(); _responsibleRepositoryMock .Setup(r => r.GetByIdsAsync(new List <int> { _responsibleId })) .Returns(Task.FromResult(new List <Responsible> { responsible })); var stepA = new Step(TestPlant, _stepA, mode, responsible); stepA.SetProtectedIdForTesting(_stepAId); var stepB = new Step(TestPlant, _stepB, mode, responsible); stepB.SetProtectedIdForTesting(_stepBId); var stepC = new Step(TestPlant, _stepC, mode, responsible); stepC.SetProtectedIdForTesting(_stepCId); var sourceJourneyWithoutSteps = new Journey(TestPlant, TestJourneyWithoutSteps); _sourceJourneyWith3Steps = new Journey(TestPlant, TestJourneyWith3Steps); _sourceJourneyWith3Steps.AddStep(stepA); _sourceJourneyWith3Steps.AddStep(stepB); _sourceJourneyWith3Steps.AddStep(stepC); _journeyRepositoryMock = new Mock <IJourneyRepository>(); _journeyRepositoryMock.Setup(j => j.GetByIdAsync(_journeyWithoutStepsId)) .Returns(Task.FromResult(sourceJourneyWithoutSteps)); _journeyRepositoryMock.Setup(j => j.GetByIdAsync(_journeyWith3StepsId)) .Returns(Task.FromResult(_sourceJourneyWith3Steps)); _journeyRepositoryMock .Setup(repo => repo.Add(It.IsAny <Journey>())) .Callback <Journey>(journey => { _journeyAdded = journey; }); _journeyWithoutStepsCommand = new DuplicateJourneyCommand(_journeyWithoutStepsId); _journeyWith3StepsCommand = new DuplicateJourneyCommand(_journeyWith3StepsId); _dut = new DuplicateJourneyCommandHandler( _journeyRepositoryMock.Object, _modeRepositoryMock.Object, _responsibleRepositoryMock.Object, UnitOfWorkMock.Object, PlantProviderMock.Object); }
public void AddStep_ShouldThrowException_WhenStepNotGiven() => Assert.ThrowsException <ArgumentNullException>(() => _dutWithNoSteps.AddStep(null));
private (int, int) CreateTag( PreservationContext context, string projectName, TagType tagType, int intervalWeeks) { var plantId = _plantProvider.Plant; _mode1 = new Mode(plantId, "M1", false); _mode2 = new Mode(plantId, "M2", false); context.Modes.Add(_mode1); context.Modes.Add(_mode2); _responsible1 = new Responsible(plantId, "Resp1", "Resp1-Desc"); _responsible2 = new Responsible(plantId, "Resp2", "Resp2-Desc"); context.Responsibles.Add(_responsible1); context.Responsibles.Add(_responsible2); context.SaveChangesAsync().Wait(); var journey = new Journey(plantId, "J1"); var step = new Step(plantId, "S1", _mode1, _responsible1); journey.AddStep(step); journey.AddStep(new Step(plantId, "S2", _mode2, _responsible2)); context.Journeys.Add(journey); context.SaveChangesAsync().Wait(); var requirementType = new RequirementType(plantId, "RT", "RT title", RequirementTypeIcon.Other, 1); context.RequirementTypes.Add(requirementType); var requirementDefinition = new RequirementDefinition(plantId, "RD", intervalWeeks, RequirementUsage.ForAll, 1); requirementType.AddRequirementDefinition(requirementDefinition); context.SaveChangesAsync().Wait(); var project = new Project(plantId, projectName, $"{projectName} Desc"); context.Projects.Add(project); var tag = new Tag( plantId, tagType, "Tag A", "Tag desc", step, new List <TagRequirement> { new TagRequirement(plantId, _intervalWeeks1, requirementDefinition) }) { Calloff = "C", CommPkgNo = "Cp", McPkgNo = "Mp", PurchaseOrderNo = "PO", TagFunctionCode = "TF" }; tag.SetArea("A", "A desc"); tag.SetDiscipline("D", "D desc"); project.AddTag(tag); context.SaveChangesAsync().Wait(); return(project.Id, tag.Id); }
public void Setup() { // Arrange _plantProviderMock = new Mock <IPlantProvider>(); _plantProviderMock.Setup(p => p.Plant).Returns(TestPlant); var journeyRepositoryMock = new Mock <IJourneyRepository>(); _journey = new Journey(TestPlant, "J"); _journey.SetProtectedIdForTesting(_journeyId); _modeRepositoryMock = new Mock <IModeRepository>(); _modeMock = new Mock <Mode>(); _modeMock.SetupGet(s => s.Plant).Returns(TestPlant); _modeMock.SetupGet(x => x.Id).Returns(_modeId); _modeRepositoryMock .Setup(r => r.GetByIdAsync(_modeId)) .Returns(Task.FromResult(_modeMock.Object)); _responsible = new Responsible(TestPlant, _responsibleCode, "D1"); _responsible.SetProtectedIdForTesting(_responsibleId); _responsible2 = new Responsible(TestPlant, _responsibleCode2, "D2"); _responsible2.SetProtectedIdForTesting(_responsibleId2); _responsibleRepositoryMock = new Mock <IResponsibleRepository>(); _responsibleRepositoryMock .Setup(r => r.GetByCodeAsync(_responsibleCode)) .Returns(Task.FromResult(_responsible)); _responsibleRepositoryMock .Setup(r => r.GetByCodeAsync(_responsibleCode2)) .Returns(Task.FromResult(_responsible2)); _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)); _step = new Step(TestPlant, _oldTitle, _modeMock.Object, _responsible) { AutoTransferMethod = _oldAutoTransferMethod }; _step.SetProtectedIdForTesting(_stepId); _journey.AddStep(_step); _responsibleApiServiceMock.Setup(s => s.TryGetResponsibleAsync(TestPlant, _responsibleCode)) .Returns(Task.FromResult(new PCSResponsible { Description = "ResponsibleTitle" })); journeyRepositoryMock.Setup(s => s.GetByIdAsync(_journeyId)) .Returns(Task.FromResult(_journey)); _command = new UpdateStepCommand(_journeyId, _stepId, _modeId, _responsibleCode, _newTitle, _newAutoTransferMethod, _rowVersion); _commandWithResponsible2 = new UpdateStepCommand(_journeyId, _stepId, _modeId, _responsibleCode2, _newTitle, _newAutoTransferMethod, _rowVersion); _dut = new UpdateStepCommandHandler( journeyRepositoryMock.Object, _modeRepositoryMock.Object, _responsibleRepositoryMock.Object, UnitOfWorkMock.Object, _plantProviderMock.Object, _responsibleApiServiceMock.Object); }
public void Setup() { var step1OnJourney1Mock = new Mock <Step>(); step1OnJourney1Mock.SetupGet(x => x.Id).Returns(Step1OnJourney1Id); step1OnJourney1Mock.SetupGet(x => x.Plant).Returns(TestPlant); var step2OnJourney1Mock = new Mock <Step>(); step2OnJourney1Mock.SetupGet(x => x.Id).Returns(Step2OnJourney1Id); step2OnJourney1Mock.SetupGet(x => x.Plant).Returns(TestPlant); var journey1 = new Journey(TestPlant, "J1"); journey1.AddStep(step1OnJourney1Mock.Object); journey1.AddStep(step2OnJourney1Mock.Object); var step1OnJourney2Mock = new Mock <Step>(); step1OnJourney2Mock.SetupGet(x => x.Id).Returns(Step1OnJourney2Id); step1OnJourney2Mock.SetupGet(x => x.Plant).Returns(TestPlant); var step2OnJourney2Mock = new Mock <Step>(); step2OnJourney2Mock.SetupGet(x => x.Id).Returns(Step2OnJourney2Id); step2OnJourney2Mock.SetupGet(x => x.Plant).Returns(TestPlant); var journey2 = new Journey(TestPlant, "J2"); journey2.AddStep(step1OnJourney2Mock.Object); journey2.AddStep(step2OnJourney2Mock.Object); var journeyRepoMock = new Mock <IJourneyRepository>(); journeyRepoMock .Setup(r => r.GetJourneysByStepIdsAsync(new List <int> { Step1OnJourney1Id, Step1OnJourney2Id })) .Returns(Task.FromResult(new List <Journey> { journey1, journey2 })); var reqMock1 = new Mock <TagRequirement>(); reqMock1.SetupGet(r => r.Plant).Returns(TestPlant); var tagId1 = 7; var tagId2 = 8; _tag1 = new Tag(TestPlant, TagType.Standard, "", "", step1OnJourney1Mock.Object, new List <TagRequirement> { reqMock1.Object }); _tag1.SetProtectedIdForTesting(tagId1); var reqMock2 = new Mock <TagRequirement>(); reqMock2.SetupGet(r => r.Plant).Returns(TestPlant); _tag2 = new Tag(TestPlant, TagType.Standard, "", "", step1OnJourney2Mock.Object, new List <TagRequirement> { reqMock2.Object }); _tag2.SetProtectedIdForTesting(tagId2); _tag1.StartPreservation(); _tag2.StartPreservation(); var projectRepoMock = new Mock <IProjectRepository>(); var tagIds = new List <int> { tagId1, tagId2 }; var tagIdsWithRowVersion = new List <IdAndRowVersion> { new IdAndRowVersion(tagId1, _rowVersion1), new IdAndRowVersion(tagId2, _rowVersion2) }; projectRepoMock .Setup(r => r.GetTagsByTagIdsAsync(tagIds)) .Returns(Task.FromResult(new List <Tag> { _tag1, _tag2 })); _command = new TransferCommand(tagIdsWithRowVersion); _dut = new TransferCommandHandler(projectRepoMock.Object, journeyRepoMock.Object, UnitOfWorkMock.Object); }