示例#1
0
        public async Task SchemaValidatorHasErrors_ShouldNotCallBusinessValidator()
        {
            A.CallTo(() => schemaValidator.Validate(A <byte[]> ._, A <string> ._, A <XNamespace> ._, A <string> ._))
            .Returns(new List <XmlValidationError>
            {
                new XmlValidationError(ErrorLevel.Error, XmlErrorType.Schema, "An error occurred")
            });

            await XmlValidator().Validate(new ProcessXmlFile(A.Dummy <Guid>(), A.Dummy <byte[]>(), A.Dummy <string>()));

            A.CallTo(() => businessValidator.Validate(A <schemeType> ._, A <Guid> ._))
            .MustNotHaveHappened();
        }
示例#2
0
        public async Task <IEnumerable <MemberUploadError> > Validate(ProcessXmlFile message)
        {
            string schemaVersion = MemberRegistrationSchemaVersion.Version_3_07.GetAttribute <DisplayAttribute>().Name;
            // Validate against the schema
            var errors = schemaValidator.Validate(message.Data, @"EA.Weee.Xml.MemberRegistration.v3schema.xsd", XmlNamespace.MemberRegistration, schemaVersion)
                         .Select(e => e.ToMemberUploadError())
                         .ToList();

            if (errors.Any())
            {
                return(errors);
            }

            schemeType deserializedXml;

            try
            {
                // Validate deserialized XML against business rules
                deserializedXml = xmlConverter.Deserialize <schemeType>(xmlConverter.Convert(message.Data));
            }
            catch (XmlDeserializationFailureException e)
            {
                // Couldn't deserialise - can't go any further, add an error and bail out here
                var exceptionMessage = e.InnerException != null ? e.InnerException.Message : e.Message;
                var friendlyMessage  = errorTranslator.MakeFriendlyErrorMessage(exceptionMessage, schemaVersion);
                errors.Add(new MemberUploadError(ErrorLevel.Error, UploadErrorType.Schema, friendlyMessage));

                return(errors);
            }

            errors = (await businessValidator.Validate(deserializedXml, message.OrganisationId))
                     .Select(err => new MemberUploadError(err.ErrorLevel.ToDomainEnumeration <ErrorLevel>(), UploadErrorType.Business, err.Message))
                     .ToList();

            return(errors);
        }