Exemplo n.º 1
0
        public OperationValidation ToOperationValidation()
        {
            var operation = Operation?.ToOperation();
            var risk      = Risk?.ToRisk();

            return(Resolution.HasValue && ResolutionMoment.HasValue
                ? OperationValidation.CreateResolved(operation, risk, ValidationMoment, ResolutionMoment.Value, Resolution.Value)
                : OperationValidation.Create(operation, risk, ValidationMoment));
        }
Exemplo n.º 2
0
        public async Task SaveAsync(OperationValidation validation)
        {
            var entity = new OperationValidationEntity(validation);
            await _storage.InsertOrReplaceAsync(entity);

            if (validation.Resolution != OperationValidationResolution.Unconfirmed)
            {
                await _index.DeleteIfExistAsync(OperationValidationEntity.IndexPk(), entity.PartitionKey);
            }
        }
Exemplo n.º 3
0
        public async Task AddAsync(OperationValidation validation)
        {
            var entity = new OperationValidationEntity(validation);
            await _storage.CreateIfNotExistsAsync(entity);

            if (validation.Risk.IsResolutionRequired)
            {
                await _index.CreateIfNotExistsAsync(new AzureIndex(OperationValidationEntity.IndexPk(), entity.PartitionKey, entity));
            }
        }
Exemplo n.º 4
0
 public OperationValidationEntity(OperationValidation operationValidation)
 {
     PartitionKey     = Partition(operationValidation.Operation.Id);
     RowKey           = Row();
     Version          = operationValidation.Version;
     Operation        = operationValidation.Operation == null ? null : new OperationEntity(operationValidation.Operation);
     Risk             = operationValidation.Risk == null ? null : new OperationRiskEntity(operationValidation.Risk);
     ValidationMoment = operationValidation.ValidationMoment;
     ResolutionMoment = operationValidation.ResolutionMoment;
     Resolution       = operationValidation.Resolution;
 }
Exemplo n.º 5
0
        public void ValidOperation_LinkAndPathDoNotMatch_FalseIsReturnedAlongWithErrorMessage()
        {
            var validator = new OperationValidation(f => new FakeFile(f), f => new FakeFolder(f));

            var data = new LinkOperationData()
            {
                LinkTo = "test", CreateLinkAt = "test"
            };
            String  errorMessage;
            Boolean valid = validator.ValidOperation(data, out errorMessage);

            Assert.IsFalse(valid);
            Assert.AreEqual("A path can not be linked to itself", errorMessage);
        }
Exemplo n.º 6
0
        public void ValidOperation_ValidData_TrueIsReturned()
        {
            var validator = new OperationValidation(f => new FakeFile(f), f => new FakeFolder(f));

            var data = new LinkOperationData()
            {
                LinkTo = "test1", CreateLinkAt = "test2"
            };

            String  errorMessage;
            Boolean valid = validator.ValidOperation(data, out errorMessage);

            Assert.IsTrue(valid);
        }
        public async Task <OperationValidation> ValidateAsync(Operation operation)
        {
            var validation = await _validationRepository.TryGetAsync(operation.Id);

            if (validation != null)
            {
                return(validation);
            }

            var risk = await _operationRiskEstimator.ValidateAsync(operation);

            validation = OperationValidation.Create(operation, risk);

            await _validationRepository.AddAsync(validation);

            return(validation);
        }
Exemplo n.º 8
0
        public void ValidOperation_File_LinkToExists_ValidOperation()
        {
            String createLinkAt = "linkAt";
            String linkTo       = "linkTo";
            var    fileFactory  = GetFileFactoryThatReturnsExistsFor(linkTo);
            var    validator    = new OperationValidation(fileFactory, f => new FakeFolder(f));


            var data = new LinkOperationData()
            {
                LinkTo = createLinkAt, CreateLinkAt = linkTo, CopyBeforeDelete = true
            };

            String  errorMessage;
            Boolean valid = validator.ValidOperation(data, out errorMessage);

            Assert.IsTrue(valid);
        }
Exemplo n.º 9
0
        public void ValidOperation__CreateLinkAtExistsNoCopyBeforeDeleteLinkToDoesNotExist_FalseIsReturnedAlongWithErrorMessage()
        {
            String createLinkAt = "linkAt";
            String linkTo       = "linkTo";
            var    fileFactory  = GetFileFactoryThatReturnsExistsFor(createLinkAt);
            var    validator    = new OperationValidation(fileFactory, f => new FakeFolder(f));


            var data = new LinkOperationData()
            {
                LinkTo = createLinkAt, CreateLinkAt = linkTo, CopyBeforeDelete = false
            };

            String  errorMessage;
            Boolean valid = validator.ValidOperation(data, out errorMessage);

            Assert.IsFalse(valid);
            Assert.AreEqual("When creating a file link the linked to file must exist", errorMessage);
        }
Exemplo n.º 10
0
        public void ValidOperation_AttemptsToLinkFolderToFile_NotValid()
        {
            String createLinkAt  = "linkAt";
            String linkTo        = "linkTo";
            var    fileFactory   = GetFileFactoryThatReturnsExistsFor(createLinkAt);
            var    folderFactory = CommandDiscoveryTests.GetFolderFactoryThatReturnsExistsFor(linkTo);
            var    validator     = new OperationValidation(fileFactory, folderFactory);


            var data = new LinkOperationData()
            {
                LinkTo = linkTo, CreateLinkAt = createLinkAt, CopyBeforeDelete = true
            };

            String  errorMessage;
            Boolean valid = validator.ValidOperation(data, out errorMessage);

            Assert.IsFalse(valid);
        }