public async Task Should_LogNoDataFound_OnRepositoyWithoutData()
        {
            var containerWithNoPurchases = new PurchaseContainer(new List <Purchase>());

            _purchaseRepositoryMock.Setup(i => i.GetData()).ReturnsAsync(containerWithNoPurchases).Verifiable();

            await _sut.ProcessPurchases();

            _taxesCalculatorMock.Verify(i => i.Compute(It.IsAny <Purchase>()), Times.Never);
            _receiptNotifier.Verify(i => i.Notify(It.IsAny <ReceiptContainer>()), Times.Never);
        }
        public void Should_Throws_IfRepositoryFailToProvideData()
        {
            var expectedErrMessage       = "error on getting data";
            var containerWithNoPurchases = new PurchaseContainer(new List <Purchase>());

            _purchaseRepositoryMock.Setup(i => i.GetData()).ThrowsAsync(new Exception(expectedErrMessage)).Verifiable();

            Assert.ThrowsAsync <Exception>(async() => await _sut.ProcessPurchases());

            _logHandler.Verify(i => i.LogError(It.IsAny <string>()), Times.Once);
            _taxesCalculatorMock.Verify(i => i.Compute(It.IsAny <Purchase>()), Times.Never);
            _receiptNotifier.Verify(i => i.Notify(It.IsAny <ReceiptContainer>()), Times.Never);
        }
Beispiel #3
0
    public void OnPurchaseSucceeded(PurchaseContainer purchases)
    {
        PaymentManager.MyDebug.PushMessage(nameof(OnPurchaseSucceeded));
        if (((Allocator <MetaPurchase, Purchase>)purchases).get_Length() > 0)
        {
            if (((string)((Allocator <MetaPurchase, Purchase>)purchases).get_Item(0).productId).Contains("bundle"))
            {
                GlobalVars.SelectedPurchaseType = GlobalVars.PurchaseType.Bundles;
                Debug.Log((object)(">>>> Bundle purchase succeeded : " + (object)purchases));
            }
            else
            {
                GlobalVars.SelectedPurchaseType = GlobalVars.PurchaseType.Gems;
                Debug.Log((object)(">>>> Gem purchase succeeded : " + (object)purchases));
            }
        }
        else
        {
            Debug.Log((object)">>>> [ERROR] Purchase succeeded but couldn't find purchase IDs.");
        }
        this.purchaseContainerTemp = purchases;
        List <gu3.Payment.Product> productList = new List <gu3.Payment.Product>();

        if (GlobalVars.SelectedPurchaseType == GlobalVars.PurchaseType.Bundles)
        {
            using (Dictionary <string, gu3.Payment.Product> .ValueCollection.Enumerator enumerator = this.BundleOnStores.Values.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    gu3.Payment.Product current = enumerator.Current;
                    productList.Add(current);
                }
            }
            this.purchaseResult = PaymentManager.ERequestPurchaseResult.SUCCESS;
            Client.SendVerify(PaymentManager.BundleApiPath, Network.SessionID, purchases, productList.ToArray());
        }
        else
        {
            using (Dictionary <string, gu3.Payment.Product> .ValueCollection.Enumerator enumerator = this.ProductOnStores.Values.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    gu3.Payment.Product current = enumerator.Current;
                    productList.Add(current);
                }
            }
            this.purchaseResult = PaymentManager.ERequestPurchaseResult.SUCCESS;
            Client.SendVerify(PaymentManager.ApiPath, Network.SessionID, purchases, productList.ToArray());
        }
    }
        public bool Post([FromBody] PurchaseContainer purchaseContainer)
        {
            var result = false;

            if (purchaseContainer != null)
            {
                var demoUser = _applicationManager.GetDemoUser();
                result = _purchaseManager.CreatePurchase(fromCurrencyId: purchaseContainer.FromCurrencyId,
                                                         toCurrencyId: purchaseContainer.ToCurrencyId,
                                                         when: purchaseContainer.When,
                                                         price: purchaseContainer.Price,
                                                         quantity: purchaseContainer.Quantity,
                                                         exchangeId: purchaseContainer.ExchangeId,
                                                         userId: demoUser.Email);
            }

            return(result);
        }