From f99c5fb5a3bdc9e914925ac65d80c82470ce43a4 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Fri, 10 Nov 2023 12:34:09 +0300 Subject: [PATCH] Adds tests --- .../Middleware/ActivitySourceRegistryTests.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Microsoft.Kiota.Http.HttpClientLibrary.Tests/Middleware/ActivitySourceRegistryTests.cs diff --git a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Middleware/ActivitySourceRegistryTests.cs b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Middleware/ActivitySourceRegistryTests.cs new file mode 100644 index 0000000..02a747a --- /dev/null +++ b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Middleware/ActivitySourceRegistryTests.cs @@ -0,0 +1,44 @@ +using System; +using Microsoft.Kiota.Http.HttpClientLibrary.Middleware; +using Xunit; + +namespace Microsoft.Kiota.Http.HttpClientLibrary.Tests.Middleware.Registries +{ + public class ActivitySourceRegistryTests + { + [Fact] + public void Defensive() + { + Assert.Throws(() => ActivitySourceRegistry.DefaultInstance.GetOrCreateActivitySource("")); + Assert.Throws(() => ActivitySourceRegistry.DefaultInstance.GetOrCreateActivitySource(null)); + } + + [Fact] + public void CreatesNewInstanceOnFirstCallAndReturnsSameInstance() + { + // Act + var activitySource = ActivitySourceRegistry.DefaultInstance.GetOrCreateActivitySource("sample source"); + Assert.NotNull(activitySource); + + var activitySource2 = ActivitySourceRegistry.DefaultInstance.GetOrCreateActivitySource("sample source"); + Assert.NotNull(activitySource); + + // They are the same instance + Assert.Equal(activitySource, activitySource2); + } + + [Fact] + public void CreatesDifferentInstances() + { + // Act + var activitySource = ActivitySourceRegistry.DefaultInstance.GetOrCreateActivitySource("sample source"); + Assert.NotNull(activitySource); + + var activitySource2 = ActivitySourceRegistry.DefaultInstance.GetOrCreateActivitySource("sample source 2"); + Assert.NotNull(activitySource); + + // They are not the same instance + Assert.NotEqual(activitySource, activitySource2); + } + } +}