コード例 #1
0
        public void ResourceDataDefaultValue_ResourceData()
        {
            ResourceData resource;

            resource = new ResourceData();
            Assert.AreEqual(0, resource.ResourceItemReferences.Count, "ResourceItemReferences count is incorrect.");
            Assert.AreEqual(0, resource.ResourceItems.Count, "ResourceItems count is incorrect.");
        }
コード例 #2
0
        public void StandardValidator_ResourceData_ResourceItemTarget()
        {
            IExtensible extensible;
            ResourceData data;
            ResourceItem item;
            ResourceItemTarget target;

            target = new ResourceItemTarget();
            target.HRef = "href";

            extensible = target;

            item = new ResourceItem();
            item.Context = true;
            item.Id = "itemid";
            item.MimeType = "mime";
            item.Target = target;
            data = new ResourceData();
            data.ResourceItems.Add(item);

            this.DeserializeDocument();
            this._document.Files[0].ResourceData = data;

            Console.WriteLine("Test with null href and empty source.");
            target.HRef = null;
            this.VerifyValidationException(ValidationError.ResourceItemReferenceBaseHRefAndSubject);

            Console.WriteLine("Test with non-null href and non-empty source.");
            extensible.Extensions.Add(new GenericExtension("ext"));
            extensible.Extensions[0].AddChild(new ElementInfo(new XmlNameInfo("name"), new GenericElement()));
            target.HRef = "href";
            this.VerifyValidationException(ValidationError.ResourceItemReferenceBaseHRefAndSubject);
            extensible.Extensions.Clear();

            Console.WriteLine("Test with invalid language.");
            target.Language = "--";
            this.VerifyValidationException(ValidationError.ResourceItemTargetLangInvalid);

            Console.WriteLine("Test with language not matching document target language.");
            target.Language = "fr-zh";
            this.VerifyValidationException(ValidationError.ResourceItemTargetLangMismatch);
        }
コード例 #3
0
        public void StandardValidator_ResourceData_ResourceItem()
        {
            Reference reference;
            ResourceData data;
            ResourceItem item;
            ResourceItemRef itemRef;
            ResourceItemSource source;

            source = new ResourceItemSource();
            source.HRef = "href";

            item = new ResourceItem();
            item.Context = true;
            item.Id = null;
            item.MimeType = "mime";
            data = new ResourceData();
            data.ResourceItems.Add(item);

            this.DeserializeDocument();
            this._document.Files[0].ResourceData = data;

            Console.WriteLine("Test with no source, target or reference.");
            this.VerifyValidationException(ValidationError.ResourceItemMissingChildren);
            item.Source = source;

            Console.WriteLine("Test with invalid MimeType.");
            item.MimeType = "  ";
            this.VerifyValidationException(ValidationError.MimeTypeNotSpecified);
            item.MimeType = "mime";

            Console.WriteLine("Test with invalid Id.");
            item.Id = "!!@";
            this.VerifyValidationException(ValidationError.ResourceItemIdNotNMToken);
            item.Id = "id";

            Console.WriteLine("Test with empty source an no mime type.");
            item.MimeType = null;
            this.VerifyValidationException(ValidationError.MimeTypeNotSpecified);
            item.MimeType = "mime";

            Console.WriteLine("Test with duplicate Id.");
            itemRef = new ResourceItemRef();
            itemRef.Id = item.Id;
            itemRef.Reference = item.Id;
            data.ResourceItemReferences.Add(itemRef);
            this.VerifyValidationException(ValidationError.ResourceItemRefIdDuplicate);

            Console.WriteLine("Test with missing source when Context is false.");
            data.ResourceItemReferences.Clear();
            reference = new Reference();
            reference.HRef = "href";
            item.References.Add(reference);
            item.Context = false;
            item.Source = null;
            this.VerifyValidationException(ValidationError.ResourceItemSourceMissingWithNoContext);
        }
コード例 #4
0
        public void StandardValidator_ResourceData_ResourceItemRef()
        {
            ResourceData data;
            ResourceItem item;
            ResourceItemRef itemRef1;
            ResourceItemRef itemRef2;
            ResourceItemSource source;

            source = new ResourceItemSource();
            source.HRef = "href";

            item = new ResourceItem();
            item.Context = true;
            item.Id = "itemid";
            item.MimeType = "mime";
            item.Source = source;
            data = new ResourceData();
            data.ResourceItems.Add(item);

            itemRef1 = new ResourceItemRef();
            itemRef1.Reference = item.Id;
            data.ResourceItemReferences.Add(itemRef1);

            itemRef2 = new ResourceItemRef();
            itemRef2.Reference = item.Id;
            data.ResourceItemReferences.Add(itemRef2);

            this.DeserializeDocument();
            this._document.Files[0].ResourceData = data;

            Console.WriteLine("Test with invalid Id.");
            itemRef1.Id = "!!@";
            this.VerifyValidationException(ValidationError.ResourceItemRefIdNotNMToken);
            itemRef1.Id = "id";

            Console.WriteLine("Test with duplicate Id.");
            itemRef2.Id = itemRef1.Id;
            this.VerifyValidationException(ValidationError.ResourceItemRefIdDuplicate);
            itemRef2.Id = "id2";

            Console.WriteLine("Test with null reference.");
            itemRef2.Reference = null;
            this.VerifyValidationException(ValidationError.ResourceItemRefInvalidReference);

            Console.WriteLine("Test with invalid reference.");
            itemRef2.Reference = "bogus";
            this.VerifyValidationException(ValidationError.ResourceItemRefInvalidReference);
        }
