public List <Card> Draw(CollectionDirection direction, string hash, int count = 1)
        {
            var deck       = repository.GetDeck(hash);
            var drawnCards = cardsHelper.Draw(direction, deck.Cards, count);

            repository.Update(deck);

            return(drawnCards);
        }
        public RedirectorQuery WithArtist(Artist value = null,
                                          ArgumentEvaluationMode mode   = ArgumentEvaluationMode.IgnoreNeutral,
                                          CollectionOperator @operator  = CollectionOperator.Equal,
                                          CollectionDirection direction = CollectionDirection.Any)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case CollectionOperator.Equal:
                switch (direction)
                {
                case CollectionDirection.Any:
                    Entities = Entities.Where(r => r.Artists.Any(a => a == value));
                    return(this);

                case CollectionDirection.All:
                    Entities = Entities.Where(r => r.Artists.All(a => a == value));
                    return(this);

                default:
                    throw new NotSupportedEnumException(direction);
                }

            case CollectionOperator.NotEqual:
                switch (direction)
                {
                case CollectionDirection.Any:
                    Entities = Entities.Where(r => r.Artists.Any(a => a != value));
                    return(this);

                case CollectionDirection.All:
                    Entities = Entities.Where(r => r.Artists.All(a => a != value));
                    return(this);

                default:
                    throw new NotSupportedEnumException(direction);
                }

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
Exemple #3
0
        public CategoryQuery WithNews(News value = null,
                                      ArgumentEvaluationMode mode   = ArgumentEvaluationMode.IgnoreNeutral,
                                      CollectionOperator @operator  = CollectionOperator.Equal,
                                      CollectionDirection direction = CollectionDirection.Any)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case CollectionOperator.Equal:
                switch (direction)
                {
                case CollectionDirection.Any:
                    Entities = Entities.Where(c => c.News.Any(n => n == value));
                    return(this);

                case CollectionDirection.All:
                    Entities = Entities.Where(c => c.News.All(n => n == value));
                    return(this);

                default:
                    throw new NotSupportedEnumException(direction);
                }

            case CollectionOperator.NotEqual:
                switch (direction)
                {
                case CollectionDirection.Any:
                    Entities = Entities.Where(c => c.News.Any(n => n != value));
                    return(this);

                case CollectionDirection.All:
                    Entities = Entities.Where(c => c.News.All(n => n != value));
                    return(this);

                default:
                    throw new NotSupportedEnumException(direction);
                }

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
Exemple #4
0
        public ArtistQuery WithComposedTrackId(long?value = null,
                                               ArgumentEvaluationMode mode   = ArgumentEvaluationMode.IgnoreNeutral,
                                               CollectionOperator @operator  = CollectionOperator.Equal,
                                               CollectionDirection direction = CollectionDirection.Any)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case CollectionOperator.Equal:
                switch (direction)
                {
                case CollectionDirection.Any:
                    Entities = Entities.Where(a => a.ComposedTracks.Any(t => t.Id == value));
                    return(this);

                case CollectionDirection.All:
                    Entities = Entities.Where(a => a.ComposedTracks.All(t => t.Id == value));
                    return(this);

                default:
                    throw new NotSupportedEnumException(direction);
                }

            case CollectionOperator.NotEqual:
                switch (direction)
                {
                case CollectionDirection.Any:
                    Entities = Entities.Where(a => a.ComposedTracks.Any(t => t.Id != value));
                    return(this);

                case CollectionDirection.All:
                    Entities = Entities.Where(a => a.ComposedTracks.All(t => t.Id != value));
                    return(this);

                default:
                    throw new NotSupportedEnumException(direction);
                }

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
Exemple #5
0
        public PollChoiceQuery WithItem(PollChoiceItem value          = null,
                                        ArgumentEvaluationMode mode   = ArgumentEvaluationMode.IgnoreNeutral,
                                        CollectionOperator @operator  = CollectionOperator.Equal,
                                        CollectionDirection direction = CollectionDirection.Any)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case CollectionOperator.Equal:
                switch (direction)
                {
                case CollectionDirection.Any:
                    Entities = Entities.Where(pc => pc.Items.Any(pci => pci == value));
                    return(this);

                case CollectionDirection.All:
                    Entities = Entities.Where(pc => pc.Items.All(pci => pci == value));
                    return(this);

                default:
                    throw new NotSupportedEnumException(direction);
                }

            case CollectionOperator.NotEqual:
                switch (direction)
                {
                case CollectionDirection.Any:
                    Entities = Entities.Where(pc => pc.Items.Any(pci => pci != value));
                    return(this);

                case CollectionDirection.All:
                    Entities = Entities.Where(pc => pc.Items.All(pci => pci != value));
                    return(this);

                default:
                    throw new NotSupportedEnumException(direction);
                }

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
        public ResourceKeyQuery WithValueId(long?value = null,
                                            ArgumentEvaluationMode mode   = ArgumentEvaluationMode.IgnoreNeutral,
                                            CollectionOperator @operator  = CollectionOperator.Equal,
                                            CollectionDirection direction = CollectionDirection.Any)
        {
            switch (mode)
            {
            case ArgumentEvaluationMode.IgnoreNeutral:
                if (Neutrals.Is(value))
                {
                    return(this);
                }
                break;

            case ArgumentEvaluationMode.Explicit:
                break;

            default:
                throw new NotSupportedEnumException(mode);
            }

            switch (@operator)
            {
            case CollectionOperator.Equal:
                switch (direction)
                {
                case CollectionDirection.Any:
                    Entities = Entities.Where(rk => rk.Values.Any(rv => rv.Id == value));
                    return(this);

                case CollectionDirection.All:
                    Entities = Entities.Where(rk => rk.Values.All(rv => rv.Id == value));
                    return(this);

                default:
                    throw new NotSupportedEnumException(direction);
                }

            case CollectionOperator.NotEqual:
                switch (direction)
                {
                case CollectionDirection.Any:
                    Entities = Entities.Where(rk => rk.Values.Any(rv => rv.Id != value));
                    return(this);

                case CollectionDirection.All:
                    Entities = Entities.Where(rk => rk.Values.All(rv => rv.Id != value));
                    return(this);

                default:
                    throw new NotSupportedEnumException(direction);
                }

            default:
                throw new NotSupportedEnumException(@operator);
            }
        }
