Example #1
0
                public void ThenPackGatewaySetIsCalledToUpdateBothPacks(string cardID, int numberOfCardsInOldPack, int newPackVersion, int oldPackVersion)
                {
                    string[] cardsInOldPack = new string[numberOfCardsInOldPack];
                    cardsInOldPack[0] = cardID;
                    for (int i = 1; i < numberOfCardsInOldPack; i++)
                    {
                        cardsInOldPack[i] = Guid.NewGuid().ToString();
                    }

                    CardStub cardToAdd = new CardStub(cardID, "New Card", "Dog", "Cat", new ICardOption[0], "Cow");

                    CardStub existingCard = new CardStub(cardID, "Old Card", " ", " ", new ICardOption[0], " ");

                    existingCard.VersionAdded = oldPackVersion;

                    CardGatewaySpy  cardGatewaySpy  = new CardGatewaySpy(existingCard, true);
                    PackGatewayFake packGatewayFake = new PackGatewayFake(cardsInOldPack);

                    new AddCard(new ValidCardDataStub(true, cardToAdd), cardGatewaySpy, packGatewayFake,
                                new IncrementVersionNumberSpy(newPackVersion)).Execute("Valid Json");

                    Console.WriteLine(packGatewayFake.GetCardsPackVersion + " " + oldPackVersion);
                    Assert.True(packGatewayFake.GetCardsPackVersion == oldPackVersion);
                    Assert.True(packGatewayFake.SetCardsHistory.ContainsKey(oldPackVersion));
                    Assert.False(packGatewayFake.SetCardsHistory[oldPackVersion].Contains(cardID));
                    AssertCardIDIsAddedToNewPack(cardID, newPackVersion, packGatewayFake);
                }
Example #2
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));
                    }
                }
Example #3
0
                public void ThenCardIDsAreRemovedFromTheirOldPacks(int cardCount, int existingCardsInPackCount, int newPackID)
                {
                    if (newPackID <= cardCount)
                    {
                        Assert.Fail($"PackIds from 0 to {cardCount} are being used for the test. Ensure newPackID is greater than cardCount");
                    }
                    PackGatewayFake packGatewayFake = new PackGatewayFake(new string[0]);
                    CardGatewayFake cardGatewayFake = new CardGatewayFake(new CardDummy(), true);

                    List <string>            cardIDs             = new List <string>();
                    List <ICard>             cardsToReturn       = new List <ICard>();
                    List <IValidationResult> results             = new List <IValidationResult>();
                    Dictionary <int, string> packVersionToCardID = new Dictionary <int, string>();

                    SetCardGatewayToReturnCardWithOldVersion(cardCount, cardsToReturn, results, cardIDs, cardGatewayFake, packVersionToCardID);

                    Dictionary <int, List <string> > initialCardsInPack = new Dictionary <int, List <string> >();

                    SetPackGatewayFakeToReturnCards(existingCardsInPackCount, cardIDs, initialCardsInPack, packGatewayFake);

                    new AddCards(new ValidCardsDataStub(results.ToArray()), cardGatewayFake, packGatewayFake, new IncrementVersionNumberSpy(newPackID), new PublishEndPointSpy()).Execute(
                        new string[results.Count]);

                    AssertCardIDsHaveBeenRemovedFromPacks(initialCardsInPack, packGatewayFake, packVersionToCardID);
                }
Example #4
0
                public void ThenNewPackIsCreatedWithCardID(string cardID, int newVersionNumber, int cardIsnPack)
                {
                    IncrementVersionNumberSpy spy   = new IncrementVersionNumberSpy(newVersionNumber);
                    CardStub        stub            = new CardStub(cardID, " ", " ", " ", new ICardOption[0], " ");
                    CardGatewaySpy  cardGatewaySpy  = new CardGatewaySpy(stub, false);
                    PackGatewayFake packGatewayFake = new PackGatewayFake(new string[0]);

                    new AddCard(new ValidCardDataStub(true, stub), cardGatewaySpy, packGatewayFake, spy)
                    .Execute("Valid Json");
                    Assert.True(packGatewayFake.SetCardsHistory.ContainsKey(newVersionNumber));
                    Assert.True(packGatewayFake.SetCardsHistory[newVersionNumber].Contains(cardID));
                }
Example #5
0
                private static void AssertCardIDsHaveBeenRemovedFromPacks(Dictionary <int, List <string> > initialCardsInPack,
                                                                          PackGatewayFake packGatewayFake, Dictionary <int, string> packVersionToCardID)
                {
                    foreach (int packNumber in initialCardsInPack.Keys)
                    {
                        foreach (string cardAdded in packGatewayFake.SetCardsHistory[packNumber])
                        {
                            Assert.True(initialCardsInPack[packNumber].Contains(cardAdded));
                        }

                        Assert.False(packGatewayFake.SetCardsHistory[packNumber].Contains(packVersionToCardID[packNumber]));
                    }
                }
Example #6
0
 private static void AssertCardIDIsRemovedFromOldPack(string cardID, int oldPackVersion, PackGatewayFake packGatewayFake)
 {
     Assert.True(packGatewayFake.GetCardsPackVersion == oldPackVersion);
     Assert.True(packGatewayFake.SetCardsHistory.ContainsKey(oldPackVersion));
     Assert.False(packGatewayFake.SetCardsHistory[oldPackVersion].Contains(cardID));
 }
Example #7
0
 private static void AssertCardIDIsAddedToNewPack(string cardID, int newPackVersion, PackGatewayFake packGatewayFake)
 {
     Assert.True(packGatewayFake.SetCardsHistory.ContainsKey(newPackVersion));
     Assert.True(packGatewayFake.SetCardsHistory[newPackVersion].Contains(cardID));
 }
Example #8
0
                private static void SetPackGatewayFakeToReturnCards(int existingCardsInPackCount, List <string> cardIDs,
                                                                    Dictionary <int, List <string> > initialCardsInPack, PackGatewayFake packGatewayFake)
                {
                    for (int i = 0; i < cardIDs.Count; i++)
                    {
                        List <string> cardsInThisPack = new List <string>();
                        cardsInThisPack.Add(cardIDs[i]);
                        for (int j = 0; j < existingCardsInPackCount; j++)
                        {
                            cardsInThisPack.Add(new Guid().ToString());
                        }

                        initialCardsInPack.Add(i, cardsInThisPack);
                        // Set fake to return these values
                        packGatewayFake.SetGetCardsReponseFor(i, cardsInThisPack.ToArray());
                    }
                }