public void Init()
        {
            _client = Helper.GetClient();

            Task <Response <Project.Project> > projectTask = _client.Project().GetProjectAsync();

            projectTask.Wait();
            Assert.IsTrue(projectTask.Result.Success);
            _project = projectTask.Result.Result;

            Assert.IsTrue(_project.Languages.Count > 0);

            CustomerDraft customerDraft = Helper.GetTestCustomerDraft();
            Task <Response <CustomerCreatedMessage> > customerTask = _client.Customers().CreateCustomerAsync(customerDraft);

            customerTask.Wait();
            Assert.IsTrue(customerTask.Result.Success);

            _testTypes = new List <Type>();

            for (int i = 0; i < 5; i++)
            {
                TypeDraft typeDraft = Helper.GetTypeDraft(_project);
                Task <Response <Type> > typeTask = _client.Types().CreateTypeAsync(typeDraft);
                typeTask.Wait();
                Assert.IsTrue(typeTask.Result.Success);

                Type type = typeTask.Result.Result;
                Assert.NotNull(type.Id);

                _testTypes.Add(type);
            }
        }
        public async Task ShouldGetTypeByIdAsync()
        {
            Response <Type> response = await _client.Types().GetTypeByIdAsync(_testTypes[0].Id);

            Assert.IsTrue(response.Success);

            Type type = response.Result;

            Assert.NotNull(type.Id);
            Assert.AreEqual(type.Id, _testTypes[0].Id);
        }
        public async Task ShouldCreateAndDeleteTypeAsync()
        {
            TypeDraft       typeDraft    = Helper.GetTypeDraft(_project);
            Response <Type> typeResponse = await _client.Types().CreateTypeAsync(typeDraft);

            Assert.IsTrue(typeResponse.Success);

            Type type = typeResponse.Result;

            Assert.NotNull(type.Id);

            string deletedTypeId = type.Id;

            Response <JObject> deleteResponse = await _client.Types().DeleteTypeAsync(type);

            Assert.IsTrue(deleteResponse.Success);

            typeResponse = await _client.Types().GetTypeByIdAsync(deletedTypeId);

            Assert.IsFalse(typeResponse.Success);
        }
        public void Init()
        {
            _client = new Client(Helper.GetConfiguration());

            Task <Response <Project.Project> > projectTask = _client.Project().GetProjectAsync();

            projectTask.Wait();
            Assert.IsTrue(projectTask.Result.Success);
            _project = projectTask.Result.Result;

            Assert.IsTrue(_project.Languages.Count > 0, "No Languages");
            Assert.IsTrue(_project.Currencies.Count > 0, "No Currencies");

            _testCustomers = new List <Customer>();
            _testCarts     = new List <Cart>();
            _testCartsExternalAmountTaxMode = new List <Cart>();
            CustomerDraft customerDraft;
            Task <Response <CustomerCreatedMessage> > customerTask;
            CustomerCreatedMessage customerCreatedMessage;
            CartDraft cartDraft;
            Cart      cart;
            Task <Response <Cart> > cartTask;

            for (int i = 0; i < 5; i++)
            {
                customerDraft = Helper.GetTestCustomerDraft();
                customerTask  = _client.Customers().CreateCustomerAsync(customerDraft);
                customerTask.Wait();
                Assert.IsTrue(customerTask.Result.Success);

                customerCreatedMessage = customerTask.Result.Result;
                Assert.NotNull(customerCreatedMessage.Customer);
                Assert.NotNull(customerCreatedMessage.Customer.Id);

                _testCustomers.Add(customerCreatedMessage.Customer);

                cartDraft = Helper.GetTestCartDraft(_project, customerCreatedMessage.Customer.Id);
                cartTask  = _client.Carts().CreateCartAsync(cartDraft);
                cartTask.Wait();
                Assert.NotNull(cartTask.Result);
                Assert.IsTrue(cartTask.Result.Success, "CreateCartAsync failed");
                cart = cartTask.Result.Result;
                Assert.NotNull(cart.Id);
                Console.Error.WriteLine(string.Format("CartManagerTest - Information Only - Init TestCartDraft TaxMode: {0}", cartDraft.TaxMode == null ? "(default)" : cart.TaxMode.ToString()));

                _testCarts.Add(cart);


                cartDraft         = Helper.GetTestCartDraft(_project, customerCreatedMessage.Customer.Id);
                cartDraft.TaxMode = TaxMode.ExternalAmount;
                cartTask          = _client.Carts().CreateCartAsync(cartDraft);
                cartTask.Wait();
                Assert.NotNull(cartTask.Result);
                Assert.IsTrue(cartTask.Result.Success, "CreateCartAsync failed");
                cart = cartTask.Result.Result;
                Assert.IsTrue(cart.TaxMode == TaxMode.ExternalAmount, string.Format("Cart created using ExternalAmount TaxMode failed - TaxMode: {0}", cart.TaxMode));
                Assert.NotNull(cart.Id);
                Console.Error.WriteLine(string.Format("CartManagerTest - Information Only - Init TestCartDraft TaxMode: {0}", cartDraft.TaxMode == null ? "(default)" : cart.TaxMode.ToString()));

                _testCartsExternalAmountTaxMode.Add(cart);
            }

            //customer/cart with external tax mode enabled

            customerDraft = Helper.GetTestCustomerDraft();
            customerTask  = _client.Customers().CreateCustomerAsync(customerDraft);
            customerTask.Wait();
            Assert.IsTrue(customerTask.Result.Success);
            customerCreatedMessage = customerTask.Result.Result;
            Assert.NotNull(customerCreatedMessage.Customer);
            Assert.NotNull(customerCreatedMessage.Customer.Id);

            _testCustomers.Add(customerCreatedMessage.Customer);

            cartDraft = Helper.GetTestCartDraftUsingExternalTaxMode(_project, customerCreatedMessage.Customer.Id);
            cartTask  = _client.Carts().CreateCartAsync(cartDraft);
            cartTask.Wait();
            Assert.NotNull(cartTask.Result);
            Assert.IsTrue(cartTask.Result.Success, "CreateCartAsync failed");
            cart = cartTask.Result.Result;
            Assert.NotNull(cart.Id);
            Console.Error.WriteLine(string.Format("CartManagerTest - Information Only - Init TestCartDraft TaxMode: {0}", cart.TaxMode));

            _testCarts.Add(cart);

            ProductTypeDraft productTypeDraft = Helper.GetTestProductTypeDraft();
            Task <Response <ProductType> > testProductTypeTask =
                _client.ProductTypes().CreateProductTypeAsync(productTypeDraft);

            testProductTypeTask.Wait();
            Assert.IsTrue(testProductTypeTask.Result.Success, "CreateProductType failed");
            _testProductType = testProductTypeTask.Result.Result;
            Assert.NotNull(_testProductType.Id);

            TaxCategoryDraft taxCategoryDraft = Helper.GetTestTaxCategoryDraft(_project);
            Task <Response <TaxCategory> > taxCategoryTask =
                _client.TaxCategories().CreateTaxCategoryAsync(taxCategoryDraft);

            taxCategoryTask.Wait();
            Assert.IsTrue(taxCategoryTask.Result.Success, "CreateTaxCategory failed");
            _testTaxCategory = taxCategoryTask.Result.Result;
            Assert.NotNull(_testTaxCategory.Id);

            Task <Response <ZoneQueryResult> > zoneQueryResultTask = _client.Zones().QueryZonesAsync();

            zoneQueryResultTask.Wait();
            Assert.IsTrue(zoneQueryResultTask.Result.Success);

            if (zoneQueryResultTask.Result.Result.Results.Count > 0)
            {
                _testZone        = zoneQueryResultTask.Result.Result.Results[0];
                _createdTestZone = false;
            }
            else
            {
                ZoneDraft zoneDraft = Helper.GetTestZoneDraft();
                Task <Response <Zone> > zoneTask = _client.Zones().CreateZoneAsync(zoneDraft);
                zoneTask.Wait();
                Assert.IsTrue(zoneTask.Result.Success, "CreateZone failed");
                _testZone        = zoneTask.Result.Result;
                _createdTestZone = true;
            }

            Assert.NotNull(_testZone.Id);

            foreach (string country in _project.Countries)
            {
                Location location =
                    _testZone.Locations
                    .Where(l => l.Country.Equals(country, StringComparison.OrdinalIgnoreCase))
                    .FirstOrDefault();

                if (location == null)
                {
                    location         = new Location();
                    location.Country = country;

                    AddLocationAction       addLocationAction = new AddLocationAction(location);
                    Task <Response <Zone> > updateZoneTask    = _client.Zones().UpdateZoneAsync(_testZone, addLocationAction);
                    updateZoneTask.Wait();
                    Assert.IsTrue(updateZoneTask.Result.Success, "UpdateZone failed");
                    _testZone = updateZoneTask.Result.Result;
                }
            }

            Assert.NotNull(_testZone.Locations.Count > 0);

            ShippingMethodDraft shippingMethodDraft =
                Helper.GetTestShippingMethodDraft(_project, _testTaxCategory, _testZone);
            Task <Response <ShippingMethod> > shippingMethodTask =
                _client.ShippingMethods().CreateShippingMethodAsync(shippingMethodDraft);

            shippingMethodTask.Wait();
            Assert.IsTrue(shippingMethodTask.Result.Success, "CreateShippingMethod failed");
            _testShippingMethod = shippingMethodTask.Result.Result;

            Assert.NotNull(_testShippingMethod.Id);

            ProductDraft productDraft = Helper.GetTestProductDraft(_project, _testProductType.Id, _testTaxCategory.Id);
            Task <Response <Product> > testProductTask = _client.Products().CreateProductAsync(productDraft);

            testProductTask.Wait();
            Assert.IsTrue(testProductTask.Result.Success, "CreateProduct failed");
            _testProduct = testProductTask.Result.Result;

            Assert.NotNull(_testProduct.Id);

            PaymentDraft paymentDraft = Helper.GetTestPaymentDraft(_project, _testCustomers[0].Id);
            Task <Response <Payment> > paymentTask = _client.Payments().CreatePaymentAsync(paymentDraft);

            paymentTask.Wait();
            Assert.IsTrue(paymentTask.Result.Success, "CreatePayment failed");
            _testPayment = paymentTask.Result.Result;

            Assert.NotNull(_testPayment.Id);

            TypeDraft typeDraft = Helper.GetTypeDraft(_project);
            Task <Response <Type> > typeTask = _client.Types().CreateTypeAsync(typeDraft);

            typeTask.Wait();
            Assert.IsTrue(typeTask.Result.Success, "CreateType failed");
            _testType = typeTask.Result.Result;
        }