コード例 #5
0
        public void StandardValidator_ResourceData_ResourceData()
        {
            Reference reference;
            ResourceData data;
            ResourceItem item;
            ResourceItemRef itemRef;
            ResourceItemSource source;
            ResourceItemTarget target;

            item = new ResourceItem();
            data = new ResourceData();

            this.DeserializeDocument();
            this._document.Files[0].ResourceData = data;

            Console.WriteLine("Test with no items or item references.");
            this.VerifyValidationException(ValidationError.ResourceDataMissingItems);

            reference = new Reference();
            reference.HRef = "href";

            source = new ResourceItemSource();
            source.HRef = "href";

            target = new ResourceItemTarget();
            target.HRef = "href";

            itemRef = new ResourceItemRef();
            itemRef.Reference = item.Id;
            data.ResourceItemReferences.Add(itemRef);

            item.Context = true;
            item.Id = null;
            item.MimeType = "mime";
            item.References.Add(reference);
            item.Source = source;
            item.Target = target;
            data.ResourceItems.Add(item);

            Console.WriteLine("Test with valid data.");
            StandardValidatorTests._validator.Validate(this._document);
        }
コード例 #6
0
        public void StandardValidator_ResourceData_Reference()
        {
            IExtensible extensible;
            Reference reference;
            ResourceData data;
            ResourceItem item;

            reference = new Reference();
            extensible = reference;

            item = new ResourceItem();
            item.Context = true;
            item.Id = null;
            item.MimeType = "mime";
            item.References.Add(reference);
            data = new ResourceData();
            data.ResourceItems.Add(item);

            this.DeserializeDocument();
            this._document.Files[0].ResourceData = data;

            Console.WriteLine("Test with null href.");
            reference.HRef = null;
            this.VerifyValidationException(ValidationError.ReferenceHRefNotSpecified);
            reference.HRef = "href";

            Console.WriteLine("Test with invalid language.");
            reference.Language = "--";
            this.VerifyValidationException(ValidationError.ReferenceLangInvalid);
        }
コード例 #7
0
 public void TestInitialize()
 {
     this.element = new ResourceData();
     this.provider = this.element;
 }
コード例 #8
0
        public void XliffWriter_ResourceData()
        {
            Reference reference;
            ResourceData data;
            ResourceItemRef itemRef;
            ResourceItem item;
            ResourceItemSource source;
            ResourceItemTarget target;
            string actualValue;

            data = new ResourceData();

            itemRef = new ResourceItemRef();
            itemRef.Id = "rif1";
            itemRef.Reference = "ri1";
            data.ResourceItemReferences.Add(itemRef);

            item = new ResourceItem();
            item.Context = true;
            item.Id = "ri1";
            item.MimeType = "mime";
            data.ResourceItems.Add(item);

            reference = new Reference();
            reference.HRef = "resource";
            reference.Language = "de-de";
            item.References.Add(reference);

            source = new ResourceItemSource();
            source.HRef = "resource";
            source.Language = "de-de";
            item.Source = source;

            target = new ResourceItemTarget();
            target.HRef = "resource";
            target.Language = "de-de";
            item.Target = target;

            this._document.Files.Add(new File("f1"));
            this._document.Files[0].ResourceData = data;

            actualValue = this.Serialize();
            Assert.AreEqual(TestUtilities.GetFileContents(TestData.FileWithResourceData), actualValue);
        }
コード例 #9
0
        /// <summary>
        /// Creates a <see cref="ResourceData"/> with every element and attribute.
        /// </summary>
        /// <returns>The created <see cref="ResourceData"/>.</returns>
        private ResourceData CreateResourceDataModule_ResourceData()
        {
            ResourceData result;
            ResourceItem item;

            result = new ResourceData();
            item = this.CreateResourceDataModule_ResourceItem();
            result.ResourceItems.Add(item);
            result.ResourceItemReferences.Add(this.CreateResourceDataModule_ResourceItemRef(item.Id));

            return result;
        }