Ejemplo n.º 1
0
        public ResponseBag <CompetitionBizDto> StartCompetition(IList <Movie> selectedMovies)
        {
            var dto = new CompetitionBizDto {
                SelectedMovies = selectedMovies
            };

            var validations = _bizValidationFactory.Create();

            foreach (var validation in validations)
            {
                var result = validation.Validate(dto);
                if (!result.IsValid)
                {
                    return(new ResponseBag <CompetitionBizDto>
                    {
                        Ok = false,
                        Message = string.Join(", ", result.Errors)
                    });
                }
            }

            var rules = _bizRuleFactory.Create();

            foreach (var rule in rules)
            {
                rule.Execute(dto);
            }

            return(new ResponseBag <CompetitionBizDto>
            {
                Ok = true,
                ObjectResponse = dto
            });
        }
Ejemplo n.º 2
0
        public void should_separate_list_into_four_groups()
        {
            _mockPhase.SetupSequence(mock => mock.Dispute(It.IsAny <IEnumerable <GroupDto> >()))
            .Returns(_getGroups(4));

            var dto = new CompetitionBizDto {
                SelectedMovies = _getMovies()
            };

            _rule.Execute(dto);
            Assert.NotNull(dto.GroupPhase);
            Assert.Equal(4, dto.GroupPhase.Count);
            Assert.Equal(4, dto.QuarterFinals.Count);
            Assert.Equal("Grupo A", dto.GroupPhase[0].Name);
            Assert.Equal("Grupo B", dto.GroupPhase[1].Name);
            Assert.Equal("Grupo C", dto.GroupPhase[2].Name);
            Assert.Equal("Grupo D", dto.GroupPhase[3].Name);
            Assert.Equal("Filme 01", dto.GroupPhase.First().Movies.First().PrimaryTitle);
            Assert.Equal("Filme 16", dto.GroupPhase.Last().Movies.Last().PrimaryTitle);

            foreach (var group in dto.GroupPhase)
            {
                Assert.Equal(4, group.Movies.Count());
            }
        }
        public void validation_test(int amount, bool isValid)
        {
            var dto = new CompetitionBizDto();

            for (int i = 0; i < amount; i++)
            {
                dto.SelectedMovies.Add(new Movie());
            }

            var result = _validation.Validate(dto);

            Assert.NotNull(result);
            Assert.Equal(isValid, result.IsValid);
        }