コード例 #1
0
        // создание объектов
        private static void CreateObjects(IFaker faker)
        {
            ClassA a = faker.Create <ClassA>();

            objectList.Add(a);
            ClassB b = faker.Create <ClassB>();

            objectList.Add(b);
            ClassC c = faker.Create <ClassC>();

            objectList.Add(c);
            ClassD d = faker.Create <ClassD>();

            objectList.Add(d);
            ClassE e = faker.Create <ClassE>();

            objectList.Add(e);
            ClassF f = faker.Create <ClassF>();

            objectList.Add(f);
            ClassG g = faker.Create <ClassG>();

            objectList.Add(g);
            ClassH h = faker.Create <ClassH>();

            objectList.Add(h);
            ClassI i = faker.Create <ClassI>();

            objectList.Add(i);
        }
コード例 #2
0
        /// <summary>Initializes a new instance of the <see cref="RandomizerChainer"/> class.</summary>
        /// <param name="faker">Provides stubs.</param>
        /// <param name="gen">Value generator to use for base randomization.</param>
        /// <param name="randomizer">Callback to the randomizer to create child values.</param>
        public RandomizerChainer(IFaker faker, IRandom gen, Func <Type, RandomizerChainer, object> randomizer)
        {
            _faker      = faker ?? throw new ArgumentNullException(nameof(faker));
            Gen         = gen ?? throw new ArgumentNullException(nameof(gen));
            _randomizer = randomizer ?? throw new ArgumentNullException(nameof(randomizer));

            _history = new Dictionary <Type, object>();
            Parent   = null;
        }
コード例 #3
0
ファイル: MockExtensions.cs プロジェクト: xwagner2/eXpand
        //        public static TypesInfo WCTypesInfo(this IFaker faker) {
        //            Isolate.WhenCalled(() => TypesInfo.Instance).WillReturn(Isolate.Fake.Instance<TypesInfo>());
        //            var typesInfo = TypesInfo.Instance;
        //
        //            Isolate.WhenCalled(() => typesInfo.ExtendedCoreMemberInfoType).WillReturn(typeof (ExtendedCoreTypeMemberInfo));
        //            Isolate.WhenCalled(() => typesInfo.ExtendedCoreMemberInfoType).WillReturn(typeof (ExtendedCoreTypeMemberInfo));
        //            Isolate.WhenCalled(() => typesInfo.ExtendedReferenceMemberInfoType).WillReturn(typeof (ExtendedReferenceMemberInfo));
        //            Isolate.WhenCalled(() => typesInfo.ExtendedCollectionMemberInfoType).WillReturn(typeof (ExtendedCollectionMemberInfo));
        //            Isolate.WhenCalled(() => typesInfo.PersistentAssemblyInfoType).WillReturn(typeof (PersistentAssemblyInfo));
        //            Isolate.WhenCalled(() => typesInfo.PersistentCoreTypeInfoType).WillReturn(typeof (PersistentCoreTypeMemberInfo));
        //            Isolate.WhenCalled(() => typesInfo.PersistentClassInfoInfoType).WillReturn(typeof (PersistentClassInfo));
        //            Isolate.WhenCalled(() => typesInfo.PersistentCollectionInfoType).WillReturn(typeof(PersistentCollectionMemberInfo));
        //            Isolate.WhenCalled(() => typesInfo.CodeTemplateInfoType).WillReturn(typeof (CodeTemplateInfo));
        //            Isolate.WhenCalled(() => typesInfo.PersistentReferenceInfoType).WillReturn(typeof (PersistentReferenceMemberInfo));
        //            Isolate.WhenCalled(() => typesInfo.CodeTemplateType).WillReturn(typeof (CodeTemplate));
        //            Isolate.WhenCalled(() => typesInfo.TemplateInfoType).WillReturn(typeof (TemplateInfo));
        //            Isolate.WhenCalled(() => typesInfo.IntefaceInfoType).WillReturn(typeof (InterfaceInfo));
        //            Isolate.WhenCalled(() => typesInfo.PersistentAssociationAttributeType).WillReturn(typeof (PersistentAssociationAttribute));
        //            Isolate.WhenCalled(() => typesInfo.PersistentDefaultClassOptionsAttributeType).WillReturn(typeof (PersistentDefaultClassOptionsAttribute));
        //
        //            return typesInfo;
        //        }
        public static TypesInfo IOTypesInfo(this IFaker faker)
        {
            Isolate.WhenCalled(() => TypesInfo.Instance).WillReturn(Isolate.Fake.Instance <TypesInfo>());
            var typesInfo = TypesInfo.Instance;

            Isolate.WhenCalled(() => typesInfo.SerializationConfigurationType).WillReturn(typeof(SerializationConfiguration));
            Isolate.WhenCalled(() => typesInfo.ClassInfoGraphNodeType).WillReturn(typeof(ClassInfoGraphNode));



            return(typesInfo);
        }
