From 3f7edc7eeed67e287f3104f085ef497f5478fed6 Mon Sep 17 00:00:00 2001 From: ryannewington Date: Sat, 18 Mar 2017 09:04:53 +1100 Subject: [PATCH] Fixes issue #11 - An ArgumentNullException is thrown for the delete of an empty resource list --- .../DeleteTests.cs | 16 ++++++++++++++++ .../ServiceImplementation/ResourceClient.cs | 11 +++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Lithnet.ResourceManagement.Client.UnitTests/DeleteTests.cs b/src/Lithnet.ResourceManagement.Client.UnitTests/DeleteTests.cs index 9500c8d..1ada1c1 100644 --- a/src/Lithnet.ResourceManagement.Client.UnitTests/DeleteTests.cs +++ b/src/Lithnet.ResourceManagement.Client.UnitTests/DeleteTests.cs @@ -7,6 +7,22 @@ namespace Lithnet.ResourceManagement.Client.UnitTests [TestClass] public class DeleteTests { + [TestMethod] + public void DeleteEmptyListResource() + { + ResourceManagementClient client = new ResourceManagementClient(); + + client.DeleteResources(new List()); + } + + [TestMethod] + public void DeleteEmptyListUniqueIdentifier() + { + ResourceManagementClient client = new ResourceManagementClient(); + + client.DeleteResources(new List()); + } + [TestMethod] public void DeleteByID() { diff --git a/src/Lithnet.ResourceManagement.Client/ServiceImplementation/ResourceClient.cs b/src/Lithnet.ResourceManagement.Client/ServiceImplementation/ResourceClient.cs index f079f79..b84da6f 100644 --- a/src/Lithnet.ResourceManagement.Client/ServiceImplementation/ResourceClient.cs +++ b/src/Lithnet.ResourceManagement.Client/ServiceImplementation/ResourceClient.cs @@ -46,7 +46,7 @@ public void Put(IEnumerable resources) { throw new ArgumentNullException(nameof(resources)); } - + using (Message message = MessageComposer.CreatePutMessage(resources.ToArray())) { if (message == null) @@ -107,7 +107,14 @@ public void Delete(IEnumerable resourceIDs) throw new ArgumentNullException(nameof(resourceIDs)); } - using (Message message = MessageComposer.CreateDeleteMessage(resourceIDs.ToArray())) + UniqueIdentifier[] ids = resourceIDs.ToArray(); + + if (ids.Length == 0) + { + return; + } + + using (Message message = MessageComposer.CreateDeleteMessage(ids)) { using (Message responseMessage = this.Invoke((c) => c.Delete(message))) {