Skip to content

Commit

Permalink
tests: Modify tests to account for XUnit issue.
Browse files Browse the repository at this point in the history
Assert.Equal gives a false negative if dictionaries being compared contain null elements.

See xunit/xunit#2824
  • Loading branch information
amanda-tarafa committed Nov 21, 2023
1 parent 891d0b4 commit d9abcaf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
using Google.Apis.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void ModifyDatasetLabels_Simple(bool runAsync)
["lab6"] = null,
};

Assert.Equal(expectedResult, result);
Assert.Collection(result, DictionaryElementInspectors(expectedResult));

var finalLabels = client.GetDataset(datasetId).Resource.Labels;
var expectedFinalLabels = new Dictionary<string, string>
Expand All @@ -83,6 +84,10 @@ public void ModifyDatasetLabels_Simple(bool runAsync)
};

Assert.Equal(expectedFinalLabels, finalLabels);

Action<KeyValuePair<string, string>>[] DictionaryElementInspectors(Dictionary<string, string> expectedElements) =>
expectedElements.Select<KeyValuePair<string, string>, Action<KeyValuePair<string, string>>>(expected =>
(actual) => Assert.Equal(expected, actual)).ToArray();
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@
using Google.Cloud.ClientTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void ModifyBucketLabels_Simple(bool runAsync)
["lab6"] = null,
};

Assert.Equal(expectedResult, result);
Assert.Collection(result, DictionaryElementInspectors(expectedResult));

var finalLabels = client.GetBucket(bucketName).Labels;
var expectedFinalLabels = new Dictionary<string, string>
Expand All @@ -85,6 +86,10 @@ public void ModifyBucketLabels_Simple(bool runAsync)
};

Assert.Equal(expectedFinalLabels, finalLabels);

Action<KeyValuePair<string, string>>[] DictionaryElementInspectors(Dictionary<string, string> expectedElements) =>
expectedElements.Select<KeyValuePair<string, string>, Action<KeyValuePair<string, string>>>(expected =>
(actual) => Assert.Equal(expected, actual)).ToArray();
}

[Theory]
Expand Down

0 comments on commit d9abcaf

Please sign in to comment.