Exemple #7
0
        public List <Card> Draw(CollectionDirection direction, string hash, string pileHash, int count)
        {
            var deck       = _deckRepository.GetDeck(hash);
            var pile       = deck.Piles.FirstOrDefault(x => x.Hash == pileHash);
            var drawnCards = _cardsHelper.Draw(direction, pile.Cards, count);

            _deckRepository.Update(deck);

            return(drawnCards);
        }
Exemple #8
0
 public List <Card> Insert(CollectionDirection direction, List <Card> cards, Card cardToInsert)
 {
     if (direction == CollectionDirection.Top)
     {
         cards.Insert(0, cardToInsert);
     }
     else
     {
         cards.Add(cardToInsert);
     }
     return(cards);
 }
Exemple #9
0
		public TicketDepartmentQuery WithTicketId(long? value = null,
		                                          ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral,
		                                          CollectionOperator @operator = CollectionOperator.Equal,
		                                          CollectionDirection direction = CollectionDirection.Any) {
			switch (mode) {
				case ArgumentEvaluationMode.IgnoreNeutral:
					if (Neutrals.Is(value))
						return this;
					break;

				case ArgumentEvaluationMode.Explicit:
					break;

				default:
					throw new NotSupportedEnumException(mode);
			}

			switch (@operator) {
				case CollectionOperator.Equal:
					switch (direction) {
						case CollectionDirection.Any:
							Entities = Entities.Where(td => td.Tickets.Any(t => t.Id == value));
							return this;

						case CollectionDirection.All:
							Entities = Entities.Where(td => td.Tickets.All(t => t.Id == value));
							return this;

						default:
							throw new NotSupportedEnumException(direction);
					}

				case CollectionOperator.NotEqual:
					switch (direction) {
						case CollectionDirection.Any:
							Entities = Entities.Where(td => td.Tickets.Any(t => t.Id != value));
							return this;

						case CollectionDirection.All:
							Entities = Entities.Where(td => td.Tickets.All(t => t.Id != value));
							return this;

						default:
							throw new NotSupportedEnumException(direction);
					}
				default:
					throw new NotSupportedEnumException(@operator);
			}
		}
        public void Insert_CallsHelperAndRepository(CollectionDirection direction)
        {
            var helperMock     = new Mock <ICardsHelper>();
            var repositoryMock = new Mock <IDeckRepository>();

            repositoryMock.Setup(x => x.GetDeck(It.IsAny <string>()))
            .Returns(new Deck());
            var cardsFactoryMock = new Mock <ICardsFactory>();

            var interractor = new DeckCardsInterractor(repositoryMock.Object, helperMock.Object, cardsFactoryMock.Object);

            interractor.Insert(It.IsAny <string>(), direction, new Card());

            repositoryMock.Verify(x => x.GetDeck(It.IsAny <string>()));
            helperMock.Verify(x => x.Insert(direction, It.IsAny <List <Card> >(), It.IsAny <Card>()));
            repositoryMock.Verify(x => x.Update(It.IsAny <Deck>()));
        }
