Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Omondi committed Nov 10, 2023
1 parent 57ff389 commit f99c5fb
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<ArgumentNullException>(() => ActivitySourceRegistry.DefaultInstance.GetOrCreateActivitySource(""));
Assert.Throws<ArgumentNullException>(() => 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);
}
}
}

0 comments on commit f99c5fb

Please sign in to comment.