public void ResourceDataDefaultValue_ResourceItemRef()
        {
            ResourceItemRef resource;

            resource = new ResourceItemRef();
            Assert.IsNull(resource.Id, "Id is incorrect.");
            Assert.IsNull(resource.Reference, "Reference is incorrect.");
        }
 public void TestInitialize()
 {
     this.element = new ResourceItemRef();
     this.provider = this.element;
 }
        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_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_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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a <see cref="ResourceItemRef"/> with every element and attribute.
        /// </summary>
        /// <returns>The created <see cref="ResourceItemRef"/>.</returns>
        private ResourceItemRef CreateResourceDataModule_ResourceItemRef(string reference)
        {
            ResourceItemRef result;

            result = new ResourceItemRef();
            result.Id = "rif" + this.GetNextId(typeof(ResourceItemRef));
            result.Reference = reference;

            this.AddExtension(result);

            return result;
        }