Exemplo n.º 1
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); });
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void GivenANewTusLibrosRestAPI_WhenCheckingOutInvalidCart_ThenAnExceptionIsThrown()
        {
            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 exception = Assert.Throws <ArgumentException>(() => sut.Checkout("invalidCartId", VALID_CARD_NUMBER, VALID_EXPIRATION_DATE, VALID_CARD_OWNER));

            Assert.Equal(TusLibrosRestAPI.CART_ID_IS_INVALID_ERROR, exception.Message);
        }
Exemplo n.º 4
0
        public void GivenANewTusLibrosRestAPI_WhenCheckingOutEmptyCart_ThenAnExceptionIsThrown()
        {
            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
            })
                      .UsesPricelist(new Dictionary <object, decimal> {
                { VALID_ITEM, 1 }
            })
                      .Build();

            var cartId    = sut.CreateCart("validClientId", "validPassword");
            var exception = Assert.Throws <ArgumentException>(() => sut.Checkout(cartId, VALID_CARD_NUMBER, VALID_EXPIRATION_DATE, VALID_CARD_OWNER));

            Assert.Equal(Cashier.CART_IS_EMPTY_ERROR, exception.Message);
        }