示例#1
0
        public void GetById_invokes_ProcessQueryAsync_on_mediator_passing_GetCategoryByIdQuery_with_correct_data()
        {
            var categoryId = AnonymousData.Int();
            var response   = _controller.Get(categoryId);

            _mediatorMock.Verify(sm => sm.ProcessQueryAsync(It.Is <GetCategoryByIdQuery>(c =>
                                                                                         c.CategoryId == categoryId
                                                                                         )), Times.Once);
        }
示例#2
0
        public static Person AnyMalePerson(this AnonymousData anon)
        {
            if (anon == null)
            {
                throw new ArgumentNullException(nameof(anon));
            }

            return(new Person(anon.AnyFirstName(true), anon.AnySurname()));
        }
示例#3
0
        public void FullName_ShouldBeCalculated()
        {
            var anon     = new AnonymousData();
            var employee = anon.Any <Employee>();

            var fullName = employee.FullName;

            Assert(fullName).IsEqualTo($"{employee.LastName}, {employee.FirstName}");
        }
示例#4
0
        public void FullName_ShouldBeCalculated()
        {
            var anon = new AnonymousData();

            anon.Register <Person>(f => new Person(f.AnyFirstName(), f.AnySurname()));
            var person = anon.Any <Person>();

            var fullName = person.FullName;

            Assert(fullName).IsEqualTo($"{person.LastName}, {person.FirstName}");
        }
示例#5
0
        public void Map_ShouldMapFullName()
        {
            var anon = new AnonymousData();
            var dto  = anon.Any <EmployeeDto>();

            anon.Populate(dto);
            var mapper = new Mapper();

            var employee = mapper.Map <Employee>(dto);

            Assert(employee.FullName).IsEqualTo($"{dto.LastName}, {dto.FirstName}");
        }
        public void AnyDecimal_MinMax()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <decimal>();

            classifier.AddClassification("GT", d => d > 0);
            classifier.AddClassification("LT", d => d < 0);

            classifier.Classify(() => anon.AnyDecimal(decimal.MinValue, decimal.MaxValue));

            Assert.True(classifier["GT"] > 0.4);
            Assert.True(classifier["LT"] > 0.4);
        }
        public void AnyDecimal_Distribution()
        {
            var anon       = new AnonymousData();
            var classifier = new Classifier <decimal>();

            classifier.AddClassification("GT", d => d > 0);
            classifier.AddClassification("LT", d => d < 0);

            classifier.Classify(() => anon.AnyDecimal(Distribution.Uniform));

            Assert.True(classifier["GT"] > 0.4);
            Assert.True(classifier["LT"] > 0.4);
        }
示例#8
0
        public void IndexOf_ItemInList_ShouldReturnIndex()
        {
            var item  = 10;
            var anon  = new AnonymousData();
            var front = anon.AnyEnumerable <int>().ToArray();
            var back  = anon.AnyEnumerable <int>().ToArray();
            var list  = new List <int>(front);

            list.Add(item);
            list.AddRange(back);

            var index = list.IndexOf(item);

            Assert(index).IsEqualTo(front.Length);
        }
示例#9
0
        public void When_invoking_Build_passing_depth_2_Should_generate_default_valid_Transaction_CategoryId_Category_and_Transactions_in_Category()
        {
            var expectedNumberOfChildEntitiesInCollection = AnonymousData.Int(1);
            var builder = new Builder <Category>
            {
                NumberOfNestedEntitiesInCollections = expectedNumberOfChildEntitiesInCollection
            };

            var category = builder.Build(1);

            Assert.IsNotNull(category);
            Assert.IsNotNull(category.Transactions);
            Assert.IsNotNull(category.Transactions.Count == expectedNumberOfChildEntitiesInCollection);
            category.Transactions.ToList().ForEach(t => {
                Assert.IsNotNull(t);
                Assert.IsNull(t.Category);
                Assert.IsTrue(t.CategoryId > 0);
                Assert.IsTrue(t.Id > 0);
                Assert.IsTrue(t.Credit > 0);
                Assert.IsTrue(t.Debit > 0);
                Assert.IsTrue(!string.IsNullOrWhiteSpace(t.Description));
            });
        }
示例#10
0
 public MoqCustomizationTests()
 {
     anon = new AnonymousData();
     anon.Customize(new MoqCustomization());
 }
示例#11
0
        protected virtual object GenerateAnonymousData(object entity, Type propertyType, string propertyName, int hierarchyDepth)
        {
            if (propertyType == typeof(string))
            {
                return(AnonymousData.String(propertyName));
            }

            if (propertyType == typeof(sbyte) || propertyType == typeof(byte) || propertyType == typeof(Byte) || propertyType == typeof(SByte))
            {
                return(AnonymousData.Byte());
            }

            if (propertyType == typeof(short) || propertyType == typeof(ushort) || propertyType == typeof(Int16) || propertyType == typeof(UInt16))
            {
                return(AnonymousData.Short());
            }

            if (propertyType == typeof(int) || propertyType == typeof(uint) || propertyType == typeof(Int32) || propertyType == typeof(UInt32))
            {
                return(AnonymousData.Int(3, false));
            }

            if (propertyType == typeof(long) || propertyType == typeof(ulong) || propertyType == typeof(Int64) || propertyType == typeof(UInt64))
            {
                return(AnonymousData.Long());
            }

            if (propertyType == typeof(double) || propertyType == typeof(Double))
            {
                return(AnonymousData.Double());
            }

            if (propertyType == typeof(decimal) || propertyType == typeof(Decimal))
            {
                return(AnonymousData.Decimal());
            }

            if (propertyType == typeof(float) || propertyType == typeof(Single))
            {
                return(AnonymousData.Float());
            }

            if (propertyType == typeof(char) || propertyType == typeof(Char))
            {
                return(AnonymousData.Char());
            }

            if (propertyType == typeof(DateTime))
            {
                return(AnonymousData.DateTime());
            }

            if (propertyType == typeof(TimeSpan))
            {
                return(AnonymousData.TimeSpan());
            }

            if (propertyType.IsValueType)
            {
                return(Activator.CreateInstance(propertyType));
            }

            if (hierarchyDepth > 0 && propertyType.IsGenericType && typeof(IEnumerable).IsAssignableFrom(propertyType))
            {
                var genericTypeArgument = propertyType.GenericTypeArguments.FirstOrDefault();
                if (!genericTypeArgument.IsClass || genericTypeArgument.IsGenericType)
                {
                    return(null);
                }
                var listOfChildEntities = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(genericTypeArgument));

                try
                {
                    for (var i = 1; i <= NumberOfNestedEntitiesInCollections; i++)
                    {
                        var childEntity = GenerateAnonymousDateForChildEntityObject(null, genericTypeArgument, propertyName, hierarchyDepth);
                        listOfChildEntities.Add(childEntity);
                    }
                    return(listOfChildEntities);
                }
                catch (Exception)
                {
                    return((IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(genericTypeArgument)));
                }
            }

            if (hierarchyDepth > 0 && propertyType.IsClass && !propertyType.IsGenericType)
            {
                return(GenerateAnonymousDateForChildEntityObject(entity, propertyType, propertyName, hierarchyDepth));
            }

            return(null);
        }
示例#12
0
 // Use whatever the appropriate "assembly initialize" logic your
 // unit test framework uses.
 static RegisterDefaultExample()
 {
     AnonymousData.RegisterDefault <Employee>(
         anon => new Employee(anon.AnyFirstName(), anon.AnySurname(), anon.AnyBool()));
 }