Exemple #1
0
        public async void DetectCorrectTemplate()
        {
            var TestStep = FibonacciSampleData.Step;
            Mock <IEntitiesRepository> entitiesRepository = new Mock <IEntitiesRepository>();

            entitiesRepository.Setup(sr => sr.GetFirstOrDefaultAsync <StepTemplate>(It.IsAny <Expression <Func <StepTemplate, bool> > >())).Returns(Task.FromResult(FibonacciSampleData.StepTemplate));
            _node.Setup(n => n.Handle(It.IsAny <AddShardWriteOperation>())).Returns(Task.FromResult(new AddShardWriteOperationResponse()
            {
                IsSuccessful = true
            }));


            var handler = new CreateStepCommandHandler(entitiesRepository.Object, clusterMoq.Object, _node.Object);

            var commandResult = await handler.Handle(new CreateStepCommand()
            {
                StepTemplateId = FibonacciSampleData.StepTemplate.ReferenceId,
                Inputs         = new Dictionary <string, object>()
                {
                    { "n-1", 1 },
                    { "n-2", 2 }
                }
            }, new System.Threading.CancellationToken());

            Assert.NotNull(handler);
            Assert.Equal(commandResult.Result.Id.ToString(), commandResult.ObjectRefId);
        }
Exemple #2
0
        public async void CreateStepWithSecret()
        {
            Mock <IEntitiesRepository> entitiesRepository = new Mock <IEntitiesRepository>();

            entitiesRepository.Setup(sr => sr.GetFirstOrDefaultAsync <StepTemplate>(It.IsAny <Expression <Func <StepTemplate, bool> > >())).Returns(Task.FromResult(SecretSampleData.StepTemplate));
            var stepTemplate = await entitiesRepository.Object.GetFirstOrDefaultAsync <StepTemplate>(st => st.ReferenceId == SecretSampleData.StepTemplate.ReferenceId);

            var newStep = stepTemplate.GenerateStep(stepTemplate.ReferenceId, "", "", "", new Dictionary <string, object>()
            {
                { "secret", "This is a test" }
            }, null, null, ClusterStateService.GetEncryptionKey());

            _node.Setup(n => n.Handle(It.IsAny <AddShardWriteOperation>())).Returns(Task.FromResult(new AddShardWriteOperationResponse()
            {
                IsSuccessful = true
            }));

            var handler = new CreateStepCommandHandler(entitiesRepository.Object, clusterMoq.Object, _node.Object);

            var step = await handler.Handle(new CreateStepCommand()
            {
                StepTemplateId = stepTemplate.ReferenceId,
                Inputs         = new Dictionary <string, object>()
                {
                    { "secret", "This is a test" }
                }
            }, new System.Threading.CancellationToken());

            //Test encryption of step worked
            Assert.NotEqual("This is a test", (string)step.Result.Inputs["secret"]);
            //Test decryption of step
            Assert.Equal("This is a test", SecurityUtility.SymmetricallyDecrypt((string)step.Result.Inputs["secret"], ClusterStateService.GetEncryptionKey()));
        }
Exemple #3
0
        public async void DetectMissingTemplate()
        {
            Mock <IEntitiesRepository> entitiesRepository = new Mock <IEntitiesRepository>();

            var handler = new CreateStepCommandHandler(entitiesRepository.Object, clusterMoq.Object, _node.Object);

            await Assert.ThrowsAsync <StepTemplateNotFoundException>(async() =>
            {
                await handler.Handle(new CreateStepCommand()
                {
                    StepTemplateId = FibonacciSampleData.StepTemplate.ReferenceId
                }, new System.Threading.CancellationToken());
            });
        }
Exemple #4
0
        public async void DetectNoInputs()
        {
            var TestStep = FibonacciSampleData.Step;
            Mock <IEntitiesRepository> entitiesRepository = new Mock <IEntitiesRepository>();

            entitiesRepository.Setup(sr => sr.GetFirstOrDefaultAsync <StepTemplate>(It.IsAny <Expression <Func <StepTemplate, bool> > >())).Returns(Task.FromResult(FibonacciSampleData.StepTemplate));
            _node.Setup(n => n.Handle(It.IsAny <AddShardWriteOperation>())).Returns(Task.FromResult(new AddShardWriteOperationResponse()
            {
                IsSuccessful = true
            }));

            var handler = new CreateStepCommandHandler(entitiesRepository.Object, clusterMoq.Object, _node.Object);

            await Assert.ThrowsAsync <InvalidStepInputException>(async() => await handler.Handle(new CreateStepCommand()
            {
                StepTemplateId = FibonacciSampleData.StepTemplate.ReferenceId
            }, new System.Threading.CancellationToken()));
        }
        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);
        }