Skip to content

Commit ac136e1

Browse files
authored
Merge pull request #209 from commercetools/LTS-Q3-2021
Adding Missing features to SDK V1
2 parents c201984 + 79c520d commit ac136e1

25 files changed

+427
-16
lines changed

commercetools.Sdk/IntegrationTests/commercetools.Sdk.IntegrationTests/Carts/CartsIntegrationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ await WithUpdateableCart(client,
610610
var updatedCart = await client
611611
.ExecuteAsync(cart.UpdateById(actions => actions.AddUpdate(action)));
612612

613-
Assert.Equal(shippingMethod.Name, updatedCart.ShippingInfo.ShippingMethodName);
613+
Assert.Equal(shippingMethod.LocalizedName["en"], updatedCart.ShippingInfo.ShippingMethodName);
614614
return updatedCart;
615615
});
616616
});
@@ -886,7 +886,7 @@ await WithUpdateableCart(client,
886886
{
887887
Assert.Equal(TaxMode.ExternalAmount, cart.TaxMode);
888888
Assert.Equal(shippingAddress.ToString(), cart.ShippingAddress.ToString());
889-
Assert.Equal(shippingMethod.Name, cart.ShippingInfo.ShippingMethodName);
889+
Assert.Equal(shippingMethod.LocalizedName["en"], cart.ShippingInfo.ShippingMethodName);
890890

891891
var externalTaxAmountDraft = TestingUtility.GetExternalTaxAmountDraft();
892892

@@ -931,7 +931,7 @@ await WithUpdateableCart(client,
931931
{
932932
Assert.Equal(TaxMode.External, cart.TaxMode);
933933
Assert.Equal(shippingAddress.ToString(), cart.ShippingAddress.ToString());
934-
Assert.Equal(shippingMethod.Name, cart.ShippingInfo.ShippingMethodName);
934+
Assert.Equal(shippingMethod.LocalizedName["en"], cart.ShippingInfo.ShippingMethodName);
935935

936936
var externalTaxRateDraft = TestingUtility.GetExternalTaxRateDraft();
937937

commercetools.Sdk/IntegrationTests/commercetools.Sdk.IntegrationTests/OrdersImport/OrdersImportFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static OrderImportDraft DefaultOrderImportDraftWithLineItemWithShippingIn
114114
{
115115
Price = amountEuro10,
116116
ShippingRate = shippingRate,
117-
ShippingMethodName = shippingMethod.Name,
117+
ShippingMethodName = shippingMethod.LocalizedName["en"],
118118
ShippingMethod = shippingMethod.ToKeyResourceIdentifier(),
119119
TaxCategory = taxCategory.ToKeyResourceIdentifier()
120120
};

commercetools.Sdk/IntegrationTests/commercetools.Sdk.IntegrationTests/Products/ProductsIntegrationTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Net;
45
using System.Threading.Tasks;
56
using commercetools.Sdk.Client;
67
using commercetools.Sdk.Domain;
8+
using commercetools.Sdk.Domain.Categories;
79
using commercetools.Sdk.Domain.Predicates;
810
using commercetools.Sdk.Domain.ProductDiscounts;
911
using commercetools.Sdk.Domain.Products.UpdateActions;
@@ -51,6 +53,40 @@ await WithProduct(
5153
Assert.Equal(key, retrievedProduct.Key);
5254
});
5355
}
56+
57+
[Fact]
58+
public async Task CheckProductById()
59+
{
60+
var key = $"CheckProductById-{TestingUtility.RandomString()}";
61+
await WithProduct(
62+
client, productDraft => DefaultProductDraftWithKey(productDraft, key),
63+
async product =>
64+
{
65+
var response = await client
66+
.ExecuteAsyncWithResponse(product.ToIdResourceIdentifier().CheckById());
67+
68+
Assert.NotNull(response);
69+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
70+
});
71+
}
72+
73+
[Fact]
74+
public async Task CheckProductNotExistsById()
75+
{
76+
var id = Guid.NewGuid().ToString();
77+
Exception expectedException = null;
78+
try
79+
{
80+
await client
81+
.ExecuteAsyncWithResponse(new CheckByIdCommand<Product>(id));
82+
}
83+
catch (Exception e)
84+
{
85+
expectedException = e;
86+
}
87+
Assert.NotNull(expectedException);
88+
Assert.IsType<NotFoundException>(expectedException);
89+
}
5490

5591
[Fact]
5692
public async Task GetProductByKey()
@@ -65,6 +101,22 @@ await WithProduct(
65101
Assert.Equal(key, retrievedProduct.Key);
66102
});
67103
}
104+
105+
[Fact]
106+
public async Task CheckProductByKey()
107+
{
108+
var key = $"CheckProductById-{TestingUtility.RandomString()}";
109+
await WithProduct(
110+
client, productDraft => DefaultProductDraftWithKey(productDraft, key),
111+
async product =>
112+
{
113+
var response = await client
114+
.ExecuteAsyncWithResponse(product.ToKeyResourceIdentifier().CheckByKey());
115+
116+
Assert.NotNull(response);
117+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
118+
});
119+
}
68120

