コード例 #1
0
        public void DuplicateTimeZoneField()
        {
            // This isn't really a valid field, but we don't parse the data yet anyway - it's
            // enough to give the ID.
            var zoneField = new TzdbStreamField(TzdbStreamFieldId.StringPool, new byte[1]);

            var builder = new TzdbStreamData.Builder();

            builder.stringPool = new List <string> {
                "zone1"
            };
            builder.HandleZoneField(zoneField);
            Assert.Throws <InvalidNodaDataException>(() => builder.HandleZoneField(zoneField));
        }
コード例 #2
0
ファイル: TzdbStreamDataTest.cs プロジェクト: jskeet/nodatime
        public void DuplicateField(object fieldIdObject, string handlerMethodName)
        {
            var fieldId = (TzdbStreamFieldId)fieldIdObject;

            var field   = new TzdbStreamField(fieldId, new byte[1]);
            var method  = typeof(TzdbStreamData.Builder).GetMethod(handlerMethodName, BindingFlags.Instance | BindingFlags.NonPublic);
            var builder = new TzdbStreamData.Builder();

            // Provide an empty string pool if we're not checking for a duplicate string pool.
            if (fieldId != TzdbStreamFieldId.StringPool)
            {
                builder.stringPool = new List <string>();
            }

            // First call should be okay
            method.Invoke(builder, new object[] { field });

            // Second call should throw
            var exception = Assert.Throws <TargetInvocationException>(() => method.Invoke(builder, new object[] { field }));

            Assert.IsInstanceOf <InvalidNodaDataException>(exception.InnerException);
        }