예제 #1
0
        public void Constructor_WhenArgumentsValid_SetsProperties()
        {
            var superType = new FileType("superId", "superDescription", null);
            var type = new FileType("id", "description", superType);

            Assert.AreEqual("id", type.Id);
            Assert.AreEqual("description", type.Description);
            Assert.AreEqual(superType, type.SuperType);
        }
예제 #2
0
        public void IsSameOrSubtypeOf_WhenOtherTypeIsASuperType_ReturnsTrue()
        {
            var superSuperType = new FileType("superSuperId", "superSuperDescription", null);
            var superType = new FileType("superId", "superDescription", superSuperType);
            var type = new FileType("id", "description", superType);

            Assert.IsTrue(type.IsSameOrSubtypeOf(superType));
            Assert.IsTrue(type.IsSameOrSubtypeOf(superSuperType));
        }
예제 #3
0
        /// <summary>
        /// Creates a file type object.
        /// </summary>
        /// <param name="id">The file type id.</param>
        /// <param name="description">The file type description.</param>
        /// <param name="superType">The super type of the file type, or null if none.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="id"/> 
        /// or <paramref name="description"/> is null.</exception>
        /// <exception cref="ArgumentException">Thrown if <paramref name="id"/> is empty.</exception>
        public FileType(string id, string description, FileType superType)
        {
            if (id == null)
                throw new ArgumentNullException("id");
            if (id.Length == 0)
                throw new ArgumentException("The file type id must not be empty.", "id");
            if (description == null)
                throw new ArgumentNullException("description");

            this.id = id;
            this.description = description;
            this.superType = superType;
        }
예제 #4
0
        public void IsSameOrSubtypeOfAny_WhenOtherTypesIsNull_Throws()
        {
            var type = new FileType("id", "description", null);

            Assert.Throws<ArgumentNullException>(() => type.IsSameOrSubtypeOfAny(null));
        }
예제 #5
0
        public void IsSameOrSubtypeOf_WhenOtherTypeIsUnrelated_ReturnsFalse()
        {
            var superType = new FileType("superId", "superDescription", null);
            var type = new FileType("id", "description", superType);
            var unrelatedType = new FileType("otherId", "otherDescription", superType);

            Assert.IsFalse(type.IsSameOrSubtypeOf(unrelatedType));
        }
예제 #6
0
        public void IsSameOrSubtypeOf_WhenOtherTypeIsSame_ReturnsTrue()
        {
            var type = new FileType("id", "description", null);

            Assert.IsTrue(type.IsSameOrSubtypeOf(type));
        }
예제 #7
0
        public void ToString_Always_ReturnsIdConcatenatedWithDescription()
        {
            var type = new FileType("id", "description", null);

            Assert.AreEqual("id: description", type.ToString());
        }
예제 #8
0
        public void IsSameOrSubtypeOfAny_WhenOtherTypesContainsUnrelatedAndSame_ReturnsTrue()
        {
            var superType = new FileType("superId", "superDescription", null);
            var type = new FileType("id", "description", superType);
            var unrelatedType = new FileType("otherId", "otherDescription", superType);

            Assert.IsTrue(type.IsSameOrSubtypeOfAny(unrelatedType, type));
        }
예제 #9
0
        public void IsSameOrSubtypeOfAny_WhenOtherTypesIsEmpty_ReturnsFalse()
        {
            var type = new FileType("id", "description", null);

            Assert.IsFalse(type.IsSameOrSubtypeOfAny());
        }
예제 #10
0
        /// <summary>
        /// Returns true if this file type is equal to or is a subtype of some other type.
        /// </summary>
        /// <param name="otherType">The other type.</param>
        /// <returns>True if the condition is satisfied.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="otherType"/> is null.</exception>
        public bool IsSameOrSubtypeOf(FileType otherType)
        {
            if (otherType == null)
                throw new ArgumentNullException("otherType");

            FileType currentType = this;
            do
            {
                if (currentType == otherType)
                    return true;

                currentType = currentType.SuperType;
            }
            while (currentType != null);

            return false;
        }
예제 #11
0
        /// <summary>
        /// Returns true if the file type is the same or a subtype of one of those specified by <see cref="FileTypes"/>.
        /// </summary>
        /// <param name="fileType">The file type.</param>
        /// <param name="fileTypeManager">The file type manager used to resolve file type ids to file types.</param>
        /// <returns>True if the framework is compatible.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="fileType"/> or <paramref name="fileTypeManager"/> is null.</exception>
        public bool IsFrameworkCompatibleWithFileType(FileType fileType, IFileTypeManager fileTypeManager)
        {
            if (fileType == null)
                throw new ArgumentNullException("fileType");
            if (fileTypeManager == null)
                throw new ArgumentNullException("fileTypeManager");

            foreach (string fileTypeId in FileTypes)
            {
                FileType supportedFileType = fileTypeManager.GetFileTypeById(fileTypeId);
                if (fileType.IsSameOrSubtypeOf(supportedFileType))
                    return true;
            }

            return false;
        }