Beispiel #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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public object Create()
        {
            Random random = new Random();

            var elementType = arrayType.GetElementType();

            if (elementType == null)
            {
                return(null);
            }

            var length = random.Next(0, 9);
            var result = Array.CreateInstance(elementType, length);

            for (var i = 0; i < length; i++)
            {
                var item = faker.Create(elementType);
                result.SetValue(item, i);
            }

            return(result);
        }
Beispiel #7
0
        public static T Create <T>(this IFaker faker)
        {
            var type = typeof(T);

            return((T)faker.Create(type));
        }
Beispiel #8
0
        public void CreatePrimitive()
        {
            var actual = _faker.Create <int>();

            Assert.GreaterOrEqual(actual, 0);
        }