public async Task <SignerCreateResponse> Create([FromQuery] SignerCreate signerCreate)
        {
            var componentValidator = new ComponentValidator(_alfrescoHttpClient);
            await signerCreate.ComponentId.ForEachAsync(async x => await componentValidator.ValidateAsync(new DocumentProperties(x)));

            return(await _signerService.CreateXml(_apiConfiguration.Url, signerCreate.DocumentId, signerCreate.ComponentId, signerCreate.Visual));
        }
Exemple #2
0
        private static void AssertCgManifestContent(string cgManifestContent, FileReport fileReport)
        {
            var componentManifest = JsonConvert.DeserializeObject <ComponentManifest>(cgManifestContent);

            foreach (var registration in componentManifest.Registrations)
            {
                var validationResult = ComponentValidator.IsComponentValid(registration.Component);
                var componentReport  = CreateComponentReportForRegistration(registration.Component, validationResult);
                fileReport.ComponentReport.Add(componentReport);
            }
        }
Exemple #3
0
        public void IsComponentValid_ComponentDefinitionNotMatchComponentType_ComponentIsInvalid()
        {
            var invalidTypedComponent = new TypedComponent
            {
                Type = ComponentType.Npm,
                Cargo = new CargoComponent()
            };

            var result = ComponentValidator.IsComponentValid(invalidTypedComponent);

            result.IsValid.Should().BeFalse();
            result.Messages.Should().HaveCount(1);
            result.Messages.First().Should().BeEquivalentTo("Incorrect component definition. The component type is Npm, but the component definition is for: Cargo.");
        }
Exemple #4
0
        public void IsComponentValid_ValidComponent_ValidResultIsReturned()
        {
            var validTypedComponent = new TypedComponent
            {
                Type = ComponentType.Npm,
                Npm = new NpmComponent
                {
                    Name = "test",
                    Version ="1.0.0"
                }
            };

            var result = ComponentValidator.IsComponentValid(validTypedComponent);

            result.IsValid.Should().BeTrue();
            result.Messages.Should().HaveCount(0);
        }
        public async Task <List <SignerStatus> > Status([FromQuery] SignerGetStatus signerStatus)
        {
            var componentValidator = new ComponentValidator(_alfrescoHttpClient);
            await signerStatus.ComponentId.ForEachAsync(async x =>
            {
                var component = x.Split('_');
                if (component.Length != 2)
                {
                    throw new BadRequestException($"Component {x} is not in form 'guid_componentId'");
                }

                //await componentValidator.ValidateAsync(new DocumentProperties(component[1]));
            });

            return((from component in signerStatus.ComponentId
                    where _simpleMemoryCache.IsExist($"{SignerStatus}{component}")
                    select new SignerStatus {
                Id = component.Split('_')[0], Component = component.Split('_')[1], Status = _simpleMemoryCache.Get <string>($"{SignerStatus}{component}")
            }).ToList());
        }
        public async Task Should_create_validator_from_component_and_invoke()
        {
            var validator = A.Fake <IValidator>();

            var componentData   = JsonValue.Object();
            var componentObject = new Component("type", componentData, new Schema("my-schema"));

            var isFactoryCalled = false;

            var sut = new ComponentValidator(_ =>
            {
                isFactoryCalled = true;
                return(validator);
            });

            await sut.ValidateAsync(componentObject, errors);

            Assert.True(isFactoryCalled);

            A.CallTo(() => validator.ValidateAsync(componentData, A <ValidationContext> ._, A <AddError> ._))
            .MustHaveHappened();
        }