コード例 #4
0
        public object GenerateCollection(Type elementType, IFaker faker)
        {
            List <string> list = new List <string>();

            int elementCount = random.Next(MIN_LENGTH, MAX_LENGTH + 1);

            for (int i = 0; i < elementCount; i++)
            {
                list.Add("dog");
            }
            return(list);
        }
コード例 #5
0
ファイル: ListGenerator.cs プロジェクト: aliailiyna/Faker
        public object GenerateCollection(Type elementType, IFaker faker)
        {
            Type  genericListType = typeof(List <>).MakeGenericType(elementType);
            IList list            = (IList)Activator.CreateInstance(genericListType);

            int elementCount = random.Next(MIN_LENGTH, MAX_LENGTH + 1);

            for (int i = 0; i < elementCount; i++)
            {
                list.Add(faker.Create(elementType));
            }
            return(list);
        }
コード例 #6
0
        /// <summary>Initializes a new instance of the <see cref="Randomizer"/> class.</summary>
        /// <param name="faker">Provides stubs.</param>
        /// <param name="gen">Value generator to use for base randomization.</param>
        /// <param name="includeDefaultHints">If the default set of hints should be added.</param>
        /// <param name="hints">Generators used to randomize specific types.</param>
        /// <param name="limiter">Limits attempts at matching conditions.</param>
        public Randomizer(IFaker faker, IRandom gen, Limiter limiter,
                          bool includeDefaultHints = true, params CreateHint[] hints)
        {
            _faker   = faker ?? throw new ArgumentNullException(nameof(faker));
            _gen     = gen ?? throw new ArgumentNullException(nameof(gen));
            _limiter = limiter ?? throw new ArgumentNullException(nameof(limiter));

            IEnumerable <CreateHint> inputHints = hints ?? Enumerable.Empty <CreateHint>();

            _hints = (includeDefaultHints)
                ? inputHints.Concat(_DefaultHints).ToList()
                : inputHints.ToList();
        }
コード例 #7
0
ファイル: MockExtensions.cs プロジェクト: xwagner2/eXpand
        public static void XafApplicationInstance(this IFaker faker, Action <XafApplication> action, Func <IList <Type> > func, Action <DetailView> viewAction, Action <Window> windowAction, params Controller[] controllers)
        {
            var            dataSet       = new DataSet();
            IObjectSpace   XPObjectSpace = ObjectSpaceInMemory.CreateNew(dataSet);
            XafApplication application   = Isolate.Fake.XafApplicationInstance(func, dataSet, controllers);

            action.Invoke(application);
            application.ShowViewStrategy = new MdiShowViewStrategy(application);
            object o          = XPObjectSpace.CreateObject(func.Invoke().ToList().First());
            var    detailView = application.CreateDetailView(XPObjectSpace, o);

            viewAction.Invoke(detailView);
            var window = application.CreateWindow(TemplateContext.View, controllers, true);

            windowAction.Invoke(window);
            window.SetView(detailView);
        }
コード例 #8
0
        /// <summary>Initializes a new instance of the <see cref="RandomizerChainer"/> class.</summary>
        /// <param name="prevChainer">Previous chainer to build upon.</param>
        /// <param name="parent">Container of the instance to create.</param>
        private RandomizerChainer(RandomizerChainer prevChainer, object parent)
        {
            Parent      = parent;
            Gen         = prevChainer.Gen;
            _faker      = prevChainer._faker;
            _randomizer = prevChainer._randomizer;

            if (parent != null)
            {
                _history = prevChainer._history
                           .Append(new KeyValuePair <Type, object>(parent.GetType(), parent))
                           .ToDictionary(p => p.Key, p => p.Value);
            }
            else
            {
                _history = prevChainer._history;
            }
        }
コード例 #9
0
        public void CreateGeneticTest()
        {
            var mock = new Mock <IFaker>();

            mock.Setup(a => a.Create <List <string> >()).Returns(new List <string>());

            IFaker        mockFaker = mock.Object;
            List <string> actual    = mockFaker.Create <List <string> >();

            if ((actual != null) && (!actual.Any()))
            {
                logger.Info("CreateGeneticTest compled succesfully: object are empty");
            }
            else
            {
                logger.Info("CreateGeneticTest compled not succesfully: object are't empty or null");
            }
            Assert.IsEmpty(actual);
        }
コード例 #10
0
ファイル: MockExtensions.cs プロジェクト: xwagner2/eXpand
        public static ISecurityComplex ISecurityComplex(this IFaker faker)
        {
            var securityComplex = Isolate.Fake.Instance <ISecurityComplex>();

            Isolate.WhenCalled(() => SecuritySystem.Instance).WillReturn(securityComplex);
            Isolate.WhenCalled(() => ((IRoleTypeProvider)securityComplex).RoleType).WillReturn(typeof(Role));
            Isolate.WhenCalled(() => securityComplex.UserType).WillReturn(typeof(User));

            Isolate.Fake.StaticMethods(typeof(SecuritySystem));
            Isolate.WhenCalled(() => SecuritySystem.UserType).WillReturn(typeof(User));

            var user = new User(Session.DefaultSession);

            user.Save();
            Isolate.WhenCalled(() => SecuritySystem.CurrentUser).WillReturn(user);

            XafTypesInfo.Instance.RegisterEntity(((IRoleTypeProvider)securityComplex).RoleType);
            XafTypesInfo.Instance.RegisterEntity(securityComplex.UserType);
            return(securityComplex);
        }
