static void Main()
        {
            Console.WriteLine("The list Contains: {0}", string.Join(" ", numbers));

            Console.WriteLine("\n1.How many ints are there? {0}", _listService.Count(numbers));

            Console.WriteLine("\n2.Sum of all ints? {0}", _listService.Sum(numbers));

            Console.WriteLine("\n3.Average of all ints? {0}", _listService.Average(numbers));

            Console.WriteLine("\n4.What is the number at position 2? {0}", _listService.ValueAt(numbers, 2));

            Console.WriteLine("\n5.What is the position for 4? {0}", _listService.GetPosition(numbers, 4));

            Console.WriteLine("\n6.Exclude all ints larger than 3? {0}", string.Join(" ", _listService.RemoveLargerThan(numbers, 3)));

            Console.WriteLine("\n7.Make one big int out of all the ints? {0}", _listService.BigInt(numbers));

            Console.WriteLine("\n8.Ints where next int is even? {0}", string.Join(" ", _listService.NextIsEven(numbers)));

            Console.WriteLine("\n9.Replace each int with sum of previous and next value? {0}", string.Join(" ", _listService.NextIsEven(numbers)));

            Console.WriteLine("\n10.Reverse order of elements? {0}", string.Join(" ", _listService.Reverse(numbers)));

            Console.WriteLine("\n11.What is the diff between ints and subSet? {0}", string.Join(" ", _listService.Difference(numbers, new List <long> {
                1, 5
            })));

            Console.ReadKey();
        }
Example #2
0
        public CreateListValidator(IListService listService)
        {
            RuleFor(dto => dto.UserId)
            .NotEmpty().WithMessage("Unauthorized")
            .Must((dto, userId) => !listService.Exists(dto.Name, userId)).WithMessage("AlreadyExists")
            .Must((dto, userId) => listService.Count(userId) < 50).WithMessage("Lists.ListLimitReached");

            RuleFor(dto => dto.Name)
            .NotEmpty().WithMessage("Lists.ModifyList.NameIsRequired")
            .MaximumLength(50).WithMessage("Lists.ModifyList.NameMaxLength");

            RuleFor(dto => dto.Icon)
            .NotEmpty().WithMessage("Lists.ModifyList.IconIsRequired")
            .Must(icon => ListIcons.Contains(icon)).WithMessage("Lists.ModifyList.InvalidIcon");

            RuleFor(dto => dto.TasksText).Must(tasksText =>
            {
                if (string.IsNullOrEmpty(tasksText))
                {
                    return(true);
                }
                var tasks = tasksText.Split("\n").Where(x => !string.IsNullOrWhiteSpace(x));
                return(tasks.Any());
            }).WithMessage("Lists.CreateList.NoTasks").Must(tasksText =>
            {
                if (string.IsNullOrEmpty(tasksText))
                {
                    return(true);
                }
                var tasks      = tasksText.Split("\n").Where(x => !string.IsNullOrWhiteSpace(x));
                var duplicates = tasks.GroupBy(x => x).Where(g => g.Count() > 1).Select(y => y.Key).ToList();
                return(!duplicates.Any());
            }).WithMessage("Lists.CreateList.DuplicateTasks").Must(tasksText =>
            {
                if (string.IsNullOrEmpty(tasksText))
                {
                    return(true);
                }
                var tasks = tasksText.Split("\n").Where(x => !string.IsNullOrWhiteSpace(x));
                return(tasks.Count() < 250);
            }).WithMessage("TasksPerListLimitReached").Must(tasksText =>
            {
                if (string.IsNullOrEmpty(tasksText))
                {
                    return(true);
                }
                var tasks = tasksText.Split("\n").Where(x => !string.IsNullOrWhiteSpace(x) && x.Length > 50);
                return(!tasks.Any());
            }).WithMessage("Lists.CreateList.TasksNameMaxLength");
        }
        public CopyListValidator(IListService listService)
        {
            RuleFor(dto => dto.UserId)
            .NotEmpty().WithMessage("Unauthorized")
            .Must((dto, userId) => listService.UserOwnsOrShares(dto.Id, userId)).WithMessage("Unauthorized")
            .Must((dto, userId) => !listService.Exists(dto.Name, userId)).WithMessage("AlreadyExists")
            .Must(userId => listService.Count(userId) < 50).WithMessage("Lists.ListLimitReached");

            RuleFor(dto => dto.Name)
            .NotEmpty().WithMessage("Lists.ModifyList.NameIsRequired")
            .MaximumLength(50).WithMessage("Lists.ModifyList.NameMaxLength");

            RuleFor(dto => dto.Icon)
            .NotEmpty().WithMessage("Lists.ModifyList.IconIsRequired")
            .Must(icon => ListIcons.Contains(icon)).WithMessage("Lists.ModifyList.InvalidIcon");
        }
        public void Test1_HowManyIntsAreThere()
        {
            var count = _listService.Count(numbers);

            Assert.AreEqual(count, 6);
        }