69121
[Fact]
70122
public async Task QueryProducts()
@@ -81,6 +133,22 @@ await WithProduct(
81133
Assert.Equal(key, returnedSet.Results[0].Key);
82134
});
83135
}
136+
137+
[Fact]
138+
public async Task CheckProductByQueryPredicate()
139+
{
140+
var key = $"QueryProducts-{TestingUtility.RandomString()}";
141+
await WithProduct(
142+
client, productDraft => DefaultProductDraftWithKey(productDraft, key),
143+
async product =>
144+
{
145+
var checkByQueryCommand = new CheckByQueryCommand<Product>();
146+
checkByQueryCommand.Where(p => p.Key == product.Key.valueOf());
147+
var response = await client.ExecuteAsyncWithResponse(checkByQueryCommand);
148+
Assert.NotNull(response);
149+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
150+
});
151+
}
84152

85153
[Fact]
86154
public async Task DeleteProductById()

commercetools.Sdk/IntegrationTests/commercetools.Sdk.IntegrationTests/ShippingMethods/ShippingMethodIntegrationTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ await WithShippingMethod(
4343
client,
4444
shippingMethodDraft =>
4545
DefaultShippingMethodDraftWithKeyWithTaxCategory(shippingMethodDraft, taxCategory.ToKeyResourceIdentifier(), key),
46-
shippingMethod =>
46+
(shippingMethod, draft) =>
4747
{
4848
Assert.Equal(key, shippingMethod.Key);
49+
Assert.Equal(draft.LocalizedName["en"], shippingMethod.LocalizedName["en"]);
50+
Assert.Equal(draft.LocalizedDescription["en"], shippingMethod.LocalizedDescription["en"]);
4951
});
5052
});
5153
}
@@ -295,13 +297,16 @@ await WithUpdateableShippingMethod(client, async shippingMethod =>
295297
{
296298
var newName = TestingUtility.RandomString();
297299
var updateActions = new List<UpdateAction<ShippingMethod>>();
298-
var action = new ChangeNameUpdateAction { Name = newName };
300+
var action = new SetLocalizedNameUpdateAction
301+
{
302+
LocalizedName= new LocalizedString {{"en", newName}}
303+
};
299304
updateActions.Add(action);
300305

301306
var updatedShippingMethod = await client
302307
.ExecuteAsync(new UpdateByIdCommand<ShippingMethod>(shippingMethod, updateActions));
303308

304-
Assert.Equal(newName, updatedShippingMethod.Name);
309+
Assert.Equal(newName, updatedShippingMethod.LocalizedName["en"]);
305310
return updatedShippingMethod;
306311
});
307312
}

commercetools.Sdk/IntegrationTests/commercetools.Sdk.IntegrationTests/ShippingMethods/ShippingMethodsFixture.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public static ShippingMethodDraft DefaultShippingMethodDraft(ShippingMethodDraft
2323
var random = TestingUtility.RandomInt();
2424
shippingMethodDraft.Key = $"Key_{random}";
2525
shippingMethodDraft.Name = $"ShippingMethod_{random}";
26+
shippingMethodDraft.LocalizedName = new LocalizedString {{"en", $"ShippingMethod_{random}"}};
27+
shippingMethodDraft.LocalizedDescription = new LocalizedString {{"en", $"ShippingMethodDes_{random}"}};
2628
return shippingMethodDraft;
2729
}
2830

