Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Nov 6, 2022
1 parent cd5bcf5 commit 9e459e1
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using starsky.foundation.platform.Exceptions;

namespace starskytest.starsky.foundation.platform.Exceptions
{
[TestClass]
public class TelemetryServiceExceptionTest
{
[TestMethod]
[ExpectedException(typeof(TelemetryServiceException))]
public void TelemetryServiceException()
{
var info = new SerializationInfo(typeof(Exception),
new FormatterConverter());
info.AddValue("Number", 1);
info.AddValue("SqlState", "SqlState");
info.AddValue("Message", "");
info.AddValue("InnerException", new Exception());
info.AddValue("HelpURL", "");
info.AddValue("StackTraceString", "");
info.AddValue("RemoteStackTraceString", "");
info.AddValue("RemoteStackIndex", 1);
info.AddValue("HResult", 1);
info.AddValue("Source", "");
info.AddValue("WatsonBuckets", Array.Empty<byte>());

var ctor =
typeof(TelemetryServiceException).GetConstructors(BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.InvokeMethod).FirstOrDefault();
var instance =
( TelemetryServiceException ) ctor!.Invoke(new object[]
{
info,
new StreamingContext(StreamingContextStates.All)
});

throw instance;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Reflection;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using starsky.foundation.webtelemetry.Models;

namespace starskytest.starsky.foundation.webtelemetry.Models
{
[TestClass]
public sealed class EmptyOperationHolderTest
{
[TestMethod]
public void EmptyOperationHolder_Disposed()
{
var operationHolder = new EmptyOperationHolder<RequestTelemetry>();
operationHolder.Dispose();

var isDisposed = operationHolder.GetType().GetProperty("IsDisposed", BindingFlags.Instance | BindingFlags.NonPublic);

var value = (bool?) isDisposed!.GetValue(operationHolder);
Assert.IsTrue(value);
}
}
}

0 comments on commit 9e459e1

Please sign in to comment.