Пример #1
0
        public void GivenANewTusLibrosRestAPI_WhenListingCartWithSeveralItems_ThenReturnsAList()
        {
            const int quantity1 = 4;
            const int quantity2 = 13;
            var       sut       = new TusLibrosRestAPIStubBuilder()
                                  .AuthenticatesWith(new AuthenticatorStubBuilder()
                                                     .Returns(true)
                                                     .Build())
                                  .MeasuresTimeWith(new ClockStubBuilder()
                                                    .Returns(new DateTime(2020, 4, 28, 12, 0, 0))
                                                    .IsExpired(false)
                                                    .Build())
                                  .UsesCatalog(new List <object> {
                VALID_ITEM, ANOTHER_VALID_ITEM
            })
                                  .Build();

            var cartId = sut.CreateCart("validClientId", "validPassword");

            sut.AddToCart(cartId, VALID_ITEM, quantity1);
            sut.AddToCart(cartId, ANOTHER_VALID_ITEM, quantity2);
            var itemsInCart = sut.ListCart(cartId);

            Assert.Collection(itemsInCart,
                              elem1 => { Assert.Equal(VALID_ITEM, elem1.Item1); Assert.Equal(quantity1, elem1.Item2); },
                              elem2 => { Assert.Equal(ANOTHER_VALID_ITEM, elem2.Item1); Assert.Equal(quantity2, elem2.Item2); });
        }
Пример #2
0
        public void GivenAClientWithSomeBuys_WhenGettingPurchasesWithThatClient_ThenDataIsReturned()
        {
            var sut = new TusLibrosRestAPIStubBuilder()
                      .AuthenticatesWith(new AuthenticatorStubBuilder()
                                         .Returns(true)
                                         .Build())
                      .MeasuresTimeWith(new ClockStubBuilder()
                                        .Returns(new DateTime(2020, 4, 28, 12, 0, 0))
                                        .IsExpired(false)
                                        .Build())
                      .UsesCatalog(new List <object> {
                VALID_ITEM, ANOTHER_VALID_ITEM
            })
                      .UsesPricelist(new Dictionary <object, decimal> {
                { VALID_ITEM, 1 }, { ANOTHER_VALID_ITEM, 2 }
            })
                      .Build();

            var cartId = sut.CreateCart("clientId", "validPassword");

            sut.AddToCart(cartId, VALID_ITEM, 10);
            sut.Checkout(cartId, VALID_CARD_NUMBER, VALID_EXPIRATION_DATE, VALID_CARD_OWNER);

            cartId = sut.CreateCart("clientId", "validPassword");
            sut.AddToCart(cartId, ANOTHER_VALID_ITEM, 6);
            sut.Checkout(cartId, VALID_CARD_NUMBER, VALID_EXPIRATION_DATE, VALID_CARD_OWNER);

            var items = sut.ListPurchases("clientId", "validPassword");

            Assert.Collection(items,
                              elem1 => { Assert.Equal(VALID_ITEM, elem1.Item1);
                                         Assert.Equal(10, elem1.Item2); },
                              elem2 => { Assert.Equal(ANOTHER_VALID_ITEM, elem2.Item1);
                                         Assert.Equal(6, elem2.Item2); });
        }
Пример #3
0
        public void GivenANewTusLibrosRestAPI_WhenCheckingOutCorrectCart_ThenATransactionIdIsReturned()
        {
            const string expectedTransactionId = "ABC";
            var          sut = new TusLibrosRestAPIStubBuilder()
                               .AuthenticatesWith(new AuthenticatorStubBuilder()
                                                  .Returns(true)
                                                  .Build())
                               .MeasuresTimeWith(new ClockStubBuilder()
                                                 .Returns(new DateTime(2020, 4, 28, 12, 0, 0))
                                                 .IsExpired(false)
                                                 .Build())
                               .CommunicatesWith(new MerchantAdapterStubBuilder()
                                                 .AlwaysReturns(expectedTransactionId)
                                                 .Build())
                               .UsesCatalog(new List <object> {
                VALID_ITEM
            })
                               .UsesPricelist(new Dictionary <object, decimal> {
                { VALID_ITEM, 1 }
            })
                               .Build();

            var cartId = sut.CreateCart("validClientId", "validPassword");

            sut.AddToCart(cartId, VALID_ITEM, 1);
            var transactionId = sut.Checkout(cartId, VALID_CARD_NUMBER, VALID_EXPIRATION_DATE, VALID_CARD_OWNER);

            Assert.Equal(expectedTransactionId, transactionId);
        }
