public void ResourceDataDefaultValue_ResourceItem()
        {
            ResourceItem resource;

            resource = new ResourceItem();
            Assert.IsTrue(resource.Context, "Context is incorrect.");
            Assert.IsNull(resource.Id, "Id is incorrect.");
            Assert.IsNull(resource.MimeType, "MimeType is incorrect.");
            Assert.AreEqual(0, resource.References.Count, "References count is incorrect.");
            Assert.IsNull(resource.Source, "Source is incorrect.");
            Assert.IsNull(resource.Target, "Target is incorrect.");
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        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 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);
        }
 public void TestInitialize()
 {
     this.element = new ResourceItem();
     this.provider = this.element;
 }
예제 #9
0
        /// <summary>
        /// Creates a <see cref="ResourceItem"/> with every element and attribute.
        /// </summary>
        /// <returns>The created <see cref="ResourceItem"/>.</returns>
        private ResourceItem CreateResourceDataModule_ResourceItem()
        {
            ResourceItem result;

            result = new ResourceItem();
            result.Context = true;
            result.Id = "ri" + this.GetNextId(typeof(ResourceItem));
            result.MimeType = "mime";

            result.References.Add(this.CreateResourceDataModule_Reference());
            result.Source = this.CreateResourceDataModule_ResourceItemSource();
            result.Target = this.CreateResourceDataModule_ResourceItemTarget();

            this.AddExtension(result);

            return result;
        }