示例#1
0
        protected virtual object GetRandomValue(Type propertyType)
        {
            var randomizer = Randomizer.Instance;

            object value;

            switch (propertyType.ToString())
            {
            case "System.Int32":
                value = Randomizer.NextInt32();
                break;

            case "System.String":
                value =
                    new string(
                        Enumerable.Repeat(Chars, randomizer.Next(5, 250))
                        .Select(s => s[randomizer.Next(s.Length)])
                        .ToArray());
                break;

            case "System.DateTime":
                var range        = DateTime.MaxValue - DateTime.MinValue;
                var randTimeSpan = new TimeSpan((long)(randomizer.NextDouble() * range.Ticks));
                value = DateTime.MinValue + randTimeSpan;
                break;

            case "System.Collections.Generic.ICollection`1[Microsoft.Qwiq.ILink]":
                var retval = new List <ILink>();
                value = retval;
                break;

            case "System.Uri":
                var c = "ABCDEFGHIJKLMNOPQRSTUVWXYZ/";
                value =
                    new Uri(
                        "http://tempuri.org/"
                        + new string(
                            Enumerable.Repeat(c, randomizer.Next(5, 250))
                            .Select(s => s[randomizer.Next(s.Length)])
                            .ToArray()));
                break;

            case "Microsoft.Qwiq.IWorkItemType":
                value = new MockWorkItemType("Baz");
                break;

            case "System.Object":
                value = new object();
                break;

            default:
                Trace.TraceInformation($"{propertyType.ToString()} is an unrecognized type. Create new instance of System.Object");
                value = new object();
                break;
            }
            return(value);
        }
示例#2
0
        public override void Given()
        {
            var wit = new MockWorkItemType("Baz", WorkItemBackingStore.Keys);

            var related = new MockWorkItemLinkType("NS.SampleLink", true, "Taker", "Giver");

            WorkItemStore = new MockWorkItemStore().Add(
                new[]
            {
                new MockWorkItem(wit)
                {
                    Id = 233
                },
                new MockWorkItem(wit)
                {
                    Id = 144
                }
            }
                ).WithLinkType(related);



            var links = new ILink[]
            {
                new MockRelatedLink(related.ForwardEnd, 0, 233),
                new MockRelatedLink(related.ReverseEnd, 0, 144)
            };

            SourceWorkItems = new IWorkItem[]
            {
                new MockWorkItem(wit, WorkItemBackingStore)
                {
                    Links = new Collection <ILink>(links)
                }
            };

            base.Given();
        }