Skip to content

Commit

Permalink
EdgeHub: Fix error if client does not send product info (#1496)
Browse files Browse the repository at this point in the history
* Update Product Info

* Fix SerDeExtensions
  • Loading branch information
varunpuranik authored Aug 6, 2019
1 parent 0ce39ee commit bb31324
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ProductInfoStore(IKeyValueStore<string, string> productInfoEntityStore, s
public Task SetProductInfo(string id, string productInfo)
{
Preconditions.CheckNonWhiteSpace(id, nameof(id));
return this.productInfoEntityStore.Put(id, productInfo);
return !string.IsNullOrWhiteSpace(productInfo) ? this.productInfoEntityStore.Put(id, productInfo) : Task.CompletedTask;
}

public async Task<string> GetProductInfo(string id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ public async Task SmokeTest()
}
}

[Fact]
public async Task EmptyProductInfoTest()
{
// Arrange
string edgeProductInfo = "IoTEdge 1.0.7";
var storeProvider = new StoreProvider(new InMemoryDbStoreProvider());
IEntityStore<string, string> store = storeProvider.GetEntityStore<string, string>("productInfo");
var productInfoStore = new ProductInfoStore(store, edgeProductInfo);

// Act
await productInfoStore.SetProductInfo("d1", string.Empty);
string productInfoValue = await productInfoStore.GetProductInfo("d1");

// Assert
Assert.Equal(string.Empty, productInfoValue);
}

[Fact]
public void ProductInfoCtorTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public static T FromJson<T>(this string json)
{
if (string.IsNullOrWhiteSpace(json))
{
return default(T);
return typeof(T) == typeof(string)
? (T)(object)json
: default(T);
}

return typeof(T) == typeof(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ public void FromJsonTest()
Assert.Equal(str, SerDeExtensions.FromJson<string>(str));
}

[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(" some value")]
public void StringToJsonRoundtripTest(string input)
{
string value = SerDeExtensions.FromJson<string>(SerDeExtensions.ToJson(input));
Assert.Equal(input, value);
}

[Fact]
public void StringToBytesRoundtripTest()
{
Expand Down

0 comments on commit bb31324

Please sign in to comment.