Example #1
0
        void AssertRaw(object value, bool hasInteractiveRepresentation)
        {
            value.ShouldNotBeNull();

            manager = new RepresentationManager();  // [SetUp] doesn't know we're looping

            for (int i = 0; i < 2; i++)
            {
                if (i == 1)
                {
                    manager.AddProvider(new EditAllTheThingsRepresentationProvider());
                }

                var valueType = value.GetType();
                var reps      = (RepresentedObject)manager.Prepare(value);

                reps.Count.ShouldEqual(hasInteractiveRepresentation ? 3 : 2);
                reps.RepresentedType.ResolvedType.ShouldEqual(valueType);

                reps [0].GetType().ShouldEqual(valueType);
                reps [0].ShouldEqual(value);

                reps.GetRepresentation(0).CanEdit.ShouldEqual(i == 1);
            }
        }
Example #2
0
        void AssertWordSizedNumber <T> (T [] values, WordSizedNumberFlags expectedFlags)
        {
            manager = new RepresentationManager();  // [SetUp] doesn't know we're looping
            //#if MAC || IOS
            //manager.AddProvider (new Unified.UnifiedRepresentationProvider ());
            //#endif

            for (int i = 0; i < values.Length; i++)
            {
                var reps = (RepresentedObject)manager.Prepare(values [i]);
                reps.Count.ShouldEqual(2);
                var word = reps [0].ShouldBeInstanceOf <WordSizedNumber> ();
                word.Flags.ShouldEqual(expectedFlags);
                word.Value.ToString().ShouldEqual(values [i].ToString());
            }
        }
Example #3
0
        public void EnumValue(Enum value)
        {
            var reps = (RepresentedObject)manager.Prepare(value);

            reps.Count.ShouldEqual(2);

            var rep = reps [0].ShouldBeInstanceOf <EnumValue> ();

            var type           = value.GetType();
            var underlyingType = type.GetEnumUnderlyingType();

            rep.RepresentedType.ShouldEqual(reps.RepresentedType);
            rep.RepresentedType.Name.ShouldEqual(type.ToString());

            rep.UnderlyingType.ResolvedType.ShouldEqual(underlyingType);

            rep.IsFlags.ShouldEqual(type.IsDefined(typeof(FlagsAttribute), false));

            rep.Value.ShouldEqual(Convert.ChangeType(
                                      value,
                                      underlyingType,
                                      CultureInfo.InvariantCulture));

            rep.Names.ShouldEqual(Enum.GetNames(type));

            var values = Enum.GetValues(type);

            rep.Values.Count.ShouldEqual(values.Length);

            for (int i = 0; i < values.Length; i++)
            {
                rep.Values [i].ShouldEqual(Convert.ChangeType(
                                               values.GetValue(i),
                                               underlyingType,
                                               CultureInfo.InvariantCulture));
            }
        }