Esempio n. 1
0
                public void ThenUpdatesEachCardDataToGateway(int cardDataCount)
                {
                    List <string>            cardDatas     = new List <string>();
                    List <ICard>             cardsToReturn = new List <ICard>();
                    List <IValidationResult> results       = new List <IValidationResult>();

                    for (int i = 0; i < cardDataCount; i++)
                    {
                        cardDatas.Add(Guid.NewGuid().ToString());
                        cardsToReturn.Add(new CardStub(Guid.NewGuid().ToString(), "Title", "Description", "Image",
                                                       new ICardOption[0], "Heavy"));
                        results.Add(new ValidationResult {
                            Valid = true, ValidCardData = cardsToReturn[i]
                        });
                    }

                    IValidCardsData stub = new ValidCardsDataStub(results.ToArray());

                    CardGatewaySpy spy = new CardGatewaySpy(new CardDummy(), true);

                    new AddCards(stub, spy, new PackGatewayDummy(), new IncrementVersionNumberDummy(), new PublishEndPointSpy()).Execute(
                        new string[results.Count]);

                    Assert.True(spy.UpdateCardCalled);
                    foreach (ICard card in spy.UpdateCardsHistory)
                    {
                        Assert.True(cardsToReturn.Contains(card));
                    }

                    Assert.True(spy.HasCardCalled);
                    Assert.False(spy.AddCardCalled);
                }
Esempio n. 2
0
            public void ThenVersionNumberIncrementIsNotCalled(int validCards, int invalidCards)
            {
                List <IValidationResult> results = new List <IValidationResult>();

                for (int i = 0; i < validCards; i++)
                {
                    results.Add(new ValidationResult()
                    {
                        ErrorMessage = Guid.NewGuid().ToString(), Valid = true
                    });
                }

                for (int i = 0; i < invalidCards; i++)
                {
                    results.Add(new ValidationResult()
                    {
                        ErrorMessage = Guid.NewGuid().ToString(), Valid = false
                    });
                }

                // Shuffle list using linq
                IValidCardsData           stub             = new ValidCardsDataStub(results.OrderBy(a => Guid.NewGuid()).ToArray());
                CardGatewaySpy            spy              = new CardGatewaySpy(new CardDummy(), true);
                IncrementVersionNumberSpy versionNumberSpy = new IncrementVersionNumberSpy(22);

                new AddCards(stub, spy, new PackGatewayDummy(), versionNumberSpy, new PublishEndPointSpy()).Execute(new string[results.Count]);
                Assert.False(versionNumberSpy.Called);
            }
Esempio n. 3
0
            public void ThenPublishesMessageWithFailDetails(int validCards, int invalidCards)
            {
                List <IValidationResult> results = new List <IValidationResult>();

                for (int i = 0; i < validCards; i++)
                {
                    results.Add(new ValidationResult()
                    {
                        ErrorMessage = Guid.NewGuid().ToString(), Valid = true
                    });
                }

                for (int i = 0; i < invalidCards; i++)
                {
                    results.Add(new ValidationResult()
                    {
                        ErrorMessage = Guid.NewGuid().ToString(), Valid = false
                    });
                }

                IValidCardsData    stub = new ValidCardsDataStub(results.OrderBy(a => Guid.NewGuid()).ToArray());
                PublishEndPointSpy spy  = new PublishEndPointSpy();

                new AddCards(stub, new CardGatewayDummy(), new PackGatewayDummy(), new IncrementVersionNumberDummy(), spy).Execute(
                    new string[results.Count]);
                Assert.True(spy.MessageObject is IFailedToAddCards);
                IFailedToAddCards failedToAddCardsMessage = (IFailedToAddCards)spy.MessageObject;

                foreach (IValidationResult validationResult in results.Where(_ => !_.Valid))
                {
                    Assert.True(failedToAddCardsMessage.ErrorMessages.Any(_ =>
                                                                          _.ToLower().Trim().Contains(validationResult.ErrorMessage.ToLower().Trim())));
                }
            }
Esempio n. 4
0
                public void ThenCardsIDsAndVersionNumberAreCorrectlySet(int cardDataCount, int newVersion)
                {
                    List <string>            cardDatas     = new List <string>();
                    List <ICard>             cardsToReturn = new List <ICard>();
                    List <IValidationResult> results       = new List <IValidationResult>();
                    List <string>            cardIds       = new List <string>();

                    for (int i = 0; i < cardDataCount; i++)
                    {
                        string cardID = Guid.NewGuid().ToString();
                        cardIds.Add(cardID);
                        cardDatas.Add(Guid.NewGuid().ToString());
                        cardsToReturn.Add(new CardStub(cardID, "Title", "Description", "Image",
                                                       new ICardOption[0], "Heavy"));
                        results.Add(new ValidationResult {
                            Valid = true, ValidCardData = cardsToReturn[i]
                        });
                    }


                    IValidCardsData stub = new ValidCardsDataStub(results.ToArray());
                    // Card is not in gateway
                    CardGatewaySpy  spy             = new CardGatewaySpy(new CardDummy(), false);
                    PackGatewayFake packGatewayFake = new PackGatewayFake(new string[0]);

                    new AddCards(stub, spy, packGatewayFake, new IncrementVersionNumberSpy(newVersion), new PublishEndPointSpy()).Execute(
                        new string[results.Count]);
                    Assert.True(packGatewayFake.SetCardsHistory.ContainsKey(newVersion));

                    foreach (string cardID in packGatewayFake.SetCardsHistory[newVersion])
                    {
                        Assert.True(cardIds.Contains(cardID));
                    }
                }
Esempio n. 5
0
                public void ThenThrowInvalidValidationResultCountException()
                {
                    List <string> cardDatas = new List <string>();

                    for (int i = 0; i < 4; i++)
                    {
                        cardDatas.Add(Guid.NewGuid().ToString());
                    }

                    List <IValidationResult> results = new List <IValidationResult>();

                    for (int i = 0; i < 2; i++)
                    {
                        results.Add(new ValidationResult {
                            Valid = true
                        });
                    }

                    IValidCardsData stub = new ValidCardsDataStub(results.ToArray());

                    Assert.Throws <InvalidValidationResultCountException>(() =>
                                                                          new AddCards(stub, new CardGatewayDummy(), new PackGatewayDummy(), new IncrementVersionNumberDummy(),
                                                                                       new PublishEndPointSpy()).Execute(cardDatas.ToArray()));
                }