Exemple #11
0
        public void Draw_TopBottom_WhenCountIsMoreThanAvailable_ReturnsEverything(CollectionDirection direction)
        {
            var cardsHelper = new CardsHelper();
            var cards       = new List <Card>()
            {
                new Card {
                    Name = "X"
                },
                new Card {
                    Name = "Y"
                },
                new Card {
                    Name = "Z"
                }
            };

            var afterDraw = cardsHelper.Draw(direction, cards, 4);

            Assert.That(afterDraw.Count == 3);
        }
Exemple #12
0
        public void Draw_TopBottom_WhenNoParamGiven_DrawsOne(CollectionDirection direction)
        {
            var cardsHelper = new CardsHelper();
            var cards       = new List <Card>()
            {
                new Card {
                    Name = "X"
                },
                new Card {
                    Name = "Y"
                },
                new Card {
                    Name = "Z"
                }
            };

            var afterDraw = cardsHelper.Draw(direction, cards);

            Assert.That(afterDraw.Count == 1);
        }
Exemple #13
0
        public void Draw_TopBottom_MutatesGivenCollection(CollectionDirection direction)
        {
            var cardsHelper = new CardsHelper();
            var cards       = new List <Card>()
            {
                new Card {
                    Name = "X"
                },
                new Card {
                    Name = "Y"
                },
                new Card {
                    Name = "Z"
                }
            };

            var afterDraw = cardsHelper.Draw(direction, cards, 1);

            Assert.That(cards.Count == 2);
        }
        public void Draw_CallsInterractor(string hash, CollectionDirection direction, int count)
        {
            var mapperMock = new Mock <IMapper>();
            var deckCardsInterractorMock = new Mock <IDeckCardsInterractor>();
            var deckRepositoryMock       = new Mock <IDeckRepository>();

            deckRepositoryMock.Setup(x => x.GetDeck(hash)).Returns(new Deck {
                Hash = hash
            });

            var controller = new DeckOperationsController(deckRepositoryMock.Object, mapperMock.Object, deckCardsInterractorMock.Object);
            var request    = new DeckDrawRequest {
                Hash      = hash,
                Direction = direction,
                Count     = count
            };
            var result = controller.Draw(request);

            Assert.IsInstanceOf <OkObjectResult>(result);
            deckCardsInterractorMock.Verify(x => x.Draw(direction, hash, count));
        }
        public void Insert_CallsInterractor(string hash, CollectionDirection direction)
        {
            var mapperMock = new Mock <IMapper>();
            var deckCardsInterractorMock = new Mock <IDeckCardsInterractor>();
            var deckRepositoryMock       = new Mock <IDeckRepository>();

            deckRepositoryMock.Setup(x => x.GetDeck(hash)).Returns(new Deck {
                Hash = hash
            });

            var controller = new DeckOperationsController(deckRepositoryMock.Object, mapperMock.Object, deckCardsInterractorMock.Object);
            var request    = new DeckCardInsertRequest {
                Hash      = hash,
                Direction = direction,
                Card      = It.IsAny <Card>()
            };
            var result = controller.Insert(request);

            Assert.IsInstanceOf <OkResult>(result);
            deckCardsInterractorMock.Verify(x => x.Insert(hash, direction, It.IsAny <Card>()));
        }