@@ -84,7 +86,12 @@ await WithTaxCategory(client, async taxCategory =>
8486
public static async Task WithShippingMethod(IClient client,
8587
Func<ShippingMethodDraft, ShippingMethodDraft> draftAction, Action<ShippingMethod> func)
8688
{
87-
await With(client, new ShippingMethodDraft(), draftAction, func);
89+
await With(client, DefaultShippingMethodDraft(new ShippingMethodDraft()), draftAction, func);
90+
}
91+
public static async Task WithShippingMethod(IClient client,
92+
Func<ShippingMethodDraft, ShippingMethodDraft> draftAction, Action<ShippingMethod,ShippingMethodDraft> func)
93+
{
94+
await With(client, DefaultShippingMethodDraft(new ShippingMethodDraft()), draftAction, func);
8895
}
8996

9097
public static async Task WithShippingMethod(IClient client, Func<ShippingMethod, Task> func)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using commercetools.Sdk.Domain.Common;
2+
3+
namespace commercetools.Sdk.Client
4+
{
5+
public class CheckByIdCommand<T> : CheckCommand<T>
6+
where T : Resource<T>, ICheckable<T>
7+
{
8+
/// <summary>
9+
/// Initializes a new instance of the <see cref="CheckByIdCommand{T}"/> class.
10+
/// </summary>
11+
/// <param name="id">The identifier.</param>
12+
public CheckByIdCommand(string id)
13+
{
14+
this.Init(id);
15+
}
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="CheckByIdCommand{T}"/> class.
19+
/// </summary>
20+
/// <param name="identifiable">The identifying resource</param>
21+
public CheckByIdCommand(IIdentifiable<T> identifiable)
22+
{
23+
this.Init(identifiable.Id);
24+
}
25+
26+
private void Init(string id)
27+
{
28+
this.ParameterKey = Parameters.Id;
29+
this.ParameterValue = id;
30+
}
31+
}
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using commercetools.Sdk.Domain.Common;
2+
3+
namespace commercetools.Sdk.Client
4+
{
5+
public class CheckByKeyCommand<T> : CheckCommand<T>
6+
where T : Resource<T>, ICheckable<T>
7+
{
8+
public CheckByKeyCommand(string key)
9+
{
10+
this.Init(key);
11+
}
12+
13+
private void Init(string key)
14+
{
15+
this.ParameterKey = Parameters.Key;
16+
this.ParameterValue = key;
17+
}
18+
}
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
using commercetools.Sdk.Domain.Common;
3+
4+
namespace commercetools.Sdk.Client
5+
{
6+
public class CheckByQueryCommand<T> : CheckCommand<T>
7+
where T : Resource<T>, ICheckable<T>
8+
{
9+
public CheckByQueryCommand()
10+
{
11+
Where = new List<string>();
12+
}
13+
14+
public List<string> Where { get; private set; }
15+
}
16+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Linq.Expressions;
5+
using commercetools.Sdk.Domain.Common;
6+
using commercetools.Sdk.Domain.Query;
7+
8+
namespace commercetools.Sdk.Client
9+
{
10+
public static class CheckByQueryCommandExtensions
11+
{
12+
public static CheckByQueryCommand<T> Where<T>(this CheckByQueryCommand<T> command, Expression<Func<T, bool>> expression)
13+
where T : Resource<T>, ICheckable<T>
14+
{
15+
command.Where.Add(new QueryPredicate<T>(expression).ToString());
16+
return command;
17+
}
18+
19+
public static CheckByQueryCommand<T> Where<T>(this CheckByQueryCommand<T> command, string expression)
20+
where T : Resource<T>, ICheckable<T>
21+
{
22+
command.Where.Add(expression);
23+
return command;
24+
}
25+
26+
public static CheckByQueryCommand<T> SetWhere<T>(this CheckByQueryCommand<T> command, IEnumerable<QueryPredicate<T>> queryPredicates)
27+
where T : Resource<T>, ICheckable<T>
28+
{
29+
return command.SetWhere(queryPredicates.Select(predicate => predicate.ToString()));
30+
}
31+
32+
public static CheckByQueryCommand<T> SetWhere<T>(this CheckByQueryCommand<T> command, IEnumerable<string> queryPredicates)
33+
where T : Resource<T>, ICheckable<T>
34+
{
35+
command.Where.Clear();
36+
foreach (var query in queryPredicates)
37+
{
38+
command.Where.Add(query);
39+
}
40+
41+
return command;
42+
}
43+
44+
public static CheckByQueryCommand<T> SetWhere<T>(this CheckByQueryCommand<T> command, QueryPredicate<T> queryPredicate)
45+
where T : Resource<T>, ICheckable<T>
46+
{
47+
return command.SetWhere(queryPredicate.ToString());
48+
}
49+
50+
public static CheckByQueryCommand<T> SetWhere<T>(this CheckByQueryCommand<T> command, string queryPredicate)
51+
where T : Resource<T>, ICheckable<T>
52+
{
53+
command.Where.Clear();
54+
command.Where.Add(queryPredicate);
55+
return command;
56+
}
57+
}
58+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using commercetools.Sdk.Domain.Common;
2+
3+
namespace commercetools.Sdk.Client
4+
{
5+
public abstract class CheckCommand<T> : Command<T>
6+
where T : Resource<T>, ICheckable<T>
7+
{
8+
protected CheckCommand()
9+
{
10+
}
11+
12+
public string ParameterKey { get; protected set; }
13+
14+
public object ParameterValue { get; protected set; }
15+
16+
public override System.Type ResourceType => typeof(T);
17+
}
18+
}

commercetools.Sdk/commercetools.Sdk.Client/GetCommandExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@ public static GetByIdCommand<T> GetById<T>(this IIdentifiable<T> resource)
3535
return new GetByIdCommand<T>(resource);
3636
}
3737

38+
public static CheckByIdCommand<T> CheckById<T>(this IIdentifiable<T> resource)
39+
where T : Resource<T>, ICheckable<T>
40+
{
41+
return new CheckByIdCommand<T>(resource);
42+
}
43+
3844
public static GetByKeyCommand<T> GetByKey<T>(this IKeyReferencable<T> resource)
3945
where T : Resource<T>
4046
{
4147
return new GetByKeyCommand<T>(resource.Key);
4248
}
49+
50+
public static CheckByKeyCommand<T> CheckByKey<T>(this IKeyReferencable<T> resource)
51+
where T : Resource<T>, ICheckable<T>
52+
{
53+
return new CheckByKeyCommand<T>(resource.Key);
54+
}
4355
}
4456
}

commercetools.Sdk/commercetools.Sdk.Client/IClient.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Threading.Tasks;
1+
using System.Net;
2+
using System.Net.Http;
3+
using System.Threading.Tasks;
24

35
namespace commercetools.Sdk.Client
46
{
@@ -22,5 +24,7 @@ public interface IClient
2224
/// <param name="command">The command.</param>
2325
/// <returns>The object of the domain specific type.</returns>
2426
Task<T> ExecuteAsync<T>(ICommand<T> command);
27+
28+
Task<HttpResponseMessage> ExecuteAsyncWithResponse<T>(ICommand<T> command);
2529
}
2630
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace commercetools.Sdk.Domain.Common
2+
{
3+
public interface ICheckable<T> where T : Resource<T>
4+
{
5+
}
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using commercetools.Sdk.Domain.Customers;
2+
3+
namespace commercetools.Sdk.Domain.Messages.Customers
4+
{
5+
[TypeMarker("CustomerDeleted")]
6+
public class CustomerDeletedMessage : Message<Customer>
7+
{
8+
public Customer Customer { get; set; }
9+
}
10+
}

0 commit comments

Comments
 (0)