public async Task HandlingCreateStepCommand_ShouldAddStepToJourney()
        {
            Assert.AreEqual(0, _journey.Steps.Count);
            // Act
            await _dut.Handle(_command, default);

            // Assert
            Assert.AreEqual(1, _journey.Steps.Count);
            var stepAdded = _journey.Steps.First();

            Assert.AreEqual(_title, stepAdded.Title);
            Assert.AreEqual(_autoTransferMethod, stepAdded.AutoTransferMethod);
            Assert.AreEqual(ModeId, stepAdded.ModeId);
            Assert.AreEqual(ResponsibleId, stepAdded.ResponsibleId);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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()));
        }
Esempio n. 4
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());
            });
        }
Esempio n. 5
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()));
        }