Пример #4
0
        public void GivenANewTusLibrosRestAPI_WhenAddingItemsWithExpiredCart_ThenAnExceptionIsThrown()
        {
            var clockStub = new ClockStub(new DateTime(2020, 4, 28, 5, 0, 0));
            var sut       = new TusLibrosRestAPIStubBuilder()
                            .AuthenticatesWith(new AuthenticatorStubBuilder()
                                               .Returns(true)
                                               .Build())
                            .MeasuresTimeWith(clockStub)
                            .UsesCatalog(new List <object> {
                VALID_ITEM
            })
                            .Build();

            var cartId = sut.CreateCart("validClientId", "validPassword");

            sut.AddToCart(cartId, VALID_ITEM, 1);
            clockStub.AddMinutes(31);

            var exception = Assert.Throws <ArgumentException>(() => sut.AddToCart(cartId, "1", 1));

            Assert.Equal(TusLibrosRestAPI.CART_HAS_EXPIRED_ERROR, exception.Message);
        }
Пример #5
0
        public void GivenANewTusLibrosRestAPI_WhenAddingItemsWithInvalidCartId_ThenAnExceptionIsThrown()
        {
            var sut = new TusLibrosRestAPIStubBuilder()
                      .AuthenticatesWith(new AuthenticatorStubBuilder()
                                         .Returns(true)
                                         .Build())
                      .MeasuresTimeWith(new ClockStubBuilder()
                                        .IsExpired(false)
                                        .Returns(new DateTime(2020, 4, 28))
                                        .Build())
                      .Build();

            var cartId = sut.CreateCart("validClientId", "validPassword");

            var exception = Assert.Throws <ArgumentException>(() => sut.AddToCart("invalid cart id", VALID_ITEM, 1));

            Assert.Equal(TusLibrosRestAPI.CART_ID_IS_INVALID_ERROR, exception.Message);
        }
Пример #6
0
        public void GivenANewTusLibrosRestAPI_WhenAddingItemsWithWrongQuantity_ThenAnExceptionIsThrown(int invalidQuantity)
        {
            var sut = new TusLibrosRestAPIStubBuilder()
                      .AuthenticatesWith(new AuthenticatorStubBuilder()
                                         .Returns(true)
                                         .Build())
                      .MeasuresTimeWith(new ClockStubBuilder()
                                        .IsExpired(false)
                                        .Returns(new DateTime(2020, 4, 28))
                                        .Build())
                      .UsesCatalog(new List <object> {
                VALID_ITEM
            })
                      .Build();

            var cartId = sut.CreateCart("validClientId", "validPassword");

            var exception = Assert.Throws <ArgumentException>(() => sut.AddToCart(cartId, VALID_ITEM, invalidQuantity));

            Assert.Equal(Cart.QUANTITY_IS_INVALID_ERROR, exception.Message);
        }
Пример #7
0
        public void GivenANewTusLibrosRestAPI_WhenAddingItemsWithValidCartId_ThenItemsCanBeListed()
        {
            var sut = new TusLibrosRestAPIStubBuilder()
                      .AuthenticatesWith(new AuthenticatorStubBuilder()
                                         .Returns(true)
                                         .Build())
                      .MeasuresTimeWith(new ClockStubBuilder()
                                        .Returns(new DateTime(2020, 4, 28, 12, 0, 0))
                                        .IsExpired(false)
                                        .Build())
                      .UsesCatalog(new List <object> {
                VALID_ITEM
            })
                      .Build();

            var cartId = sut.CreateCart("validClientId", "validPassword");

            sut.AddToCart(cartId, VALID_ITEM, 1);
            var itemsInCart = sut.ListCart(cartId);

            Assert.Single(itemsInCart);
            Assert.Equal(VALID_ITEM, itemsInCart[0].Item1);
            Assert.Equal(1, itemsInCart[0].Item2);
        }