예제 #1
0
        public void GetProperties_Success()
        {
            var swiftMetadata = new ThriftyServiceMetadata(typeof(IServiceStup), "1.1");

            //这个测试有点....
            Assert.Equal(swiftMetadata.ServiceName, ThriftServiceMetadata.ParseServiceName(typeof(IServiceStup)));
            Assert.Equal(swiftMetadata.Version, "1.1");
        }
예제 #2
0
        /// <summary>
        ///     构造函数
        /// </summary>
        /// <param name="serviceType">服务源类型</param>
        /// <param name="version">服务版本。</param>
        public ThriftyServiceMetadata(Type serviceType, string version = "1.0.0")
        {
            Guard.ArgumentNotNull(serviceType, nameof(serviceType));
            if (!serviceType.GetTypeInfo().IsInterface)
            {
                throw new ThriftyException($"{serviceType.FullName} as a swifty service type must be a interface type.");
            }

            ThriftServiceAttribute thriftServiceAttr = serviceType.GetTypeInfo().GetCustomAttribute <ThriftServiceAttribute>(false);

            if (thriftServiceAttr == null)
            {
                throw new ThriftyException($"{serviceType.FullName} as a swifty service type must attrited by {nameof(ThriftServiceAttribute)}.");
            }

            this.Version     = String.IsNullOrWhiteSpace(version) ? "1.0.0" : version;
            this.ServiceName = ThriftServiceMetadata.ParseServiceName(serviceType);
        }