コード例 #11
0
        public void CreateRecTest()
        {
            var mock = new Mock <IFaker>();

            mock.Setup(a => a.Create <Rec1>()).Returns(new Rec1());

            IFaker mockFaker = mock.Object;
            Rec2   expected  = null;
            Rec2   actual    = mockFaker.Create <Rec1>().A;

            if (expected == actual)
            {
                logger.Info("CreateRecTest compled succesfully: object are equal");
            }
            else
            {
                logger.Info("CreateRecTest compled not succesfully: object are't equal");
            }
            Assert.AreEqual(expected, actual);
        }
コード例 #12
0
        public void CreateIntTest()
        {
            var mock = new Mock <IFaker>();

            mock.Setup(a => a.Create <int>()).Returns(15);

            IFaker mockFaker = mock.Object;
            int    expected  = 15;
            int    actual    = mockFaker.Create <int>();

            if (expected == actual)
            {
                logger.Info("CreateIntTest compled succesfully: object are equal");
            }
            else
            {
                logger.Info("CreateIntTest compled not succesfully: object are't equal");
            }
            Assert.AreEqual(expected, actual);
        }
コード例 #13
0
        public object Generate(GeneratorContext context)
        {
            if (context.Faker.fillContext.Contains(context.TargetType))
            {
                return(null);
            }

            if (!context.TargetType.IsPrimitive)
            {
                context.Faker.fillContext.Add(context.TargetType);
            }

            gen = context.Faker;
            object result = FillObject(context.TargetType);

            if (!context.TargetType.IsPrimitive)
            {
                context.Faker.fillContext.RemoveAt(context.Faker.fillContext.Count - 1);
            }
            return(result);
        }
コード例 #14
0
        public static void Main(string[] args)
        {
            // FakerConfig
            fakerConfig = new FakerConfig();

            // Настройка генерируемых случайных значений для конкретного поля
            // путем передачи собственного генератора для конкретного поля/свойства
            ConfigFaker();

            // Faker
            faker = new Faker(fakerConfig);

            // создание объектов
            CreateObjects(faker);

            // вывод объектов
            OutputObjects();

            // ожидание ввода
            Console.ReadLine();
        }
コード例 #15
0
ファイル: MockExtensions.cs プロジェクト: xwagner2/eXpand
        public static XafApplication XafApplicationInstance(this IFaker faker, Func <IList <Type> > func, DataSet dataSet, params Controller[] controllers)
        {
            var defaultSkinListGenerator = Isolate.Fake.Instance <DefaultSkinListGenerator>();
            var editorsFactory           = new EditorsFactory();

#pragma warning disable 612,618
            Isolate.WhenCalled(() => editorsFactory.CreateListEditor(null, null, null)).WillReturn(new GridListEditor(null));
#pragma warning restore 612,618
            Isolate.Swap.AllInstances <EditorsFactory>().With(editorsFactory);

            Isolate.Swap.NextInstance <DefaultSkinListGenerator>().With(defaultSkinListGenerator);
            var application = Isolate.Fake.Instance <XpandWinApplication>();
            RegisterControllers(application, controllers);
            //            var xpandModuleBase = Isolate.Fake.Instance<XpandModuleBase>(Members.CallOriginal, ConstructorWillBe.Called);
            //            xpandModuleBase.Setup(application);
            var XPObjectSpaceProvider = Isolate.Fake.Instance <IObjectSpaceProvider>();
            Isolate.WhenCalled(() => XPObjectSpaceProvider.TypesInfo).WillReturn(XafTypesInfo.Instance);
            application.CreateCustomObjectSpaceProvider += (sender, args) => args.ObjectSpaceProvider = XPObjectSpaceProvider;
            RegisterDomainComponents(application, func);
            application.Setup();
            Isolate.WhenCalled(() => application.CreateObjectSpace()).WillReturn(ObjectSpaceInMemory.CreateNew(dataSet));

            return(application);
        }
コード例 #16
0
ファイル: ArrayGenerator.cs プロジェクト: maxnevans/Faker
 public ArrayGenerator(IFaker faker, Type arrayType)
 {
     this.faker     = faker;
     this.arrayType = arrayType;
 }
コード例 #17
0
 public GeneratorContext(Random random, Type targetType, IFaker faker)
 {
     Random     = random;
     TargetType = targetType;
     Faker      = faker;
 }
コード例 #18
0
ファイル: IFaker.cs プロジェクト: maxnevans/Faker
        public static T Create <T>(this IFaker faker)
        {
            var type = typeof(T);

            return((T)faker.Create(type));
        }