Exemple #16
0
        public void Draw_TopBottom_ReturnsProperCards(CollectionDirection direction, string expectedName)
        {
            var cardsHelper = new CardsHelper();
            var cards       = new List <Card>()
            {
                new Card {
                    Name = "X"
                },
                new Card {
                    Name = "Y"
                },
                new Card {
                    Name = "Z"
                }
            };

            var afterDraw = cardsHelper.Draw(direction, cards, 1);

            Assert.That(afterDraw.Count == 1);
            Assert.That(afterDraw[0].Name == expectedName);
        }
Exemple #17
0
        public List <Card> Draw(CollectionDirection direction, List <Card> cards, int count = 1)
        {
            if (count <= 0)
            {
                return(new List <Card>());
            }

            if (count > cards.Count)
            {
                count = cards.Count;
            }

            var toSkip = direction == CollectionDirection.Top ? 0 : cards.Count - count;

            var result = cards
                         .Skip(toSkip)
                         .Take(count)
                         .ToList();

            cards.RemoveRange(0, count);
            return(result);
        }
        public void Insert_CallsInterractor(string hash, CollectionDirection direction)
        {
            PileCardInsertRequest request = new PileCardInsertRequest {
                DeckHash  = hash,
                Direction = direction,
                PileHash  = It.IsAny <string>(),
                Card      = It.IsAny <Card>()
            };
            var pileCardsInterractorMock = new Mock <IPileCardsInterractor>();
            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <CreatePileResponse>(It.IsAny <Pile>()))
            .Returns(new CreatePileResponse());
            var repositoryMock = new Mock <IDeckRepository>();

            repositoryMock.Setup(x => x.GetDeck(request.DeckHash)).Returns(new Deck());
            var hashidsMock = new Mock <IHashids>();
            var controller  = new PileOperationsController(pileCardsInterractorMock.Object, mapperMock.Object, repositoryMock.Object, hashidsMock.Object);

            var response = controller.Insert(request) as OkResult;

            Assert.NotNull(response);
            pileCardsInterractorMock.Verify(x => x.Insert(request.DeckHash, request.PileHash, request.Direction, request.Card));
        }
        public void Insert_CallsHelperAndRepository(CollectionDirection direction)
        {
            var helperMock     = new Mock <ICardsHelper>();
            var repositoryMock = new Mock <IDeckRepository>();

            repositoryMock.Setup(x => x.GetDeck(It.IsAny <string>()))
            .Returns(new Deck {
                Piles = new List <Pile> {
                    new Pile {
                        Hash  = "First",
                        Cards = new List <Card>()
                    }
                }
            });
            var hashidsMock = new Mock <IHashids>();

            var interractor = new PileCardsInterractor(repositoryMock.Object, helperMock.Object, hashidsMock.Object);

            interractor.Insert(It.IsAny <string>(), "First", direction, new Card());

            repositoryMock.Verify(x => x.GetDeck(It.IsAny <string>()));
            helperMock.Verify(x => x.Insert(direction, It.IsAny <List <Card> >(), It.IsAny <Card>()));
            repositoryMock.Verify(x => x.Update(It.IsAny <Deck>()));
        }