diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Cart/CartFixture.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Cart/CartFixture.cs new file mode 100644 index 00000000000..cd1d55b782c --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Cart/CartFixture.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Sdk.Api.Models.Carts; +using commercetools.Sdk.Api.Models.Common; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using static commercetools.Api.IntegrationTests.GenericFixture; + + +namespace commercetools.Api.IntegrationTests.Cart +{ + public class CartFixture + { + #region DraftBuilds + + public static CartDraft DefaultCartDraft(CartDraft cartDraft) + { + var randomInt = TestingUtility.RandomInt(); + cartDraft.Country = "DE"; + cartDraft.Currency = "EUR"; + cartDraft.ItemShippingAddresses = new List() + { + new BaseAddress() { Country = "DE", Key = $"Key{randomInt}" } + }; + + return cartDraft; + } + + public static CartDraft DefaultCartDraftWithKey(CartDraft draft, string key) + { + var cartDraft = DefaultCartDraft(draft); + cartDraft.Key = key; + + return cartDraft; + } + + #endregion + + public static async Task CreateCart(ProjectApiRoot client, CartDraft cartDraft) + { + return await client + .Carts() + .Post(cartDraft) + .ExecuteAsync(); + } + + public static async Task DeleteCart(ProjectApiRoot client, ICart cart) + { + try + { + await client + .Carts() + .WithKey(cart.Key) + .Delete() + .WithVersion(cart.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region WithCart + + public static async Task WithCart(ProjectApiRoot client, Func draftAction, Action func) + { + await With(client, new CartDraft(), draftAction, func, CreateCart, DeleteCart); + } + + public static async Task WithCart(ProjectApiRoot client, Func draftAction, + Func func) + { + await WithAsync(client, new CartDraft(), draftAction, func, CreateCart, DeleteCart); + } + + public static async Task WithCart(ProjectApiRoot client, Func func) + { + await WithAsync(client, new CartDraft(), DefaultCartDraft, func, CreateCart, DeleteCart); + } + + public static async Task WithUpdateableCart(ProjectApiRoot client, Func> func) + { + await WithUpdateableAsync(client, new CartDraft(), DefaultCartDraft, func, CreateCart, DeleteCart); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Cart/CartIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Cart/CartIntegrationTests.cs new file mode 100644 index 00000000000..ed0668e8138 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Cart/CartIntegrationTests.cs @@ -0,0 +1,188 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client.Error; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.Carts; +using Xunit; +using static commercetools.Api.IntegrationTests.Cart.CartFixture; + +namespace commercetools.Api.IntegrationTests.Cart +{ + [Collection("Integration Tests")] + public class CartIntegrationTests + { + private readonly ProjectApiRoot _client; + + public CartIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateCart() + { + var key = $"CreateCart-{TestingUtility.RandomString()}"; + await WithCart( + _client, + cartDraft => DefaultCartDraftWithKey(cartDraft, key), + cart => { Assert.Equal(key, cart.Key); } + ); + } + + [Fact] + public async Task GetCartById() + { + var key = $"GetCartById-{TestingUtility.RandomString()}"; + await WithCart( + _client, cartDraft => DefaultCartDraftWithKey(cartDraft, key), + async cart => + { + Assert.NotNull(cart); + var retrievedCart = await _client + .Carts() + .WithId(cart.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedCart); + Assert.Equal(key, retrievedCart.Key); + }); + } + + [Fact] + public async Task GetCartByKey() + { + var key = $"GetCartByKey-{TestingUtility.RandomString()}"; + await WithCart( + _client, cartDraft => DefaultCartDraftWithKey(cartDraft, key), + async cart => + { + Assert.NotNull(cart); + var retrievedCart = await _client + .Carts() + .WithKey(cart.Key) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedCart); + Assert.Equal(key, retrievedCart.Key); + } + ); + } + + [Fact] + public async Task QueryCarts() + { + var key = $"QueryCarts-{TestingUtility.RandomString()}"; + await WithCart( + _client, cartDraft => DefaultCartDraftWithKey(cartDraft, key), + async cart => + { + Assert.NotNull(cart); + var returnedSet = await _client + .Carts() + .Get() + .WithQuery(q => q.Key().Is(cart.Key)) + .ExecuteAsync(); + Assert.Single(returnedSet.Results); + Assert.Equal(key, returnedSet.Results[0].Key); + } + ); + } + + [Fact] + public async Task DeleteCartById() + { + var key = $"DeleteCartById-{TestingUtility.RandomString()}"; + await WithCart( + _client, cartDraft => DefaultCartDraftWithKey(cartDraft, key), + async cart => + { + Assert.NotNull(cart); + + await _client + .Carts() + .WithId(cart.Id) + .Delete() + .WithVersion(cart.Version) + .ExecuteAsync(); + + await Assert.ThrowsAsync( + () => _client + .Carts().WithId(cart.Id) + .Get() + .ExecuteAsync() + ); + } + ); + } + + [Fact] + public async Task DeleteCartByKey() + { + var key = $"DeleteCartByKey-{TestingUtility.RandomString()}"; + await WithCart( + _client, cartDraft => DefaultCartDraftWithKey(cartDraft, key), + async cart => + { + Assert.NotNull(cart); + + await _client + .Carts() + .WithKey(cart.Key) + .Delete() + .WithVersion(cart.Version) + .ExecuteAsync(); + + await Assert.ThrowsAsync( + () => _client + .Carts() + .WithId(cart.Id) + .Get() + .ExecuteAsync() + ); + } + ); + } + + [Fact] + public async Task UpdateCartByIdChangeCountry() + { + await WithUpdateableCart(_client, async cart => + { + Assert.NotNull(cart); + + const string name = "US"; + var action = new CartSetCountryAction() + { + Action = "setCountry", + Country = name + }; + + var update = new CartUpdate() + { + Version = cart.Version, + Actions = new List() { action } + }; + + try + { + var updatedCart = await _client + .Carts() + .WithId(cart.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(name, updatedCart.Country); + return updatedCart; + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + }); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CartDiscount/CartDiscountFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CartDiscount/CartDiscountFixtures.cs new file mode 100644 index 00000000000..76fe6bafdb4 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CartDiscount/CartDiscountFixtures.cs @@ -0,0 +1,109 @@ +using System; +using System.Threading.Tasks; +using commercetools.Sdk.Api.Models.Common; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.CartDiscounts; +using static commercetools.Api.IntegrationTests.GenericFixture; + +namespace commercetools.Api.IntegrationTests.CartDiscount +{ + public class CartDiscountFixtures + { + #region DraftBuilds + + public static CartDiscountDraft DefaultCartDiscountDraft(CartDiscountDraft cartDiscountDraft) + { + var randomString = TestingUtility.RandomString(); + + cartDiscountDraft.Name = new LocalizedString { { "en", $"$Name-{randomString}" } }; + cartDiscountDraft.CartPredicate = $"country=\"DE\""; + cartDiscountDraft.Value = new CartDiscountValueRelativeDraft() { Type = "relative", Permyriad = 10 }; + cartDiscountDraft.Target = new CartDiscountShippingCostTarget() { Type = "shipping" }; + cartDiscountDraft.SortOrder = TestingUtility.RandomSortOrder(); + cartDiscountDraft.RequiresDiscountCode = true; + cartDiscountDraft.IsActive = false; + + return cartDiscountDraft; + } + + public static CartDiscountDraft DefaultCartDiscountDraftWithKey(CartDiscountDraft draft, string key) + { + var cartDiscountDraft = DefaultCartDiscountDraft(draft); + cartDiscountDraft.Key = key; + + return cartDiscountDraft; + } + + #endregion + + #region CreateAndDelete + + public static async Task CreateCartDiscount(ProjectApiRoot client, CartDiscountDraft cartDiscountDraft) + { + try + { + var resource = await client + .CartDiscounts() + .Post(cartDiscountDraft) + .ExecuteAsync(); + + return resource; + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteCartDiscount(ProjectApiRoot client, ICartDiscount cartDiscount) + { + try + { + await client + .CartDiscounts() + .WithId(cartDiscount.Id) + .Delete() + .WithVersion(cartDiscount.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #endregion + + #region WithDiscountCodes + + public static async Task WithCartDiscount(ProjectApiRoot client, + Func draftAction, Action func) + { + await With(client, new CartDiscountDraft(), draftAction, func, CreateCartDiscount, DeleteCartDiscount); + } + + public static async Task WithCartDiscount(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new CartDiscountDraft(), draftAction, func, CreateCartDiscount, + DeleteCartDiscount); + } + + public static async Task WithCartDiscount(ProjectApiRoot client, Func func) + { + await WithAsync(client, new CartDiscountDraft(), DefaultCartDiscountDraft, func, CreateCartDiscount, + DeleteCartDiscount); + } + + public static async Task WithUpdateableCartDiscount(ProjectApiRoot client, + Func> func) + { + await WithUpdateableAsync(client, new CartDiscountDraft(), DefaultCartDiscountDraft, func, + CreateCartDiscount, DeleteCartDiscount); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CartDiscount/CartDiscountIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CartDiscount/CartDiscountIntegrationTests.cs new file mode 100644 index 00000000000..1488fbbf0ce --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CartDiscount/CartDiscountIntegrationTests.cs @@ -0,0 +1,107 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.CartDiscounts; +using Xunit; +using static commercetools.Api.IntegrationTests.CartDiscount.CartDiscountFixtures; + +namespace commercetools.Api.IntegrationTests.CartDiscount +{ + [Collection("Integration Tests")] + public class CartDiscountIntegrationTests + { + private readonly ProjectApiRoot _client; + + public CartDiscountIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateCartDiscount() + { + var key = $"CreateCartDiscount-{TestingUtility.RandomString()}"; + await WithCartDiscount( + _client, + cartDiscountDraft => DefaultCartDiscountDraftWithKey(cartDiscountDraft, key), + cartDiscount => { Assert.Equal(key, cartDiscount.Key); } + ); + } + + [Fact] + public async Task GetCartDiscountById() + { + var key = $"GetDiscountById-{TestingUtility.RandomString()}"; + await WithCartDiscount( + _client, + cartDiscountDraft => DefaultCartDiscountDraftWithKey(cartDiscountDraft, key), + async cartDiscount => + { + Assert.NotNull(cartDiscount); + var retrievedCartDiscount = await _client + .CartDiscounts() + .WithId(cartDiscount.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedCartDiscount); + Assert.Equal(key, retrievedCartDiscount.Key); + } + ); + } + + [Fact] + public async Task QueryCartDiscounts() + { + var key = $"QueryCartDiscounts-{TestingUtility.RandomString()}"; + await WithCartDiscount( + _client, + cartDiscountDraft => DefaultCartDiscountDraftWithKey(cartDiscountDraft, key), + async cartDiscount => + { + Assert.NotNull(cartDiscount); + var returnedSet = await _client + .CartDiscounts() + .Get() + .WithQuery(q => q.Key().Is(cartDiscount.Key)) + .ExecuteAsync(); + + Assert.Single(returnedSet.Results); + Assert.Equal(key, returnedSet.Results[0].Key); + }); + } + + [Fact] + public async Task UpdateCartDiscountByIdSetKey() + { + await WithUpdateableCartDiscount( + _client, + async cartDiscount => + { + Assert.NotNull(cartDiscount); + var key = $"{TestingUtility.RandomString()}"; + var action = new CartDiscountSetKeyAction() + { + Action = "setKey", + Key = key + }; + + var update = new CartDiscountUpdate() + { + Version = cartDiscount.Version, + Actions = new List() { action } + }; + + var updatedCartDiscount = await _client + .CartDiscounts() + .WithId(cartDiscount.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedCartDiscount.Key, key); + return updatedCartDiscount; + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Categories/CategoriesFixture.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Categories/CategoriesFixture.cs index 10da2eca9ec..6706db20a80 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Categories/CategoriesFixture.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Categories/CategoriesFixture.cs @@ -4,6 +4,7 @@ using commercetools.Sdk.Api.Models.Categories; using commercetools.Sdk.Api.Models.Common; using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; using commercetools.Sdk.Api.Extensions; using static commercetools.Api.IntegrationTests.GenericFixture; @@ -44,19 +45,19 @@ public static CategoryDraft DefaultCategoryDraftWithParent(CategoryDraft draft, #region CreateAndDelete - public static async Task CreateCategory(IClient client, CategoryDraft categoryDraft) + public static async Task CreateCategory(ProjectApiRoot client, CategoryDraft categoryDraft) { - return await client.WithApi().WithProjectKey(DefaultProjectKey) + return await client .Categories() .Post(categoryDraft) .ExecuteAsync(); } - public static async Task DeleteCategory(IClient client, ICategory category) + public static async Task DeleteCategory(ProjectApiRoot client, ICategory category) { try { - await client.WithApi().WithProjectKey(DefaultProjectKey) + await client .Categories() .WithId(category.Id) .Delete() @@ -73,24 +74,24 @@ await client.WithApi().WithProjectKey(DefaultProjectKey) #region WithCategory - public static async Task WithCategory(IClient client, Func draftAction, Action func) + public static async Task WithCategory(ProjectApiRoot client, Func draftAction, Action func) { await With(client, new CategoryDraft(), draftAction, func, CreateCategory, DeleteCategory); } - public static async Task WithCategory(IClient client, Func draftAction, Func func) + public static async Task WithCategory(ProjectApiRoot client, Func draftAction, Func func) { await WithAsync(client, new CategoryDraft(), draftAction, func, CreateCategory, DeleteCategory); } - public static async Task WithCategory(IClient client, Func func) + public static async Task WithCategory(ProjectApiRoot client, Func func) { await WithAsync(client, new CategoryDraft(), DefaultCategoryDraft, func, CreateCategory, DeleteCategory); } - public static async Task WithListOfCategories(IClient client, Func draftAction, int count, Func, Task> func) + public static async Task WithListOfCategories(ProjectApiRoot client, Func draftAction, int count, Func, Task> func) { await WithListAsync(client, new CategoryDraft(), draftAction, func, count, CreateCategory, DeleteCategory); } - public static async Task WithUpdateableCategory(IClient client, Func> func) + public static async Task WithUpdateableCategory(ProjectApiRoot client, Func> func) { await WithUpdateableAsync(client, new CategoryDraft(), DefaultCategoryDraft, func, CreateCategory, DeleteCategory); } diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Categories/CategoriesIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Categories/CategoriesIntegrationTests.cs index 9987c0ec526..3dcdc147100 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Categories/CategoriesIntegrationTests.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Categories/CategoriesIntegrationTests.cs @@ -16,14 +16,11 @@ namespace commercetools.Api.IntegrationTests.Categories [Collection("Integration Tests")] public class CategoriesIntegrationTests { - private readonly IClient _client; - private readonly string _projectKey; + private readonly ProjectApiRoot _client; public CategoriesIntegrationTests(ServiceProviderFixture serviceProviderFixture) { - var clientConfiguration = serviceProviderFixture.GetClientConfiguration("Client"); - this._client = serviceProviderFixture.GetService(); - this._projectKey = clientConfiguration.ProjectKey; + this._client = serviceProviderFixture.GetService(); } [Fact] @@ -47,7 +44,7 @@ await WithCategory( async category => { Assert.NotNull(category); - var retrievedCategory = await _client.WithApi().WithProjectKey(_projectKey) + var retrievedCategory = await _client .Categories() .WithId(category.Id) .Get() @@ -67,7 +64,7 @@ await WithCategory( async category => { Assert.NotNull(category); - var retrievedCategory = await _client.WithApi(_projectKey) + var retrievedCategory = await _client .Categories() .WithKey(category.Key) .Get() @@ -87,7 +84,7 @@ await WithCategory( async category => { Assert.NotNull(category); - var returnedSet = await _client.WithApi().WithProjectKey(_projectKey) + var returnedSet = await _client .Categories() .Get() .WithQuery(q => q.Key().Is(category.Key)) @@ -108,7 +105,7 @@ await WithCategory( { Assert.NotNull(category); - var returnedSet = await _client.WithApi().WithProjectKey(_projectKey) + var returnedSet = await _client .Categories() .Get() .WithQuery(q => q.Key().Is(category.Key)) @@ -141,7 +138,7 @@ await WithListOfCategories( var orderedCategoriesNames = categoriesList.OrderBy(c => c.Name["en"]).Select(c => c.Name["en"]).ToList(); - var returnedSet = await _client.WithApi().WithProjectKey(_projectKey) + var returnedSet = await _client .Categories() .Get() .WithQuery(q => q.Parent(p => p.Id().Is(parentCategory.Id))) @@ -173,7 +170,7 @@ await WithListOfCategories( var orderedCategoriesNames = categoriesList.OrderByDescending(c => c.Name["en"]).Select(c => c.Name["en"]).ToList(); - var returnedSet = await _client.WithApi().WithProjectKey(_projectKey) + var returnedSet = await _client .Categories() .Get() .WithQuery(q => q.Parent(p => p.Id().Is(parentCategory.Id))) @@ -206,7 +203,7 @@ await WithListOfCategories( await AssertEventuallyAsync(async () => { - var returnedSet = await _client.WithApi().WithProjectKey(_projectKey) + var returnedSet = await _client .Categories() .Get() .WithQuery(q => q.Parent(p => p.Id().Is(parentCategory.Id))) @@ -237,7 +234,7 @@ await WithCategory( { Assert.NotNull(category); - await _client.WithApi().WithProjectKey(_projectKey) + await _client .Categories() .WithId(category.Id) .Delete() @@ -245,7 +242,7 @@ await _client.WithApi().WithProjectKey(_projectKey) .ExecuteAsync(); await Assert.ThrowsAsync( - () => _client.WithApi().WithProjectKey(_projectKey).Categories().WithId(category.Id).Get().ExecuteAsync()); + () => _client.Categories().WithId(category.Id).Get().ExecuteAsync()); }); } @@ -259,7 +256,7 @@ await WithCategory( { Assert.NotNull(category); - await _client.WithApi().WithProjectKey(_projectKey) + await _client .Categories() .WithKey(category.Key) .Delete() @@ -267,7 +264,7 @@ await _client.WithApi().WithProjectKey(_projectKey) .ExecuteAsync(); await Assert.ThrowsAsync( - () => _client.WithApi().WithProjectKey(_projectKey).Categories().WithId(category.Id).Get().ExecuteAsync()); + () => _client.Categories().WithId(category.Id).Get().ExecuteAsync()); }); } @@ -280,7 +277,7 @@ await WithCategory( async category => { Assert.NotNull(category); - var retrievedCategory = await _client.WithApi().WithProjectKey(_projectKey) + var retrievedCategory = await _client .Categories() .WithId(category.Id) .Get() @@ -313,7 +310,7 @@ await WithUpdateableCategory(_client, async category => Actions = new List { action } }; - var updatedCategory = await _client.WithApi().WithProjectKey(_projectKey) + var updatedCategory = await _client .Categories() .WithKey(category.Key) .Post(update) diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Channel/ChannelFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Channel/ChannelFixtures.cs new file mode 100644 index 00000000000..e0e0623b003 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Channel/ChannelFixtures.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.Channels; +using static commercetools.Api.IntegrationTests.GenericFixture; +using commercetools.Sdk.Api.Models.Common; + +namespace commercetools.Api.IntegrationTests.Channel +{ + public class ChannelFixtures + { + #region DraftBuilds + + public static ChannelDraft DefaultChannelDraft(ChannelDraft channelDraft) + { + var randomInt = TestingUtility.RandomInt(); + var randomStr = TestingUtility.RandomString(); + + channelDraft.Key = $"Channel-Key-${randomInt}"; + channelDraft.GeoLocation = new GeoJsonPoint() + { + Type = "Point", + Coordinates = new List() { 18, 9 } + }; + + channelDraft.Roles = new List() + { + IChannelRoleEnum.InventorySupply + }; + + return channelDraft; + } + + #endregion + + public static ChannelDraft DefaultChannelDraftWithKey(ChannelDraft draft, string key) + { + var channelDraft = DefaultChannelDraft(draft); + channelDraft.Key = key; + + return channelDraft; + } + + // public static async Task + public static async Task CreateChannel(ProjectApiRoot client, ChannelDraft channelDraft) + { + try + { + return await client + .Channels() + .Post(channelDraft) + .ExecuteAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteChannel(ProjectApiRoot client, IChannel channel) + { + try + { + await client + .Channels() + .WithId(channel.Id) + .Delete() + .WithVersion(channel.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithChannel(ProjectApiRoot client, Func draftAction, + Action func) + { + await With(client, new ChannelDraft(), draftAction, func, CreateChannel, DeleteChannel); + } + + public static async Task WithChannel(ProjectApiRoot client, Func draftAction, + Func func) + { + await WithAsync(client, new ChannelDraft(), draftAction, func, CreateChannel, DeleteChannel); + } + + public static async Task WithUpdateableChannel(ProjectApiRoot client, Func> func) + { + await WithUpdateableAsync(client, new ChannelDraft(), DefaultChannelDraft, func, CreateChannel, + DeleteChannel); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Channel/ChannelIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Channel/ChannelIntegrationTests.cs new file mode 100644 index 00000000000..062af1bc1ed --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Channel/ChannelIntegrationTests.cs @@ -0,0 +1,117 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.Channels; +using commercetools.Sdk.Api.Models.Common; +using Xunit; +using static commercetools.Api.IntegrationTests.Channel.ChannelFixtures; + +namespace commercetools.Api.IntegrationTests.Channel +{ + [Collection("Integration Tests")] + public class ChannelIntegrationTests + { + private readonly ProjectApiRoot _client; + private readonly string _projectKey; + + public ChannelIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + var clientConfiguration = serviceProviderFixture.GetClientConfiguration("Client"); + this._client = serviceProviderFixture.GetService(); + this._projectKey = clientConfiguration.ProjectKey; + } + + [Fact] + public async Task CreateChannel() + { + var key = $"CreateChannel-{TestingUtility.RandomString()}"; + await WithChannel( + _client, + channelDraft => DefaultChannelDraftWithKey(channelDraft, key), + channel => { Assert.Equal(key, channel.Key); } + ); + } + + [Fact] + public async Task GetChannelById() + { + var key = $"GetChannelById-{TestingUtility.RandomString()}"; + await WithChannel( + _client, + channelDraft => DefaultChannelDraftWithKey(channelDraft, key), + async channel => + { + Assert.NotNull(channel); + var retrievedChannel = await _client + .Channels() + .WithId(channel.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedChannel); + Assert.Equal(key, retrievedChannel.Key); + } + ); + } + + [Fact] + public async Task QueryChannels() + { + var key = $"QueryChannels-{TestingUtility.RandomString()}"; + await WithChannel( + _client, + channelDraft => DefaultChannelDraftWithKey(channelDraft, key), + async channel => + { + Assert.NotNull(channel); + var returnedSet = await _client + .Channels() + .Get() + .WithQuery(q => q.Key().Is(channel.Key)) + .ExecuteAsync(); + + Assert.Single(returnedSet.Results); + Assert.Equal(key, returnedSet.Results[0].Key); + }); + } + + [Fact] + public async Task UpdateChannelByIdSetGeoLocation() + { + await WithUpdateableChannel( + _client, + async channel => + { + Assert.NotNull(channel); + var location = new GeoJsonPoint() + { + Type = "Point", + Coordinates = new List() { 0, 0 } + }; + + var action = new ChannelSetGeoLocationAction() + { + Action = "setGeoLocation", + GeoLocation = location + }; + + var update = new ChannelUpdate() + { + Version = channel.Version, + Actions = new List() { action } + }; + + var updatedChannel = await _client + .Channels() + .WithId(channel.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedChannel.GeoLocation.ToString(), location.ToString()); + return updatedChannel; + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomObject/CustomObjectFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomObject/CustomObjectFixtures.cs new file mode 100644 index 00000000000..624dfe597bf --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomObject/CustomObjectFixtures.cs @@ -0,0 +1,98 @@ +using System; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.CustomObjects; +using static commercetools.Api.IntegrationTests.GenericFixture; +using commercetools.Sdk.Api.Extensions; + +namespace commercetools.Api.IntegrationTests.CustomObject +{ + public class CustomObjectFixtures + { + #region DraftBuilds + + public static CustomObjectDraft DefaultCustomObjectDraft(CustomObjectDraft customObjectDraft) + { + var randomInt = TestingUtility.RandomInt(); + var randomStr = TestingUtility.RandomString(); + + customObjectDraft.Key = $"CustomObject-Key-{randomStr}"; + customObjectDraft.Container = $"container-{randomStr}"; + customObjectDraft.Value = 5; + + return customObjectDraft; + } + + #endregion + + public static CustomObjectDraft DefaultCustomObjectDraftWithKey(CustomObjectDraft draft, string key) + { + var customObjectDraft = DefaultCustomObjectDraft(draft); + customObjectDraft.Key = key; + + return customObjectDraft; + } + + public static async Task CreateCustomObject(ProjectApiRoot client, CustomObjectDraft customObjectDraft) + { + try + { + return await client + .CustomObjects() + .Post(customObjectDraft) + .ExecuteAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteCustomObject(ProjectApiRoot client, ICustomObject customObject) + { + try + { + await client + .CustomObjects() + .WithContainerAndKey(customObject.Container, customObject.Key) + .Delete() + .WithVersion(customObject.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithCustomObject(ProjectApiRoot client, + Func draftAction, + Action func) + { + await With(client, new CustomObjectDraft(), draftAction, func, CreateCustomObject, + DeleteCustomObject); + } + + public static async Task WithCustomObject(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new CustomObjectDraft(), draftAction, func, CreateCustomObject, + DeleteCustomObject); + } + + public static async Task WithUpdateableCustomObject(ProjectApiRoot client, + Func> func) + { + await WithUpdateableAsync(client, new CustomObjectDraft(), DefaultCustomObjectDraft, func, + CreateCustomObject, + DeleteCustomObject); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomObject/CustomObjectsIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomObject/CustomObjectsIntegrationTests.cs new file mode 100644 index 00000000000..a2779d6d257 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomObject/CustomObjectsIntegrationTests.cs @@ -0,0 +1,112 @@ +using System; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.CustomObjects; +using Xunit; +using static commercetools.Api.IntegrationTests.CustomObject.CustomObjectFixtures; + +namespace commercetools.Api.IntegrationTests.CustomObject +{ + [Collection("Integration Tests")] + public class CustomObjectIntegrationTests + { + private readonly ProjectApiRoot _client; + + public CustomObjectIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateCustomObject() + { + var key = $"CreateCustomObject-{TestingUtility.RandomString()}"; + await WithCustomObject( + _client, + customObjectDraft => DefaultCustomObjectDraftWithKey(customObjectDraft, key), + customer => { Assert.Equal(key, customer.Key); } + ); + } + + [Fact] + public async Task GetCustomObjectById() + { + var key = $"GetCustomObjectById-{TestingUtility.RandomString()}"; + await WithCustomObject( + _client, + customObjectDraft => DefaultCustomObjectDraftWithKey(customObjectDraft, key), + async customObject => + { + Assert.NotNull(customObject); + var retrievedCustomObject = await _client + .CustomObjects() + .WithContainerAndKey(customObject.Container, customObject.Key) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedCustomObject); + Assert.Equal(key, retrievedCustomObject.Key); + } + ); + } + + [Fact] + public async Task QueryCustomObject() + { + var key = $"QueryCustomObjects-{TestingUtility.RandomString()}"; + await WithCustomObject( + _client, + customerDraft => DefaultCustomObjectDraftWithKey(customerDraft, key), + async customer => + { + Assert.NotNull(customer); + var returnedSet = await _client + .CustomObjects() + .Get() + .WithQuery(q => q.Key().Is(customer.Key)) + .ExecuteAsync(); + + Assert.Single(returnedSet.Results); + Assert.Equal(key, returnedSet.Results[0].Key); + }); + } + + [Fact] + public async Task UpdateCustomObjectById() + { + await WithUpdateableCustomObject( + _client, + async customObject => + { + try + { + Assert.NotNull(customObject); + var name = $"New-Custom-Object-Value-{TestingUtility.RandomString()}"; + + var update = new CustomObjectDraft() + { + Key = customObject.Key, + Container = customObject.Container, + Value = name + }; + + var updatedCustomObject = await _client + .CustomObjects() + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedCustomObject.Key, customObject.Key); + return updatedCustomObject; + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomerGroup/CustomerGroupFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomerGroup/CustomerGroupFixtures.cs new file mode 100644 index 00000000000..3eab84a6526 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomerGroup/CustomerGroupFixtures.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.CustomerGroups; +using static commercetools.Api.IntegrationTests.GenericFixture; + +namespace commercetools.Api.IntegrationTests.CustomerGroup +{ + public class CustomerGroupFixtures + { + #region DraftBuilds + + public static CustomerGroupDraft DefaultCustomerGroupDraft(CustomerGroupDraft customerGroupsDraft) + { + var randomStr = TestingUtility.RandomString(); + customerGroupsDraft.GroupName = $"Test-name-customerGroup-{randomStr}"; + + return customerGroupsDraft; + } + + #endregion + + public static CustomerGroupDraft DefaultCustomerGroupDraftWithKey(CustomerGroupDraft draft, string key) + { + var customerGroupDraft = DefaultCustomerGroupDraft(draft); + customerGroupDraft.Key = key; + + return customerGroupDraft; + } + + // public static async Task + public static async Task CreateCustomerGroup(ProjectApiRoot client, CustomerGroupDraft customerGroupsDraft) + { + try + { + return await client + .CustomerGroups() + .Post(customerGroupsDraft) + .ExecuteAsync() + .ContinueWith(r => r.Result); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteCustomerGroup(ProjectApiRoot client, ICustomerGroup customerGroup) + { + try + { + await client + .Customers() + .WithKey(customerGroup.Key) + .Delete() + .WithVersion(customerGroup.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithCustomerGroup(ProjectApiRoot client, + Func draftAction, + Action func) + { + await With(client, new CustomerGroupDraft(), draftAction, func, CreateCustomerGroup, DeleteCustomerGroup); + } + + public static async Task WithCustomerGroup(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new CustomerGroupDraft(), draftAction, func, CreateCustomerGroup, + DeleteCustomerGroup); + } + + public static async Task WithUpdateableCustomerGroup(ProjectApiRoot client, Func> func) + { + await WithUpdateableAsync(client, new CustomerGroupDraft(), DefaultCustomerGroupDraft, func, CreateCustomerGroup, + DeleteCustomerGroup); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomerGroup/CustomerGroupIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomerGroup/CustomerGroupIntegrationTests.cs new file mode 100644 index 00000000000..aba88252bcb --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/CustomerGroup/CustomerGroupIntegrationTests.cs @@ -0,0 +1,109 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.CustomerGroups; +using Xunit; +using static commercetools.Api.IntegrationTests.CustomerGroup.CustomerGroupFixtures; + +namespace commercetools.Api.IntegrationTests.CustomerGroup +{ + [Collection("Integration Tests")] + public class CustomerIntegrationTests + { + private readonly ProjectApiRoot _client; + + public CustomerIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateCustomerGroup() + { + var key = $"CreateCustomer-{TestingUtility.RandomString()}"; + await WithCustomerGroup( + _client, + customerGroupDraft => DefaultCustomerGroupDraftWithKey(customerGroupDraft, key), + customerGroup => { Assert.Equal(key, customerGroup.Key); } + ); + } + + [Fact] + public async Task GetCustomerGroupById() + { + var key = $"GetCustomerById-{TestingUtility.RandomString()}"; + await WithCustomerGroup( + _client, + customerDraft => DefaultCustomerGroupDraftWithKey(customerDraft, key), + async customerGroup => + { + Assert.NotNull(customerGroup); + var retrievedCustomer = await _client + .CustomerGroups() + .WithId(customerGroup.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedCustomer); + Assert.Equal(key, retrievedCustomer.Key); + } + ); + } + + [Fact] + public async Task QueryCustomersGroup() + { + var key = $"QueryCustomers-{TestingUtility.RandomString()}"; + await WithCustomerGroup( + _client, + customerDraft => DefaultCustomerGroupDraftWithKey(customerDraft, key), + async customerGroup => + { + Assert.NotNull(customerGroup); + var returnedSet = await _client + .CustomerGroups() + .Get() + .WithQuery(q => q.Key().Is(customerGroup.Key)) + .ExecuteAsync(); + + Assert.Single(returnedSet.Results); + Assert.Equal(key, returnedSet.Results[0].Key); + }); + } + + [Fact] + public async Task UpdateCustomerGroupByIdChangeKey() + { + await WithUpdateableCustomerGroup( + _client, + async customerGroup => + { + Assert.NotNull(customerGroup); + var name = $"{TestingUtility.RandomString()}"; + var action = new CustomerGroupSetKeyAction() + { + Action = "setKey", + Key = name + }; + + var update = new CustomerGroupUpdate() + { + Version = customerGroup.Version, + Actions = new List() { action } + }; + + var updatedCustomerGroup = await _client + .CustomerGroups() + .WithId(customerGroup.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedCustomerGroup.Key, name); + return updatedCustomerGroup; + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Customers/CustomersFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Customers/CustomersFixtures.cs new file mode 100644 index 00000000000..ea11cfc2188 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Customers/CustomersFixtures.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.Customers; +using static commercetools.Api.IntegrationTests.GenericFixture; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Common; + +namespace commercetools.Api.IntegrationTests.Customers +{ + public class CustomersFixtures + { + #region DraftBuilds + + public static CustomerDraft DefaultCustomerDraft(CustomerDraft customerDraft) + { + var randomInt = TestingUtility.RandomInt(); + var randomStr = TestingUtility.RandomString(); + customerDraft.Email = $"test-{randomStr}@mail.com"; + customerDraft.FirstName = "test-first-name"; + customerDraft.LastName = "test-last-name"; + customerDraft.Password = $"test-password-{randomStr}"; + + // customerDraft.Addresses = new List() + // { + // new BaseAddress() { Country = "DE", Key = $"Key{randomInt}" } + // }; + + return customerDraft; + } + + #endregion + + public static CustomerDraft DefaultCustomerDraftWithKey(CustomerDraft draft, string key) + { + var customerDraft = DefaultCustomerDraft(draft); + customerDraft.Key = key; + + return customerDraft; + } + + public static async Task CreateCustomer(ProjectApiRoot client, CustomerDraft customerDraft) + { + try + { + return await client + .Customers() + .Post(customerDraft) + .ExecuteAsync() + .ContinueWith(r => r.Result.Customer); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteCustomer(ProjectApiRoot client, ICustomer customer) + { + try + { + await client + .Customers() + .WithKey(customer.Key) + .Delete() + .WithVersion(customer.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithCustomer(ProjectApiRoot client, Func draftAction, + Action func) + { + await With(client, new CustomerDraft(), draftAction, func, CreateCustomer, DeleteCustomer); + } + + public static async Task WithCustomer(ProjectApiRoot client, Func draftAction, + Func func) + { + await WithAsync(client, new CustomerDraft(), draftAction, func, CreateCustomer, DeleteCustomer); + } + + public static async Task WithCart(ProjectApiRoot client, Func func) + { + await WithAsync(client, new CustomerDraft(), DefaultCustomerDraft, func, CreateCustomer, DeleteCustomer); + } + + public static async Task WithUpdateableCustomer(ProjectApiRoot client, Func> func) + { + await WithUpdateableAsync(client, new CustomerDraft(), DefaultCustomerDraft, func, CreateCustomer, + DeleteCustomer); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Customers/CustomersIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Customers/CustomersIntegrationTests.cs new file mode 100644 index 00000000000..15e1d2834dd --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Customers/CustomersIntegrationTests.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Base.Client.Error; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Carts; +using commercetools.Sdk.Api.Models.Customers; +using Xunit; +using static commercetools.Api.IntegrationTests.Customers.CustomersFixtures; + +namespace commercetools.Api.IntegrationTests.Customers +{ + [Collection("Integration Tests")] + public class CustomerIntegrationTests + { + private readonly ProjectApiRoot _client; + private readonly string _projectKey; + + public CustomerIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateCustomer() + { + var key = $"CreateCustomer-{TestingUtility.RandomString()}"; + await WithCustomer( + _client, + customerDraft => DefaultCustomerDraftWithKey(customerDraft, key), + customer => { Assert.Equal(key, customer.Key); } + ); + } + + [Fact] + public async Task GetCustomerById() + { + var key = $"GetCustomerById-{TestingUtility.RandomString()}"; + await WithCustomer( + _client, + customerDraft => DefaultCustomerDraftWithKey(customerDraft, key), + async customer => + { + Assert.NotNull(customer); + var retrievedCustomer = await _client + .Customers() + .WithId(customer.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedCustomer); + Assert.Equal(key, retrievedCustomer.Key); + } + ); + } + + [Fact] + public async Task QueryCustomers() + { + var key = $"QueryCustomers-{TestingUtility.RandomString()}"; + await WithCustomer( + _client, + customerDraft => DefaultCustomerDraftWithKey(customerDraft, key), + async customer => + { + Assert.NotNull(customer); + var returnedSet = await _client + .Customers() + .Get() + .WithQuery(q => q.Key().Is(customer.Key)) + .ExecuteAsync(); + + Assert.Single(returnedSet.Results); + Assert.Equal(key, returnedSet.Results[0].Key); + }); + } + + [Fact] + public async Task UpdateCustomerByIdChangeFirstName() + { + await WithUpdateableCustomer( + _client, + async customer => + { + Assert.NotNull(customer); + var name = $"{TestingUtility.RandomString()}"; + var action = new CustomerSetFirstNameAction() + { + Action = "setFirstName", + FirstName = name + }; + + var update = new CustomerUpdate() + { + Version = customer.Version, + Actions = new List() { action } + }; + + var updatedCustomer = await _client + .Customers() + .WithId(customer.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedCustomer.FirstName, name); + return updatedCustomer; + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/DiscountCodes/DiscountCodesFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/DiscountCodes/DiscountCodesFixtures.cs new file mode 100644 index 00000000000..c2d014c380e --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/DiscountCodes/DiscountCodesFixtures.cs @@ -0,0 +1,104 @@ +using System; +using System.Threading.Tasks; +using commercetools.Sdk.Api.Models.Common; +using commercetools.Sdk.Api.Models.DiscountCodes; +using commercetools.Sdk.Api.Client; +using static commercetools.Api.IntegrationTests.GenericFixture; + +namespace commercetools.Api.IntegrationTests.DiscountCodes +{ + public class DiscountCodesFixtures + { + #region DraftBuilds + + public static DiscountCodeDraft DefaultDiscountCodesDraft(DiscountCodeDraft discountCodeDraft) + { + discountCodeDraft.Name = new LocalizedString { { "en", "Name" } }; + discountCodeDraft.CartPredicate = "country=\"DE\""; + discountCodeDraft.IsActive = false; + + return discountCodeDraft; + } + + public static DiscountCodeDraft DefaultDiscountCodeDraftWithKey(DiscountCodeDraft draft, string key) + { + var discountCodeDraft = DefaultDiscountCodesDraft(draft); + discountCodeDraft.Key = key; + + return discountCodeDraft; + } + + #endregion + + #region CreateAndDelete + + public static async Task CreateDiscountCodes(ProjectApiRoot client, DiscountCodeDraft discountCodeDraft) + { + var resource = await client + .DiscountCodes() + .Post(discountCodeDraft) + .ExecuteAsync(); + + return resource; + } + + public static async Task DeleteDiscountCodes(ProjectApiRoot client, IDiscountCode discountCode) + { + try + { + await client + .DiscountCodes() + .WithId(discountCode.Id) + .Delete() + .WithVersion(discountCode.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #endregion + + #region WithDiscountCodes + + public static async Task WithDiscountCodes(ProjectApiRoot client, + Func draftAction, Action func) + { + await With(client, new DiscountCodeDraft(), draftAction, func, CreateDiscountCodes, DeleteDiscountCodes); + } + + public static async Task WithDiscountCodes(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new DiscountCodeDraft(), draftAction, func, CreateDiscountCodes, + DeleteDiscountCodes); + } + + public static async Task WithDiscountCodes(ProjectApiRoot client, Func func) + { + await WithAsync(client, new DiscountCodeDraft(), DefaultDiscountCodesDraft, func, CreateDiscountCodes, + DeleteDiscountCodes); + } + + public static async Task WithUpdateableDiscountCodes(ProjectApiRoot client, + Func> func) + { + await WithUpdateableAsync(client, new DiscountCodeDraft(), DefaultDiscountCodesDraft, func, + CreateDiscountCodes, + DeleteDiscountCodes); + } + + public static async Task WithUpdateableDiscountCodes(ProjectApiRoot client, Func draftAction, + Func> func) + { + await WithUpdateableAsync(client, new DiscountCodeDraft(), draftAction, func, + CreateDiscountCodes, + DeleteDiscountCodes); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/DiscountCodes/DiscountCodesIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/DiscountCodes/DiscountCodesIntegrationTests.cs new file mode 100644 index 00000000000..d7cb5311f29 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/DiscountCodes/DiscountCodesIntegrationTests.cs @@ -0,0 +1,214 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.CartDiscounts; +using commercetools.Sdk.Api.Models.Common; +using commercetools.Sdk.Api.Models.DiscountCodes; +using static commercetools.Api.IntegrationTests.CartDiscount.CartDiscountFixtures; +using static commercetools.Api.IntegrationTests.DiscountCodes.DiscountCodesFixtures; +using Xunit; + +namespace commercetools.Api.IntegrationTests.DiscountCodes +{ + [Collection("Integration Tests")] + public class DiscountCodesIntegrationTests + { + private readonly ProjectApiRoot _projectApiRoot; + + public DiscountCodesIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._projectApiRoot = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateDiscountCodes() + { + // create CartDiscount code + var key = $"CreateCartDiscount-{TestingUtility.RandomString()}"; + await WithCartDiscount( + _projectApiRoot, + cartDiscountDraft => DefaultCartDiscountDraftWithKey(cartDiscountDraft, key), + async cartDiscount => + { + Assert.Equal(key, cartDiscount.Key); + // create DiscountCodes + await WithDiscountCodes( + _projectApiRoot, + discountCodesDraft => + { + discountCodesDraft.Code = TestingUtility.RandomString(); + discountCodesDraft.CartDiscounts = new List() + { + new CartDiscountResourceIdentifier() + { + TypeId = IReferenceTypeId.CartDiscount, + Id = cartDiscount.Id + } + }; + return DefaultDiscountCodesDraft(discountCodesDraft); + }, + discountCode => + { + var codes = discountCode.Code; + Assert.NotNull(discountCode); + Assert.Equal(codes, discountCode.Code); + } + ); + } + ); + } + + [Fact] + public async Task GetDiscountCodeById() + { + // create CartDiscount code + var key = $"CreateCartDiscount-{TestingUtility.RandomString()}"; + var keys = $"CreateCartDiscount-{TestingUtility.RandomString()}"; + + await WithCartDiscount( + _projectApiRoot, + cartDiscountDraft => DefaultCartDiscountDraftWithKey(cartDiscountDraft, key), + async cartDiscount => + { + Assert.Equal(key, cartDiscount.Key); + // create DiscountCodes + await WithDiscountCodes( + _projectApiRoot, + discountCodesDraft => + { + discountCodesDraft.Code = TestingUtility.RandomString(); + discountCodesDraft.CartDiscounts = new List() + { + new CartDiscountResourceIdentifier() + { + TypeId = IReferenceTypeId.CartDiscount, + Id = cartDiscount.Id + } + }; + return DefaultDiscountCodeDraftWithKey(discountCodesDraft, keys); + }, + async discountCode => + { + Assert.NotNull(discountCode); + var retrievedDiscountCode = await _projectApiRoot + .DiscountCodes() + .WithId(discountCode.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedDiscountCode); + Assert.Equal(keys, retrievedDiscountCode.Key); + } + ); + } + ); + } + + [Fact] + public async Task QueryDiscountCodeById() + { + // create CartDiscount code + var key = $"CreateCartDiscount-{TestingUtility.RandomString()}"; + var keys = $"CreateCartDiscount-{TestingUtility.RandomString()}"; + + await WithCartDiscount( + _projectApiRoot, + cartDiscountDraft => DefaultCartDiscountDraftWithKey(cartDiscountDraft, key), + async cartDiscount => + { + Assert.Equal(key, cartDiscount.Key); + // create DiscountCodes + await WithDiscountCodes( + _projectApiRoot, + discountCodesDraft => + { + discountCodesDraft.Code = TestingUtility.RandomString(); + discountCodesDraft.CartDiscounts = new List() + { + new CartDiscountResourceIdentifier() + { + TypeId = IReferenceTypeId.CartDiscount, + Id = cartDiscount.Id + } + }; + return DefaultDiscountCodeDraftWithKey(discountCodesDraft, keys); + }, + async discountCode => + { + Assert.NotNull(discountCode); + var retrievedDiscountCode = await _projectApiRoot + .DiscountCodes() + .Get() + .WithQuery(d => d.Id().Is(discountCode.Id)) + .ExecuteAsync(); + + Assert.NotNull(retrievedDiscountCode); + } + ); + } + ); + } + + [Fact] + public async Task UpdateDiscountCodeByIdSetKey() + { + // create CartDiscount code + var key = $"Create-CartDiscount-{TestingUtility.RandomString()}"; + var discountCodeDraftKeys = $"Create-DiscountCode-{TestingUtility.RandomString()}"; + + await WithCartDiscount( + _projectApiRoot, + cartDiscountDraft => DefaultCartDiscountDraftWithKey(cartDiscountDraft, key), + async cartDiscount => + { + Assert.Equal(key, cartDiscount.Key); + // update DiscountCodes + await WithUpdateableDiscountCodes( + _projectApiRoot, + discountCodesDraft => + { + discountCodesDraft.Code = TestingUtility.RandomString(); + discountCodesDraft.CartDiscounts = new List() + { + new CartDiscountResourceIdentifier() + { + TypeId = IReferenceTypeId.CartDiscount, + Id = cartDiscount.Id + } + }; + return DefaultDiscountCodeDraftWithKey(discountCodesDraft, discountCodeDraftKeys); + }, + async discountCode => + { + Assert.NotNull(discountCode); + var discountCodeKey = $"Test-DiscountCodeKey-{TestingUtility.RandomString()}"; + + var action = new DiscountCodeSetKeyAction() + { + Action = "setKey", + Key = discountCodeKey + }; + + var update = new DiscountCodeUpdate() + { + Version = discountCode.Version, + Actions = new List() { action } + }; + + var updatedDiscountCode = await _projectApiRoot + .DiscountCodes() + .WithId(discountCode.Id) + .Post(update) + .ExecuteAsync(); + + Assert.NotNull(updatedDiscountCode); + Assert.Equal(discountCodeKey, updatedDiscountCode.Key); + + return updatedDiscountCode; + } + ); + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Errors/ErrorsIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Errors/ErrorsIntegrationTests.cs index 278634c8485..03d77ec9d64 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Errors/ErrorsIntegrationTests.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Errors/ErrorsIntegrationTests.cs @@ -6,6 +6,7 @@ using commercetools.Sdk.Api.Models.Errors; using commercetools.Base.Client; using commercetools.Base.Client.Error; +using commercetools.Sdk.Api.Client; using commercetools.Sdk.Api.Extensions; using Xunit; using static commercetools.Api.IntegrationTests.Categories.CategoriesFixture; @@ -15,13 +16,13 @@ namespace commercetools.Api.IntegrationTests.Errors [Collection("Integration Tests")] public class ErrorsIntegrationTests { - private readonly IClient _client; + private readonly ProjectApiRoot _client; private readonly string _projectKey; public ErrorsIntegrationTests(ServiceProviderFixture serviceProviderFixture) { var clientConfiguration = serviceProviderFixture.GetClientConfiguration("Client"); - this._client = serviceProviderFixture.GetService(); + this._client = serviceProviderFixture.GetService(); this._projectKey = clientConfiguration.ProjectKey; } @@ -43,7 +44,7 @@ await WithUpdateableCategory(_client, async category => Actions = new List { action } }; - var updatedCategory = await _client.WithApi(_projectKey) + var updatedCategory = await _client .Categories() .WithKey(category.Key) .Post(update) @@ -55,7 +56,7 @@ await WithUpdateableCategory(_client, async category => try { //do the same update again with the same version - await _client.WithApi(_projectKey) + await _client .Categories() .WithKey(category.Key) .Post(update) diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Extension/ExtensionFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Extension/ExtensionFixtures.cs new file mode 100644 index 00000000000..13298a72efd --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Extension/ExtensionFixtures.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.Extensions; +using static commercetools.Api.IntegrationTests.GenericFixture; +using commercetools.Sdk.Api.Extensions; + +namespace commercetools.Api.IntegrationTests.Extension +{ + public class ExtensionFixtures + { + #region DraftBuilds + + public static ExtensionDraft DefaultExtensionDraft(ExtensionDraft extensionDraft) + { + var randomInt = TestingUtility.RandomInt(); + var randomStr = TestingUtility.RandomString(); + + var action = new ExtensionAction() { }; + + extensionDraft.Destination = new HttpDestination() + { + Type = "HTTP", + Url = "https://www.commercetools.com" + }; + extensionDraft.Triggers = new List() + { + new ExtensionTrigger() + { + ResourceTypeId = IExtensionResourceTypeId.Cart, + Actions = new List() + { + IExtensionAction.Create + } + } + }; + + return extensionDraft; + } + + #endregion + + public static ExtensionDraft DefaultExtensionDraftWithKey(ExtensionDraft draft, string key) + { + var extensionDraft = DefaultExtensionDraft(draft); + extensionDraft.Key = key; + + return extensionDraft; + } + + public static async Task CreateExtension(ProjectApiRoot client, ExtensionDraft extensionDraft) + { + try + { + return await client + .Extensions() + .Post(extensionDraft) + .ExecuteAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteExtension(ProjectApiRoot client, IExtension extension) + { + try + { + await client + .Extensions() + .WithKey(extension.Key) + .Delete() + .WithVersion(extension.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithExtension(ProjectApiRoot client, Func draftAction, + Action func) + { + await With(client, new ExtensionDraft(), draftAction, func, CreateExtension, DeleteExtension); + } + + public static async Task WithExtension(ProjectApiRoot client, Func draftAction, + Func func) + { + await WithAsync(client, new ExtensionDraft(), draftAction, func, CreateExtension, DeleteExtension); + } + + public static async Task WithExtension(ProjectApiRoot client, Func func) + { + await WithAsync(client, new ExtensionDraft(), DefaultExtensionDraft, func, CreateExtension, + DeleteExtension); + } + + public static async Task WithUpdateableExtension(ProjectApiRoot client, Func> func) + { + await WithUpdateableAsync(client, new ExtensionDraft(), DefaultExtensionDraft, func, CreateExtension, + DeleteExtension); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Extension/ExtensionIntegratedTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Extension/ExtensionIntegratedTests.cs new file mode 100644 index 00000000000..e664fa95f51 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Extension/ExtensionIntegratedTests.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Base.Client.Error; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Carts; +using commercetools.Sdk.Api.Models.Extensions; +using Xunit; +using static commercetools.Api.IntegrationTests.Extension.ExtensionFixtures; + +namespace commercetools.Api.IntegrationTests.Extension +{ + [Collection("Integration Tests")] + public class ExtensionIntegrationTests + { + private readonly ProjectApiRoot _client; + + public ExtensionIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateExtension() + { + var key = $"CreateExtension-{TestingUtility.RandomString()}"; + await WithExtension( + _client, + extensionDraft => DefaultExtensionDraftWithKey(extensionDraft, key), + extension => { Assert.Equal(key, extension.Key); } + ); + } + + [Fact] + public async Task GetExtensionById() + { + var key = $"GetExtensionById-{TestingUtility.RandomString()}"; + await WithExtension( + _client, + extensionDraft => DefaultExtensionDraftWithKey(extensionDraft, key), + async extension => + { + Assert.NotNull(extension); + var retrievedExtension = await _client + .Extensions() + .WithId(extension.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedExtension); + Assert.Equal(key, retrievedExtension.Key); + } + ); + } + + // [Fact] + // public async Task QueryExtensions() + // { + // var key = $"QueryExtensions-{TestingUtility.RandomString()}"; + // await WithExtension( + // _client, + // extensionDraft => DefaultExtensionDraftWithKey(extensionDraft, key), + // async extension => + // { + // Assert.NotNull(extension); + // var returnedSet = await _client + // .WithApi() + // .WithProjectKey(_projectKey) + // .Extensions() + // .Get() + // // .WithQuery(q => q.Key().Is(extension.Key)) + // .ExecuteAsync(); + // + // Assert.Single(returnedSet.Results); + // Assert.Equal(key, returnedSet.Results[0].Key); + // }); + // } + + // [Fact] + // public async Task UpdateExtensionByIdChangeFirstName() + // { + // await WithUpdateableExtension( + // _client, + // async extension => + // { + // Assert.NotNull(extension); + // var name = $"{TestingUtility.RandomString()}"; + // var action = new ExtensionSetFirstNameAction() + // { + // Action = "setFirstName", + // FirstName = name + // }; + // + // var update = new ExtensionUpdate() + // { + // Version = extension.Version, + // Actions = new List() { action } + // }; + // + // var updatedExtension = await _client + // .WithApi() + // .WithProjectKey(_projectKey) + // .Extensions() + // .WithId(extension.Id) + // .Post(update) + // .ExecuteAsync(); + // + // Assert.Equal(updatedExtension.FirstName, name); + // return updatedExtension; + // } + // ); + // } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Inventory/InventoryFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Inventory/InventoryFixtures.cs new file mode 100644 index 00000000000..2645934af17 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Inventory/InventoryFixtures.cs @@ -0,0 +1,101 @@ +using System; +using System.Threading.Tasks; +using commercetools.Sdk.Api.Models.Inventories; +using commercetools.Sdk.Api.Client; +using static commercetools.Api.IntegrationTests.GenericFixture; + +namespace commercetools.Api.IntegrationTests.Inventory +{ + public class InventoryFixtures + { + #region DraftBuilds + + public static InventoryEntryDraft DefaultInventoryEntryDraft(InventoryEntryDraft inventoryDraft) + { + inventoryDraft.Sku = $"Test-Inventory-Sku-{TestingUtility.RandomString()}"; + inventoryDraft.QuantityOnStock = 8; + return inventoryDraft; + } + + public static InventoryEntryDraft DefaultInventoryEntryDraftWithKey(InventoryEntryDraft draft, string key) + { + var inventoryDraft = DefaultInventoryEntryDraft(draft); + inventoryDraft.Key = key; + + return inventoryDraft; + } + + #endregion + + #region CreateAndDelete + + public static async Task CreateInventory(ProjectApiRoot client, InventoryEntryDraft inventoryDraft) + { + var resource = await client + .Inventory() + .Post(inventoryDraft) + .ExecuteAsync(); + + return resource; + } + + public static async Task DeleteInventory(ProjectApiRoot client, IInventoryEntry inventory) + { + try + { + await client + .Inventory() + .WithId(inventory.Id) + .Delete() + .WithVersion(inventory.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #endregion + + #region WithInventoryEntrys + + public static async Task WithInventory(ProjectApiRoot client, + Func draftAction, Action func) + { + await With(client, new InventoryEntryDraft(), draftAction, func, CreateInventory, DeleteInventory); + } + + public static async Task WithInventory(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new InventoryEntryDraft(), draftAction, func, CreateInventory, + DeleteInventory); + } + + public static async Task WithInventory(ProjectApiRoot client, Func func) + { + await WithAsync(client, new InventoryEntryDraft(), DefaultInventoryEntryDraft, func, CreateInventory, + DeleteInventory); + } + + public static async Task WithUpdateableInventory(ProjectApiRoot client, + Func> func) + { + await WithUpdateableAsync(client, new InventoryEntryDraft(), DefaultInventoryEntryDraft, func, + CreateInventory, + DeleteInventory); + } + + public static async Task WithUpdateableInventory(ProjectApiRoot client, Func draftAction, + Func> func) + { + await WithUpdateableAsync(client, new InventoryEntryDraft(), draftAction, func, + CreateInventory, + DeleteInventory); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Inventory/InventoryIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Inventory/InventoryIntegrationTests.cs new file mode 100644 index 00000000000..9a63d015507 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Inventory/InventoryIntegrationTests.cs @@ -0,0 +1,205 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.Channels; +using commercetools.Sdk.Api.Models.Common; +using commercetools.Sdk.Api.Models.Inventories; +using static commercetools.Api.IntegrationTests.Channel.ChannelFixtures; +using static commercetools.Api.IntegrationTests.Inventory.InventoryFixtures; +using Xunit; + +namespace commercetools.Api.IntegrationTests.Inventory +{ + [Collection("Integration Tests")] + public class InventoryIntegrationTests + { + private readonly ProjectApiRoot _projectApiRoot; + + public InventoryIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._projectApiRoot = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateInventory() + { + // create Channel + var key = $"Create-Channel-{TestingUtility.RandomString()}"; + var inventoryKey = $"Test-Inventory-Key-{TestingUtility.RandomString()}"; + + await WithChannel( + _projectApiRoot, + channelDraft => DefaultChannelDraftWithKey(channelDraft, key), + async channel => + { + Assert.Equal(key, channel.Key); + // create Inventory + await WithInventory( + _projectApiRoot, + inventoryDraft => + { + inventoryDraft.Key = inventoryKey; + inventoryDraft.SupplyChannel = new ChannelResourceIdentifier() + { + Id = channel.Id, + TypeId = IReferenceTypeId.Channel + }; + + return DefaultInventoryEntryDraft(inventoryDraft); + }, + inventory => + { + Assert.NotNull(inventory); + Assert.Equal(inventoryKey, inventory.Key); + } + ); + } + ); + } + + [Fact] + public async Task GetInventoryById() + { + var key = $"Create-Channel-{TestingUtility.RandomString()}"; + var inventoryKey = $"Test-Inventory-Key-{TestingUtility.RandomString()}"; + + // create channel + await WithChannel( + _projectApiRoot, + channelDraft => DefaultChannelDraftWithKey(channelDraft, key), + async channel => + { + Assert.Equal(key, channel.Key); + // create Inventory + await WithInventory( + _projectApiRoot, + inventoryDraft => + { + inventoryDraft.Key = inventoryKey; + inventoryDraft.SupplyChannel = new ChannelResourceIdentifier() + { + Id = channel.Id, + TypeId = IReferenceTypeId.Channel + }; + + return DefaultInventoryEntryDraft(inventoryDraft); + }, + async inventory => + { + Assert.NotNull(inventory); + var retrievedDiscountCode = await _projectApiRoot + .Inventory() + .WithId(inventory.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedDiscountCode); + Assert.Equal(inventoryKey, retrievedDiscountCode.Key); + } + ); + } + ); + } + + [Fact] + public async Task QueryInventoryById() + { + // create Channel + var key = $"Create-Channel-{TestingUtility.RandomString()}"; + var inventoryKey = $"Test-Inventory-Key-{TestingUtility.RandomString()}"; + + await WithChannel( + _projectApiRoot, + channelDraft => DefaultChannelDraftWithKey(channelDraft, key), + async channel => + { + Assert.Equal(key, channel.Key); + // create DiscountCodes + await WithInventory( + _projectApiRoot, + inventoryEntryDraft => + { + inventoryEntryDraft.Key = inventoryKey; + inventoryEntryDraft.SupplyChannel = new ChannelResourceIdentifier() + { + TypeId = IReferenceTypeId.Channel, + Id = channel.Id + }; + + return DefaultInventoryEntryDraftWithKey(inventoryEntryDraft, inventoryKey); + }, + async inventory => + { + Assert.NotNull(inventory); + var retrievedDiscountCode = await _projectApiRoot + .Inventory() + .Get() + .WithQuery(d => d.Id().Is(inventory.Id)) + .ExecuteAsync(); + + Assert.NotNull(retrievedDiscountCode); + } + ); + } + ); + } + + [Fact] + public async Task UpdateInventoryByIdSetKey() + { + var key = $"Create-Channel-{TestingUtility.RandomString()}"; + var inventoryKey = $"Test-Inventory-Key-{TestingUtility.RandomString()}"; + + // create channel + await WithChannel( + _projectApiRoot, + channelDraft => DefaultChannelDraftWithKey(channelDraft, key), + async channel => + { + Assert.Equal(key, channel.Key); + // update Inventory + await WithUpdateableInventory( + _projectApiRoot, + inventoryEntryDraft => + { + inventoryEntryDraft.Key = inventoryKey; + inventoryEntryDraft.SupplyChannel = new ChannelResourceIdentifier() + { + TypeId = IReferenceTypeId.Channel, + Id = channel.Id + }; + + return DefaultInventoryEntryDraftWithKey(inventoryEntryDraft, inventoryKey); + }, + async inventoryEntry => + { + Assert.NotNull(inventoryEntry); + var action = new InventoryEntrySetRestockableInDaysAction() + { + Action = "setRestockableInDays", + RestockableInDays = 8 + }; + + var update = new InventoryEntryUpdate() + { + Version = inventoryEntry.Version, + Actions = new List() { action } + }; + + var updatedInventory = await _projectApiRoot + .Inventory() + .WithId(inventoryEntry.Id) + .Post(update) + .ExecuteAsync(); + + Assert.NotNull(updatedInventory); + Assert.NotEqual(inventoryEntry.Version, updatedInventory.Version); + + return updatedInventory; + } + ); + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Payments/PaymentsFixture.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Payments/PaymentsFixture.cs index 99b87f93b13..9fededf6929 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Payments/PaymentsFixture.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Payments/PaymentsFixture.cs @@ -4,6 +4,7 @@ using commercetools.Sdk.Api.Models.Common; using commercetools.Sdk.Api.Models.Payments; using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; using commercetools.Sdk.Api.Extensions; using static commercetools.Api.IntegrationTests.GenericFixture; @@ -30,20 +31,20 @@ public static PaymentDraft DefaultPaymentDraftWithTransaction(PaymentDraft draft #region CreateAndDelete - public static async Task CreatePayment(IClient client, PaymentDraft paymentDraft) + public static async Task CreatePayment(ProjectApiRoot client, PaymentDraft paymentDraft) { - var resource = await client.WithApi().WithProjectKey(DefaultProjectKey) + var resource = await client .Payments() .Post(paymentDraft) .ExecuteAsync(); return resource; } - public static async Task DeletePayment(IClient client, IPayment payment) + public static async Task DeletePayment(ProjectApiRoot client, IPayment payment) { try { - await client.WithApi().WithProjectKey(DefaultProjectKey) + await client .Payments() .WithId(payment.Id) .Delete() @@ -60,7 +61,7 @@ await client.WithApi().WithProjectKey(DefaultProjectKey) #region WithPayment - public static async Task WithPayment(IClient client, Func draftAction, Action func) + public static async Task WithPayment(ProjectApiRoot client, Func draftAction, Action func) { await With(client, new PaymentDraft(), draftAction, func, CreatePayment, DeletePayment); } diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Payments/PaymentsIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Payments/PaymentsIntegrationTests.cs index 0caa5060d51..43bc7268561 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Payments/PaymentsIntegrationTests.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Payments/PaymentsIntegrationTests.cs @@ -12,13 +12,11 @@ namespace commercetools.Api.IntegrationTests.Payments [Collection("Integration Tests")] public class PaymentsIntegrationTests { - private readonly IClient _client; - private readonly ProjectApiRoot _apiRoot; + private readonly ProjectApiRoot _client; public PaymentsIntegrationTests(ServiceProviderFixture serviceProviderFixture) { - this._client = serviceProviderFixture.GetService(); - this._apiRoot = serviceProviderFixture.GetService(); + this._client = serviceProviderFixture.GetService(); } [Fact] @@ -31,7 +29,8 @@ public async Task CreatePayment() Type = ITransactionType.Charge }; await WithPayment( - _client, paymentDraft => DefaultPaymentDraftWithTransaction(paymentDraft, transactionDraft), + _client, + paymentDraft => DefaultPaymentDraftWithTransaction(paymentDraft, transactionDraft), payment => { Assert.Single(payment.Transactions); @@ -52,7 +51,7 @@ public async Task QueryPayment() await WithPayment( _client, draft => DefaultPaymentDraft(draft), async payment => { - var queryPayment = await _apiRoot.Payments().Get().WithQuery(d => d.Id().Is(payment.Id)) + var queryPayment = await _client.Payments().Get().WithQuery(d => d.Id().Is(payment.Id)) .ExecuteAsync(); Assert.Equal(payment.Id, queryPayment.Results.FirstOrDefault().Id); } diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductDiscount/ProductDiscountFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductDiscount/ProductDiscountFixtures.cs new file mode 100644 index 00000000000..fc434d57db7 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductDiscount/ProductDiscountFixtures.cs @@ -0,0 +1,109 @@ +using System; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.ProductDiscounts; +using static commercetools.Api.IntegrationTests.GenericFixture; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Common; + +namespace commercetools.Api.IntegrationTests.ProductDiscount +{ + public class ProductDiscountFixtures + { + #region DraftBuilds + + public static ProductDiscountDraft DefaultProductDiscountDraft(ProductDiscountDraft productDiscountDraft) + { + var randomInt = TestingUtility.RandomInt(); + var randomStr = TestingUtility.RandomString(); + + productDiscountDraft.Name = new LocalizedString() { { "en", $"Special-Test-Name-{randomInt}" } }; + productDiscountDraft.Predicate = $"product.key=\"randomStr\""; + productDiscountDraft.IsActive = false; + productDiscountDraft.SortOrder = "0.65181"; + productDiscountDraft.Value = new ProductDiscountValueRelativeDraft() + { + Type = "relative", + Permyriad = 10 + }; + productDiscountDraft.Description = new LocalizedString() + { { "en", $"Test-name-productDiscount-{randomStr}" } }; + + + return productDiscountDraft; + } + + #endregion + + public static ProductDiscountDraft DefaultProductDiscountDraftWithKey(ProductDiscountDraft draft, string key) + { + var productDiscountDraft = DefaultProductDiscountDraft(draft); + productDiscountDraft.Key = key; + + return productDiscountDraft; + } + + public static async Task CreateProductDiscount(ProjectApiRoot client, + ProductDiscountDraft productDiscountDraft) + { + try + { + return await client + .ProductDiscounts() + .Post(productDiscountDraft) + .ExecuteAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteProductDiscount(ProjectApiRoot client, IProductDiscount productDiscount) + { + try + { + await client + .ProductDiscounts() + .WithId(productDiscount.Id) + .Delete() + .WithVersion(productDiscount.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithProductDiscount(ProjectApiRoot client, + Func draftAction, + Action func) + { + await With(client, new ProductDiscountDraft(), draftAction, func, CreateProductDiscount, + DeleteProductDiscount); + } + + public static async Task WithProductDiscount(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new ProductDiscountDraft(), draftAction, func, CreateProductDiscount, + DeleteProductDiscount); + } + + public static async Task WithUpdateableProductDiscount(ProjectApiRoot client, + Func> func) + { + await WithUpdateableAsync(client, new ProductDiscountDraft(), DefaultProductDiscountDraft, func, + CreateProductDiscount, + DeleteProductDiscount); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductDiscount/ProductDiscountIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductDiscount/ProductDiscountIntegrationTests.cs new file mode 100644 index 00000000000..dbf35f1cd23 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductDiscount/ProductDiscountIntegrationTests.cs @@ -0,0 +1,110 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Common; +using commercetools.Sdk.Api.Models.ProductDiscounts; +using Xunit; +using static commercetools.Api.IntegrationTests.ProductDiscount.ProductDiscountFixtures; + +namespace commercetools.Api.IntegrationTests.ProductDiscount +{ + [Collection("Integration Tests")] + public class ProductDiscountIntegrationTests + { + private readonly ProjectApiRoot _client; + private readonly string _projectKey; + + public ProductDiscountIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateProductDiscount() + { + var key = $"CreateProductDiscount-{TestingUtility.RandomString()}"; + await WithProductDiscount( + _client, productDiscountDraft => DefaultProductDiscountDraftWithKey(productDiscountDraft, key), + productDiscount => { Assert.Equal(key, productDiscount.Key); } + ); + } + + [Fact] + public async Task GetProductDiscountById() + { + var key = $"GetProductDiscountById-{TestingUtility.RandomString()}"; + await WithProductDiscount( + _client, + productDiscountDraft => DefaultProductDiscountDraftWithKey(productDiscountDraft, key), + async productDiscount => + { + Assert.NotNull(productDiscount); + var retrievedProductDiscount = await _client + .ProductDiscounts() + .WithId(productDiscount.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedProductDiscount); + Assert.Equal(key, retrievedProductDiscount.Key); + } + ); + } + + [Fact] + public async Task QueryProductDiscount() + { + var key = $"QueryProductDiscounts-{TestingUtility.RandomString()}"; + await WithProductDiscount( + _client, + productDiscountDraft => DefaultProductDiscountDraftWithKey(productDiscountDraft, key), + async productDiscount => + { + Assert.NotNull(productDiscount); + var returnedSet = await _client + .ProductDiscounts() + .Get() + .WithQuery(q => q.Key().Is(productDiscount.Key)) + .ExecuteAsync(); + + Assert.Single(returnedSet.Results); + Assert.Equal(key, returnedSet.Results[0].Key); + }); + } + + [Fact] + public async Task UpdateProductDiscountByIdChangeDescription() + { + await WithUpdateableProductDiscount( + _client, + async productDiscount => + { + Assert.NotNull(productDiscount); + var name = $"{TestingUtility.RandomString()}"; + var action = new ProductDiscountSetDescriptionAction() + { + Action = "setDescription", + Description = new LocalizedString() { { "en", name } } + }; + + var update = new ProductDiscountUpdate() + { + Version = productDiscount.Version, + Actions = new List() { action } + }; + + var updatedProductDiscount = await _client + .ProductDiscounts() + .WithId(productDiscount.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedProductDiscount.Description, new LocalizedString() { { "en", name } }); + return updatedProductDiscount; + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductProjectionSearch/ProductProjectionSearchIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductProjectionSearch/ProductProjectionSearchIntegrationTests.cs index 3ae04bdc32c..be37b30056d 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductProjectionSearch/ProductProjectionSearchIntegrationTests.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductProjectionSearch/ProductProjectionSearchIntegrationTests.cs @@ -21,16 +21,11 @@ public class ProductProjectionSearchIntegrationTests public readonly string KeyProductType = $"{KeyPrefix}_ProductType"; public readonly string KeyLocalizedProduct = $"{KeyPrefix}_localizedProduct"; - private readonly IClient _client; - private readonly string _projectKey; - private readonly ProjectApiRoot _apiRoot; + private readonly ProjectApiRoot _client; public ProductProjectionSearchIntegrationTests(ServiceProviderFixture serviceProviderFixture) { - var clientConfiguration = serviceProviderFixture.GetClientConfiguration("Client"); - this._client = serviceProviderFixture.GetService(); - this._apiRoot = serviceProviderFixture.GetService(); - this._projectKey = clientConfiguration.ProjectKey; + this._client = serviceProviderFixture.GetService(); } [Fact] @@ -61,8 +56,7 @@ public async Task SearchByFullLocale() await AssertEventuallyAsync(async () => { //Act - var searchResult = await _client.WithApi() - .WithProjectKey(_projectKey) + var searchResult = await _client .ProductProjections() .Search() .Get() @@ -79,7 +73,7 @@ await AssertEventuallyAsync(async () => }); - var r = _apiRoot.StandalonePrices().Get() + var r = _client.StandalonePrices().Get() .WithQuery(q => q.Key().IsInVar("keys"), new Dictionary>() { { @@ -95,7 +89,7 @@ await AssertEventuallyAsync(async () => [Fact] public Task SearchPost() { - var request = _client.WithApi().WithProjectKey(_projectKey).ProductProjections().Search() + var request = _client.ProductProjections().Search() .Post() .AddFormParam("filter", "test") .AddFormParam("filter", "test2") diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductTypes/ProductTypesFixture.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductTypes/ProductTypesFixture.cs index d9e57811ce8..4e14d60fc2d 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductTypes/ProductTypesFixture.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/ProductTypes/ProductTypesFixture.cs @@ -51,11 +51,6 @@ public static ProductTypeDraft DefaultProductTypeDraft(ProductTypeDraft productT #region CreateAndDelete - public static async Task CreateProductType(IClient client, ProductTypeDraft productTypeDraft) - { - return await CreateProductType(client.WithProject(DefaultProjectKey), productTypeDraft); - } - public static async Task CreateProductType(ProjectApiRoot apiRoot, ProductTypeDraft productTypeDraft) { return await apiRoot @@ -64,11 +59,6 @@ public static async Task CreateProductType(ProjectApiRoot apiRoot, .ExecuteAsync(); } - public static async Task DeleteProductType(IClient client, IProductType productType) - { - await DeleteProductType(client.WithProject(DefaultProjectKey), productType); - } - public static async Task DeleteProductType(ProjectApiRoot apiRoot, IProductType productType) { try @@ -86,11 +76,6 @@ await apiRoot } } - public static async Task CreateOrRetrieveProductType(IClient client, - ProductTypeDraft productTypeDraft) - { - return await CreateOrRetrieveProductType(client.WithProject(DefaultProjectKey), productTypeDraft); - } public static async Task CreateOrRetrieveProductType(ProjectApiRoot apiRoot, ProductTypeDraft productTypeDraft) { IProductType productType = null; @@ -117,10 +102,5 @@ public static async Task WithProductType(ProjectApiRoot apiRoot, Func func) - { - await WithAsync(client, new ProductTypeDraft(), DefaultProductTypeDraft, func, CreateProductType, DeleteProductType); - } } } \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Products/ProductsFixture.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Products/ProductsFixture.cs index 00f36dc4fde..ca1c66dac90 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Products/ProductsFixture.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Products/ProductsFixture.cs @@ -87,16 +87,6 @@ public static async Task CreateProduct(ProjectApiRoot apiRoot, Product return resource; } - public static async Task CreateProduct(IClient client, ProductDraft productDraft) - { - return await CreateProduct(client.WithProject(DefaultProjectKey), productDraft); - } - - public static async Task DeleteProduct(IClient client, IProduct product) - { - await DeleteProduct(client.WithProject(DefaultProjectKey), product); - } - public static async Task DeleteProduct(ProjectApiRoot apiRoot, IProduct product) { try @@ -130,10 +120,6 @@ await apiRoot } } - public static async Task CreateOrRetrieveProduct(IClient client, ProductDraft productDraft) - { - return await CreateOrRetrieveProduct(client.WithProject(DefaultProjectKey), productDraft); - } public static async Task CreateOrRetrieveProduct(ProjectApiRoot apiRoot, ProductDraft productDraft) { IProduct product = null; @@ -156,22 +142,11 @@ public static async Task CreateOrRetrieveProduct(ProjectApiRoot apiRoo } #endregion - public static async Task WithProduct(IClient client, Func func) - { - await WithProduct(client.WithProject(DefaultProjectKey), func); - } - public static async Task WithProduct(ProjectApiRoot apiRoot, Func func) { await WithProduct(apiRoot, DefaultProductDraft, func); } - public static async Task WithProduct(IClient client, Func draftAction, - Func func) - { - await WithProduct(client.WithProject(DefaultProjectKey), draftAction, func); - } - public static async Task WithProduct(ProjectApiRoot apiRoot, Func draftAction, Func func) { await WithProductType(apiRoot, async productType => diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Products/ProductsIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Products/ProductsIntegrationTests.cs index 7996c521cff..070269b19a7 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Products/ProductsIntegrationTests.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Products/ProductsIntegrationTests.cs @@ -26,8 +26,7 @@ public ProductsIntegrationTests(ServiceProviderFixture serviceProviderFixture) { this._projectApiRoot = serviceProviderFixture.GetService(); } - - + [Fact] public async Task HeadRequest() { diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Review/ReviewFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Review/ReviewFixtures.cs new file mode 100644 index 00000000000..d5f7c0c32d8 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Review/ReviewFixtures.cs @@ -0,0 +1,98 @@ +using System; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.Reviews; +using static commercetools.Api.IntegrationTests.GenericFixture; +using commercetools.Sdk.Api.Extensions; + +namespace commercetools.Api.IntegrationTests.Review +{ + public class ReviewFixtures + { + #region DraftBuilds + + public static ReviewDraft DefaultReviewDraft(ReviewDraft reviewDraft) + { + var randomInt = TestingUtility.RandomInt(); + var randomStr = TestingUtility.RandomString(); + + reviewDraft.Key = $"Test-Key-{randomInt}"; + reviewDraft.Title = $"Test-Title-{randomStr}"; + + return reviewDraft; + } + + #endregion + + public static ReviewDraft DefaultReviewDraftWithKey(ReviewDraft draft, string key) + { + var reviewDraft = DefaultReviewDraft(draft); + reviewDraft.Key = key; + + return reviewDraft; + } + + public static async Task CreateReview(ProjectApiRoot client, + ReviewDraft reviewDraft) + { + try + { + return await client + .Reviews() + .Post(reviewDraft) + .ExecuteAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteReview(ProjectApiRoot client, IReview review) + { + try + { + await client + .Reviews() + .WithId(review.Id) + .Delete() + .WithVersion(review.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithReview(ProjectApiRoot client, + Func draftAction, + Action func) + { + await With(client, new ReviewDraft(), draftAction, func, CreateReview, + DeleteReview); + } + + public static async Task WithReview(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new ReviewDraft(), draftAction, func, CreateReview, + DeleteReview); + } + + public static async Task WithUpdateableReview(ProjectApiRoot client, + Func> func) + { + await WithUpdateableAsync(client, new ReviewDraft(), DefaultReviewDraft, func, + CreateReview, + DeleteReview); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Review/ReviewIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Review/ReviewIntegrationTests.cs new file mode 100644 index 00000000000..0b757e426f6 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Review/ReviewIntegrationTests.cs @@ -0,0 +1,109 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Reviews; +using Xunit; +using static commercetools.Api.IntegrationTests.Review.ReviewFixtures; + +namespace commercetools.Api.IntegrationTests.Review +{ + [Collection("Integration Tests")] + public class ReviewIntegrationTests + { + private readonly ProjectApiRoot _client; + private readonly string _projectKey; + + public ReviewIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateReview() + { + var key = $"CreateReview-{TestingUtility.RandomString()}"; + await WithReview( + _client, reviewDraft => DefaultReviewDraftWithKey(reviewDraft, key), + review => { Assert.Equal(key, review.Key); } + ); + } + + [Fact] + public async Task GetReviewById() + { + var key = $"GetReviewById-{TestingUtility.RandomString()}"; + await WithReview( + _client, + reviewDraft => DefaultReviewDraftWithKey(reviewDraft, key), + async review => + { + Assert.NotNull(review); + var retrievedReview = await _client + .Reviews() + .WithId(review.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedReview); + Assert.Equal(key, retrievedReview.Key); + } + ); + } + + [Fact] + public async Task QueryReview() + { + var key = $"QueryReview-{TestingUtility.RandomString()}"; + await WithReview( + _client, + reviewDraft => DefaultReviewDraftWithKey(reviewDraft, key), + async review => + { + Assert.NotNull(review); + var returnedSet = await _client + .Reviews() + .Get() + .WithQuery(q => q.Key().Is(review.Key)) + .ExecuteAsync(); + + Assert.Single(returnedSet.Results); + Assert.Equal(key, returnedSet.Results[0].Key); + }); + } + + [Fact] + public async Task UpdateReviewByIdChangeTitle() + { + await WithUpdateableReview( + _client, + async review => + { + Assert.NotNull(review); + var name = $"Test-Title-{TestingUtility.RandomString()}"; + var action = new ReviewSetTitleAction() + { + Action = "setTitle", + Title = name + }; + + var update = new ReviewUpdate() + { + Version = review.Version, + Actions = new List() { action } + }; + + var updatedReview = await _client + .Reviews() + .WithId(review.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedReview.Title, name); + return updatedReview; + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Services/CustomerServices.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Services/CustomerServices.cs index fc2a4f58f8a..6188161fc54 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Services/CustomerServices.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Services/CustomerServices.cs @@ -15,7 +15,7 @@ public async Task GetCustomerByKey(IClient adminClient, string key) { try { - var customer = await adminClient.WithApi().WithProjectKey(GenericFixture.DefaultProjectKey) + var customer = await adminClient.WithApi(GenericFixture.DefaultProjectKey) .Customers() .WithKey(key) .Get() @@ -31,7 +31,7 @@ public async Task GetCustomerByKey(IClient adminClient, string key) } public async Task CreateCustomer(IClient adminClient, ICustomerDraft customerDraft) { - var customerSignInResult = await adminClient.WithApi().WithProjectKey(GenericFixture.DefaultProjectKey) + var customerSignInResult = await adminClient.WithApi(GenericFixture.DefaultProjectKey) .Customers() .Post(customerDraft) .ExecuteAsync(); diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Services/ShoppingListServices.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Services/ShoppingListServices.cs index f34d0ef8055..3d7ae68506e 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Services/ShoppingListServices.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Services/ShoppingListServices.cs @@ -16,7 +16,7 @@ public async Task GetShoppingListByKey(IClient adminClient, strin { try { - var shoppingList = await adminClient.WithApi().WithProjectKey(GenericFixture.DefaultProjectKey) + var shoppingList = await adminClient.WithApi(GenericFixture.DefaultProjectKey) .ShoppingLists() .WithKey(key) .Get() @@ -33,7 +33,7 @@ public async Task GetShoppingListByKey(IClient adminClient, strin public async Task CreateShoppingList(IClient adminClient, IShoppingListDraft shoppingListDraft) { - var shoppingList = await adminClient.WithApi().WithProjectKey(GenericFixture.DefaultProjectKey) + var shoppingList = await adminClient.WithApi(GenericFixture.DefaultProjectKey) .ShoppingLists() .Post(shoppingListDraft) .ExecuteAsync(); diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/State/StateFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/State/StateFixtures.cs new file mode 100644 index 00000000000..06bdee07596 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/State/StateFixtures.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.States; +using static commercetools.Api.IntegrationTests.GenericFixture; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Common; + +namespace commercetools.Api.IntegrationTests.State +{ + public class StateFixtures + { + #region DraftBuilds + + public static StateDraft DefaultStateDraft(StateDraft stateDraft) + { + var randomInt = TestingUtility.RandomInt(); + var randomStr = TestingUtility.RandomString(); + + stateDraft.Key = $"Test-Key-{randomInt}"; + stateDraft.Type = IStateTypeEnum.LineItemState; + stateDraft.Roles = new List() + { + IStateRoleEnum.Return + }; + + return stateDraft; + } + + #endregion + + public static StateDraft DefaultStateDraftWithKey(StateDraft draft, string key) + { + var stateDraft = DefaultStateDraft(draft); + stateDraft.Key = key; + + return stateDraft; + } + + public static async Task CreateState(ProjectApiRoot client, + StateDraft stateDraft) + { + try + { + return await client + .States() + .Post(stateDraft) + .ExecuteAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteState(ProjectApiRoot client, IState state) + { + try + { + await client + .States() + .WithId(state.Id) + .Delete() + .WithVersion(state.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithState(ProjectApiRoot client, + Func draftAction, + Action func) + { + await With(client, new StateDraft(), draftAction, func, CreateState, + DeleteState); + } + + public static async Task WithState(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new StateDraft(), draftAction, func, CreateState, + DeleteState); + } + + public static async Task WithUpdateableState(ProjectApiRoot client, + Func> func) + { + await WithUpdateableAsync(client, new StateDraft(), DefaultStateDraft, func, + CreateState, + DeleteState); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/State/StateIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/State/StateIntegrationTests.cs new file mode 100644 index 00000000000..5809a3756f9 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/State/StateIntegrationTests.cs @@ -0,0 +1,108 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Common; +using commercetools.Sdk.Api.Models.States; +using Xunit; +using static commercetools.Api.IntegrationTests.State.StateFixtures; + +namespace commercetools.Api.IntegrationTests.State +{ + [Collection("Integration Tests")] + public class StateIntegrationTests + { + private readonly ProjectApiRoot _client; + + public StateIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateState() + { + var key = $"CreateState-{TestingUtility.RandomString()}"; + await WithState( + _client, stateDraft => DefaultStateDraftWithKey(stateDraft, key), + state => { Assert.Equal(key, state.Key); } + ); + } + + [Fact] + public async Task GetStateById() + { + var key = $"GetStateById-{TestingUtility.RandomString()}"; + await WithState( + _client, + stateDraft => DefaultStateDraftWithKey(stateDraft, key), + async state => + { + Assert.NotNull(state); + var retrievedState = await _client + .States() + .WithId(state.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedState); + Assert.Equal(key, retrievedState.Key); + } + ); + } + + [Fact] + public async Task QueryState() + { + var key = $"QueryState-{TestingUtility.RandomString()}"; + await WithState( + _client, + stateDraft => DefaultStateDraftWithKey(stateDraft, key), + async state => + { + Assert.NotNull(state); + var returnedSet = await _client + .States() + .WithKey(key) + .Get() + .ExecuteAsync(); + + Assert.Equal(key, returnedSet.Key); + }); + } + + [Fact] + public async Task UpdateStateByIdChangeDescription() + { + await WithUpdateableState( + _client, + async state => + { + Assert.NotNull(state); + var desc = $"Test-Desc-{TestingUtility.RandomString()}"; + var action = new StateSetDescriptionAction() + { + Action = "setDescription", + Description = new LocalizedString() { { "en", desc } } + }; + + var update = new StateUpdate() + { + Version = state.Version, + Actions = new List() { action } + }; + + var updatedState = await _client + .States() + .WithId(state.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedState.Description, new LocalizedString() { { "en", desc } }); + return updatedState; + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Store/StoreFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Store/StoreFixtures.cs new file mode 100644 index 00000000000..674c7118ce2 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Store/StoreFixtures.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.Stores; +using static commercetools.Api.IntegrationTests.GenericFixture; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Common; + +namespace commercetools.Api.IntegrationTests.Store +{ + public class StoreFixtures + { + #region DraftBuilds + + public static StoreDraft DefaultStoreDraft(StoreDraft storeDraft) + { + var randomInt = TestingUtility.RandomInt(); + var randomStr = TestingUtility.RandomString(); + + storeDraft.Key = $"Test-Key-{randomInt}"; + + return storeDraft; + } + + #endregion + + public static StoreDraft DefaultStoreDraftWithKey(StoreDraft draft, string key) + { + var storeDraft = DefaultStoreDraft(draft); + storeDraft.Key = key; + + return storeDraft; + } + + public static async Task CreateStore(ProjectApiRoot client, + StoreDraft storeDraft) + { + try + { + return await client + .Stores() + .Post(storeDraft) + .ExecuteAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteStore(ProjectApiRoot client, IStore store) + { + try + { + await client + .Stores() + .WithId(store.Id) + .Delete() + .WithVersion(store.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithStore(ProjectApiRoot client, + Func draftAction, + Action func) + { + await With(client, new StoreDraft(), draftAction, func, CreateStore, + DeleteStore); + } + + public static async Task WithStore(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new StoreDraft(), draftAction, func, CreateStore, + DeleteStore); + } + + public static async Task WithUpdateableStore(ProjectApiRoot client, + Func> func) + { + await WithUpdateableAsync(client, new StoreDraft(), DefaultStoreDraft, func, + CreateStore, + DeleteStore); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Store/StoreIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Store/StoreIntegrationTests.cs new file mode 100644 index 00000000000..ede70ef8948 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Store/StoreIntegrationTests.cs @@ -0,0 +1,109 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Common; +using commercetools.Sdk.Api.Models.StoreCountries; +using commercetools.Sdk.Api.Models.Stores; +using Xunit; +using static commercetools.Api.IntegrationTests.Store.StoreFixtures; + +namespace commercetools.Api.IntegrationTests.Store +{ + [Collection("Integration Tests")] + public class StoreIntegrationTests + { + private readonly ProjectApiRoot _client; + + public StoreIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateStore() + { + var key = $"CreateStore-{TestingUtility.RandomString()}"; + await WithStore( + _client, storeDraft => DefaultStoreDraftWithKey(storeDraft, key), + store => { Assert.Equal(key, store.Key); } + ); + } + + [Fact] + public async Task GetStoreById() + { + var key = $"GetStoreById-{TestingUtility.RandomString()}"; + await WithStore( + _client, + storeDraft => DefaultStoreDraftWithKey(storeDraft, key), + async store => + { + Assert.NotNull(store); + var retrievedStore = await _client + .Stores() + .WithId(store.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedStore); + Assert.Equal(key, retrievedStore.Key); + } + ); + } + + [Fact] + public async Task QueryStore() + { + var key = $"QueryStore-{TestingUtility.RandomString()}"; + await WithStore( + _client, + storeDraft => DefaultStoreDraftWithKey(storeDraft, key), + async store => + { + Assert.NotNull(store); + var returnedSet = await _client + .Stores() + .WithKey(key) + .Get() + .ExecuteAsync(); + + Assert.Equal(key, returnedSet.Key); + }); + } + + [Fact] + public async Task UpdateStoreByIdChangeDescription() + { + await WithUpdateableStore( + _client, + async store => + { + Assert.NotNull(store); + var name = $"Test-Desc-{TestingUtility.RandomString()}"; + var action = new StoreSetNameAction() + { + Action = "setName", + Name = new LocalizedString() { { "en", name } } + }; + + var update = new StoreUpdate() + { + Version = store.Version, + Actions = new List() { action } + }; + + var updatedStore = await _client + .Stores() + .WithId(store.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedStore.Name, new LocalizedString() { { "en", name } }); + return updatedStore; + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/TaxCategories/TaxCategoriesFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/TaxCategories/TaxCategoriesFixtures.cs new file mode 100644 index 00000000000..5fda787bafb --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/TaxCategories/TaxCategoriesFixtures.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.TaxCategories; +using static commercetools.Api.IntegrationTests.GenericFixture; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Common; + +namespace commercetools.Api.IntegrationTests.TaxCategories +{ + public class TaxCategoriesFixtures + { + #region DraftBuilds + + public static TaxCategoryDraft DefaultTaxCategoryDraft(TaxCategoryDraft taxCategoryDraft) + { + var randomInt = TestingUtility.RandomInt(); + var randomStr = TestingUtility.RandomString(); + + taxCategoryDraft.Key = $"Test-Key-{randomInt}"; + taxCategoryDraft.Name = $"Test-Name-{randomStr}"; + taxCategoryDraft.Rates = new List() + { + new TaxRateDraft() + { + Name = $"Test-Tax-Rate-{randomStr}", + Country = "DE", + IncludedInPrice = true, + State = "Berlin", + Key = $"Test-Tax-Key-{randomInt}", + Amount = 1 + } + }; + + return taxCategoryDraft; + } + + #endregion + + public static TaxCategoryDraft DefaultTaxCategoriesDraftWithKey(TaxCategoryDraft draft, string key) + { + var taxCategoryDraft = DefaultTaxCategoryDraft(draft); + taxCategoryDraft.Key = key; + + return taxCategoryDraft; + } + + public static async Task CreateTaxCategories(ProjectApiRoot client, + TaxCategoryDraft taxCategoriesDraft) + { + try + { + return await client + .TaxCategories() + .Post(taxCategoriesDraft) + .ExecuteAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteTaxCategories(ProjectApiRoot client, ITaxCategory taxCategories) + { + try + { + await client + .TaxCategories() + .WithId(taxCategories.Id) + .Delete() + .WithVersion(taxCategories.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithTaxCategory(ProjectApiRoot client, + Func draftAction, + Action func) + { + await With(client, new TaxCategoryDraft(), draftAction, func, CreateTaxCategories, + DeleteTaxCategories); + } + + public static async Task WithTaxCategory(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new TaxCategoryDraft(), draftAction, func, CreateTaxCategories, + DeleteTaxCategories); + } + + public static async Task WithUpdateableTaxCategory(ProjectApiRoot client, + Func> func) + { + await WithUpdateableAsync(client, new TaxCategoryDraft(), DefaultTaxCategoryDraft, func, + CreateTaxCategories, + DeleteTaxCategories); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/TaxCategories/TaxCategoriesIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/TaxCategories/TaxCategoriesIntegrationTests.cs new file mode 100644 index 00000000000..e56f197c9f6 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/TaxCategories/TaxCategoriesIntegrationTests.cs @@ -0,0 +1,108 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.TaxCategories; +using Xunit; +using static commercetools.Api.IntegrationTests.TaxCategories.TaxCategoriesFixtures; + +namespace commercetools.Api.IntegrationTests.TaxCategories +{ + [Collection("Integration Tests")] + public class TaxCategoriesIntegrationTests + { + private readonly ProjectApiRoot _client; + + public TaxCategoriesIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateTaxCategories() + { + var key = $"CreateTaxCategories-{TestingUtility.RandomString()}"; + await WithTaxCategory( + _client, taxCategoryDraft => DefaultTaxCategoriesDraftWithKey(taxCategoryDraft, key), + taxCategory => { Assert.Equal(key, taxCategory.Key); } + ); + } + + [Fact] + public async Task GetTaxCategoriesById() + { + var key = $"GetTaxCategoriesById-{TestingUtility.RandomString()}"; + await WithTaxCategory( + _client, + taxCategoryDraft => DefaultTaxCategoriesDraftWithKey(taxCategoryDraft, key), + async taxCategory => + { + Assert.NotNull(taxCategory); + var retrievedTaxCategories = await _client + .TaxCategories() + .WithId(taxCategory.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedTaxCategories); + Assert.Equal(key, retrievedTaxCategories.Key); + } + ); + } + + [Fact] + public async Task QueryTaxCategories() + { + var key = $"QueryTaxCategory-{TestingUtility.RandomString()}"; + await WithTaxCategory( + _client, + taxCategoryDraft => DefaultTaxCategoriesDraftWithKey(taxCategoryDraft, key), + async taxCategory => + { + Assert.NotNull(taxCategory); + var returnedSet = await _client + .TaxCategories() + .Get() + .WithQuery(q => q.Key().Is(taxCategory.Key)) + .ExecuteAsync(); + + Assert.Single(returnedSet.Results); + Assert.Equal(key, returnedSet.Results[0].Key); + }); + } + + [Fact] + public async Task UpdateTaxCategoriesByIdChangeDescription() + { + await WithUpdateableTaxCategory( + _client, + async taxCategory => + { + Assert.NotNull(taxCategory); + var name = $"Test-Desc-{TestingUtility.RandomString()}"; + var action = new TaxCategorySetDescriptionAction() + { + Action = "setDescription", + Description = name, + }; + + var update = new TaxCategoryUpdate() + { + Version = taxCategory.Version, + Actions = new List() { action } + }; + + var updatedTaxCategory = await _client + .TaxCategories() + .WithId(taxCategory.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedTaxCategory.Description, name); + return updatedTaxCategory; + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Type/TypeFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Type/TypeFixtures.cs new file mode 100644 index 00000000000..10e9116efd0 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Type/TypeFixtures.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.Types; +using static commercetools.Api.IntegrationTests.GenericFixture; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Common; + +namespace commercetools.Api.IntegrationTests.Type +{ + public class TypeFixtures + { + #region DraftBuilds + + public static TypeDraft DefaultTypeDraft(TypeDraft typeDraft) + { + var randomInt = TestingUtility.RandomInt(); + var randomStr = TestingUtility.RandomString(); + + typeDraft.Key = $"Test-Key-{randomInt}"; + typeDraft.Name = new LocalizedString() {{ "de", $"Test-Name-{randomStr}" }}; + typeDraft.ResourceTypeIds = new List() + { + IResourceTypeId.Asset, + IResourceTypeId.Category, + IResourceTypeId.Order, + IResourceTypeId.PaymentInterfaceInteraction, + IResourceTypeId.Payment, + IResourceTypeId.CartDiscount + }; + + return typeDraft; + } + + #endregion + + public static TypeDraft DefaultTypeDraftWithKey(TypeDraft draft, string key) + { + var typeDraft = DefaultTypeDraft(draft); + typeDraft.Key = key; + + return typeDraft; + } + + public static async Task CreateType(ProjectApiRoot client, + TypeDraft typeDraft) + { + try + { + return await client + .Types() + .Post(typeDraft) + .ExecuteAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteType(ProjectApiRoot client, IType type) + { + try + { + await client + .Types() + .WithId(type.Id) + .Delete() + .WithVersion(type.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithType(ProjectApiRoot client, + Func draftAction, + Action func) + { + await With(client, new TypeDraft(), draftAction, func, CreateType, + DeleteType); + } + + public static async Task WithType(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new TypeDraft(), draftAction, func, CreateType, + DeleteType); + } + + public static async Task WithUpdateableType(ProjectApiRoot client, + Func> func) + { + await WithUpdateableAsync(client, new TypeDraft(), DefaultTypeDraft, func, + CreateType, + DeleteType); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Type/TypeIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Type/TypeIntegrationTests.cs new file mode 100644 index 00000000000..5452f055b39 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Type/TypeIntegrationTests.cs @@ -0,0 +1,109 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Common; +using commercetools.Sdk.Api.Models.Types; +using Xunit; +using static commercetools.Api.IntegrationTests.Type.TypeFixtures; + +namespace commercetools.Api.IntegrationTests.Type +{ + [Collection("Integration Tests")] + public class TypeIntegrationTests + { + private readonly ProjectApiRoot _client; + + public TypeIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateType() + { + var key = $"CreateType-{TestingUtility.RandomString()}"; + await WithType( + _client, typeDraft => DefaultTypeDraftWithKey(typeDraft, key), + type => { Assert.Equal(key, type.Key); } + ); + } + + [Fact] + public async Task GetTypeById() + { + var key = $"GetTypeById-{TestingUtility.RandomString()}"; + await WithType( + _client, + typeDraft => DefaultTypeDraftWithKey(typeDraft, key), + async type => + { + Assert.NotNull(type); + var retrievedType = await _client + .Types() + .WithId(type.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedType); + Assert.Equal(key, retrievedType.Key); + } + ); + } + + [Fact] + public async Task QueryType() + { + var key = $"QueryType-{TestingUtility.RandomString()}"; + await WithType( + _client, + typeDraft => DefaultTypeDraftWithKey(typeDraft, key), + async type => + { + Assert.NotNull(type); + var returnedSet = await _client + .Types() + .Get() + .WithQuery(q => q.Key().Is(type.Key)) + .ExecuteAsync(); + + Assert.Single(returnedSet.Results); + Assert.Equal(key, returnedSet.Results[0].Key); + }); + } + + [Fact] + public async Task UpdateTypeByIdChangeDescription() + { + await WithUpdateableType( + _client, + async type => + { + Assert.NotNull(type); + var name = $"Test-Desc-{TestingUtility.RandomString()}"; + var action = new TypeSetDescriptionAction() + { + Action = "setDescription", + Description = new LocalizedString() {{ "en", name }} + }; + + var update = new TypeUpdate() + { + Version = type.Version, + Actions = new List() { action } + }; + + var updatedType = await _client + .Types() + .WithId(type.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedType.Description, new LocalizedString() {{ "en", name }}); + return updatedType; + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Zone/ZoneFixtures.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Zone/ZoneFixtures.cs new file mode 100644 index 00000000000..b9fcecaca5f --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Zone/ZoneFixtures.cs @@ -0,0 +1,99 @@ +using System; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Models.Zones; +using static commercetools.Api.IntegrationTests.GenericFixture; +using commercetools.Sdk.Api.Extensions; + +namespace commercetools.Api.IntegrationTests.Zone +{ + public class ZoneFixtures + { + #region DraftBuilds + + public static ZoneDraft DefaultZoneDraft(ZoneDraft zoneDraft) + { + var randomInt = TestingUtility.RandomInt(); + var randomStr = TestingUtility.RandomString(); + + zoneDraft.Key = $"Test-Key-{randomInt}"; + zoneDraft.Name = $"Test-Name-{randomStr}"; + zoneDraft.Description = $"Test-Desc-{randomStr}"; + + return zoneDraft; + } + + #endregion + + public static ZoneDraft DefaultZoneDraftWithKey(ZoneDraft draft, string key) + { + var zoneDraft = DefaultZoneDraft(draft); + zoneDraft.Key = key; + + return zoneDraft; + } + + public static async Task CreateZone(ProjectApiRoot client, + ZoneDraft zoneDraft) + { + try + { + return await client + .Zones() + .Post(zoneDraft) + .ExecuteAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + + public static async Task DeleteZone(ProjectApiRoot client, IZone zone) + { + try + { + await client + .Zones() + .WithId(zone.Id) + .Delete() + .WithVersion(zone.Version) + .ExecuteAsync(); + } + catch (Exception) + { + // ignored + } + } + + #region + + public static async Task WithZone(ProjectApiRoot client, + Func draftAction, + Action func) + { + await With(client, new ZoneDraft(), draftAction, func, CreateZone, + DeleteZone); + } + + public static async Task WithZone(ProjectApiRoot client, + Func draftAction, + Func func) + { + await WithAsync(client, new ZoneDraft(), draftAction, func, CreateZone, + DeleteZone); + } + + public static async Task WithUpdateableZone(ProjectApiRoot client, + Func> func) + { + await WithUpdateableAsync(client, new ZoneDraft(), DefaultZoneDraft, func, + CreateZone, + DeleteZone); + } + + #endregion + } +} \ No newline at end of file diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Zone/ZoneIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Zone/ZoneIntegrationTests.cs new file mode 100644 index 00000000000..d12d476cea0 --- /dev/null +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Zone/ZoneIntegrationTests.cs @@ -0,0 +1,108 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using commercetools.Base.Client; +using commercetools.Sdk.Api.Client; +using commercetools.Sdk.Api.Extensions; +using commercetools.Sdk.Api.Models.Zones; +using Xunit; +using static commercetools.Api.IntegrationTests.Zone.ZoneFixtures; + +namespace commercetools.Api.IntegrationTests.Zone +{ + [Collection("Integration Tests")] + public class ZoneIntegrationTests + { + private readonly ProjectApiRoot _client; + + public ZoneIntegrationTests(ServiceProviderFixture serviceProviderFixture) + { + this._client = serviceProviderFixture.GetService(); + } + + [Fact] + public async Task CreateZone() + { + var key = $"CreateZone-{TestingUtility.RandomString()}"; + await WithZone( + _client, zoneDraft => DefaultZoneDraftWithKey(zoneDraft, key), + zone => { Assert.Equal(key, zone.Key); } + ); + } + + [Fact] + public async Task GetZoneById() + { + var key = $"GetZoneById-{TestingUtility.RandomString()}"; + await WithZone( + _client, + zoneDraft => DefaultZoneDraftWithKey(zoneDraft, key), + async zone => + { + Assert.NotNull(zone); + var retrievedZone = await _client + .Zones() + .WithId(zone.Id) + .Get() + .ExecuteAsync(); + + Assert.NotNull(retrievedZone); + Assert.Equal(key, retrievedZone.Key); + } + ); + } + + [Fact] + public async Task QueryZone() + { + var key = $"QueryZone-{TestingUtility.RandomString()}"; + await WithZone( + _client, + zoneDraft => DefaultZoneDraftWithKey(zoneDraft, key), + async zone => + { + Assert.NotNull(zone); + var returnedSet = await _client + .Zones() + .Get() + .WithQuery(q => q.Key().Is(zone.Key)) + .ExecuteAsync(); + + Assert.Single(returnedSet.Results); + Assert.Equal(key, returnedSet.Results[0].Key); + }); + } + + [Fact] + public async Task UpdateZoneByIdChangeDescription() + { + await WithUpdateableZone( + _client, + async zone => + { + Assert.NotNull(zone); + var name = $"Test-Desc-{TestingUtility.RandomString()}"; + var action = new ZoneSetDescriptionAction() + { + Action = "setDescription", + Description = name, + }; + + var update = new ZoneUpdate() + { + Version = zone.Version, + Actions = new List() { action } + }; + + var updatedZone = await _client + .Zones() + .WithId(zone.Id) + .Post(update) + .ExecuteAsync(); + + Assert.Equal(updatedZone.Description, name); + return updatedZone; + } + ); + } + } +} \ No newline at end of file diff --git a/commercetools.Sdk/commercetools.Sdk.ImportApi/Client/ProjectApiRoot.cs b/commercetools.Sdk/commercetools.Sdk.ImportApi/Client/ProjectApiRoot.cs index 93ba6f60bf1..db1a40c8ca4 100644 --- a/commercetools.Sdk/commercetools.Sdk.ImportApi/Client/ProjectApiRoot.cs +++ b/commercetools.Sdk/commercetools.Sdk.ImportApi/Client/ProjectApiRoot.cs @@ -14,6 +14,7 @@ using commercetools.Sdk.ImportApi.Client.RequestBuilders.ProductVariants; using commercetools.Sdk.ImportApi.Client.RequestBuilders.Projects; using commercetools.Sdk.ImportApi.Client.RequestBuilders.StandalonePrices; +using commercetools.Sdk.ImportApi.Client.RequestBuilders.Types; namespace commercetools.Sdk.ImportApi.Client { @@ -107,5 +108,9 @@ public ByProjectKeyInventoriesRequestBuilder Inventories() return With().Inventories(); } + public ByProjectKeyTypesRequestBuilder Types() + { + return With().Types(); + } } } \ No newline at end of file