public void CancelingAnActionClosesAllChildObjectsThatAreNotCancelable() { // given var childObjectOne = Substitute.For <IOpenKitObject>(); var childObjectTwo = Substitute.For <IOpenKitObject>(); var target = CreateStubAction(); IOpenKitComposite targetComposite = target; targetComposite.StoreChildInList(childObjectOne); targetComposite.StoreChildInList(childObjectTwo); // when target.CancelAction(); // then childObjectOne.Received(1).Dispose(); childObjectTwo.Received(1).Dispose(); #if NET35 || NET40 // old NSubstitute does only print the class, nothing about instance mockLogger.Received(2).Warn(Arg.Is <string>(message => message.EndsWith("is not cancelable - falling back to Dispose() instead"))); #else mockLogger.Received(1).Warn($"{childObjectOne} is not cancelable - falling back to Dispose() instead"); mockLogger.Received(1).Warn($"{childObjectTwo} is not cancelable - falling back to Dispose() instead"); #endif }
public void OnChildClosedRemovesArgumentFromListOfChildren() { // given IOpenKitComposite target = CreateOpenKit().Build(); var childObjectOne = Substitute.For <IOpenKitObject>(); var childObjectTwo = Substitute.For <IOpenKitObject>(); target.StoreChildInList(childObjectOne); target.StoreChildInList(childObjectTwo); // when target.OnChildClosed(childObjectOne); // then var childObjects = target.GetCopyOfChildObjects(); Assert.That(childObjects.Count, Is.EqualTo(1)); Assert.That(childObjects[0], Is.SameAs(childObjectTwo)); // when target.OnChildClosed(childObjectTwo); // then Assert.That(target.GetCopyOfChildObjects(), Is.Empty); }
public void CreateSessionWithoutIpAddsNewlyCreatedSessionToListOfChildren() { // given var target = CreateOpenKit().Build(); IOpenKitComposite targetComposite = target; // when var sessionOne = target.CreateSession(); // then var childObjects = targetComposite.GetCopyOfChildObjects(); Assert.That(sessionOne, Is.Not.Null); Assert.That(childObjects.Count, Is.EqualTo(1)); Assert.That(childObjects[0], Is.SameAs(sessionOne)); // when var sessionTwo = target.CreateSession(); // then childObjects = targetComposite.GetCopyOfChildObjects(); Assert.That(sessionTwo, Is.Not.Null); Assert.That(childObjects.Count, Is.EqualTo(2)); Assert.That(childObjects[0], Is.SameAs(sessionOne)); Assert.That(childObjects[1], Is.SameAs(sessionTwo)); }
public void CallingShutdownASecondTimeReturnsImmediately() { // given var target = CreateOpenKit().Build(); IOpenKitComposite targetComposite = target; var childObjectOne = Substitute.For <IOpenKitObject>(); var childObjectTwo = Substitute.For <IOpenKitObject>(); targetComposite.StoreChildInList(childObjectOne); targetComposite.StoreChildInList(childObjectTwo); // when target.Shutdown(); // then mockBeaconCacheEvictor.Received(1).Stop(); mockBeaconSender.Received(1).Shutdown(); childObjectOne.Received(1).Dispose(); childObjectTwo.Received(1).Dispose(); mockBeaconCacheEvictor.ClearReceivedCalls(); mockBeaconSender.ClearReceivedCalls(); childObjectOne.ClearReceivedCalls(); childObjectTwo.ClearReceivedCalls(); // and when target.Shutdown(); // then Assert.That(mockBeaconCacheEvictor.ReceivedCalls(), Is.Empty); Assert.That(mockBeaconSender.ReceivedCalls(), Is.Empty); Assert.That(childObjectOne.ReceivedCalls(), Is.Empty); Assert.That(childObjectTwo.ReceivedCalls(), Is.Empty); }
public void SetUp() { mockLogger = Substitute.For <ILogger>(); mockOpenKitConfiguration = Substitute.For <IOpenKitConfiguration>(); mockOpenKitConfiguration.ApplicationId.Returns(string.Empty); mockOpenKitConfiguration.ApplicationName.Returns(string.Empty); mockOpenKitConfiguration.ApplicationVersion.Returns(string.Empty); mockOpenKitConfiguration.DeviceId.Returns(DeviceId); mockPrivacyConfiguration = Substitute.For <IPrivacyConfiguration>(); mockBeaconCache = Substitute.For <IBeaconCache>(); mockSessionIdProvider = Substitute.For <ISessionIdProvider>(); mockThreadIdProvider = Substitute.For <IThreadIdProvider>(); mockTimingProvider = Substitute.For <ITimingProvider>(); mockParent = Substitute.For <IOpenKitComposite>(); mockInput = Substitute.For <ISessionCreatorInput>(); mockInput.Logger.Returns(mockLogger); mockInput.OpenKitConfiguration.Returns(mockOpenKitConfiguration); mockInput.PrivacyConfiguration.Returns(mockPrivacyConfiguration); mockInput.BeaconCache.Returns(mockBeaconCache); mockInput.SessionIdProvider.Returns(mockSessionIdProvider); mockInput.ThreadIdProvider.Returns(mockThreadIdProvider); mockInput.TimingProvider.Returns(mockTimingProvider); mockInput.CurrentServerId.Returns(ServerId); }
/// <summary> /// This constructor can be used for tracing and timing of a web request handled by any 3rd party HTTP Client. /// Setting the Dynatrace tag to the <see cref="OpenKitConstants.WEBREQUEST_TAG_HEADER"/> HTTP header has to /// be done manually by the user. /// </summary> internal WebRequestTracer(ILogger logger, IOpenKitComposite parent, IBeacon beacon, string url) : this(logger, parent, beacon) { if (IsValidUrlScheme(url)) { Url = url.Split(new [] { '?' }, 2)[0]; } }
public void SetUp() { mockLogger = Substitute.For <ILogger>(); mockParent = Substitute.For <IOpenKitComposite>(); mockBeacon = Substitute.For <IBeacon>(); mockBeacon.CreateTag(Arg.Any <int>(), Arg.Any <int>()).Returns(Tag); mockBeacon.NextSequenceNumber.Returns(SequenceNumber); }
ISessionInternals ISessionCreator.CreateSession(IOpenKitComposite parent) { var configuration = BeaconConfiguration.From(openKitConfiguration, privacyConfiguration, serverId); var beacon = new Beacon(this, configuration); var session = new Session(Logger, parent, beacon); SessionSequenceNumber++; return(session); }
public void SetUp() { mockLogger = Substitute.For <ILogger>(); mockLogger.IsDebugEnabled.Returns(true); mockLogger.IsDebugEnabled.Returns(true); nextBeaconId = IdBaseOffset; mockBeacon = Substitute.For <IBeacon>(); mockBeacon.NextId.Returns(_ => nextBeaconId++); parentComposite = Substitute.For <IOpenKitComposite>(); }
internal Session( ILogger logger, IOpenKitComposite parent, IBeacon beacon ) { state = new SessionState(this); this.logger = logger; this.parent = parent; this.beacon = beacon; beacon.StartSession(); }
public void OnChildClosedRemovesChildFromList() { // given IOpenKitComposite target = CreateStubAction(); var childObject = Substitute.For <IOpenKitObject>(); target.StoreChildInList(childObject); // when target.OnChildClosed(childObject); // then Assert.That(target.GetCopyOfChildObjects(), Is.Empty); }
/// <summary> /// Constructor for creating a new WebRequestTracer instance. /// </summary> /// <param name="logger">the logger used to log information.</param> /// <param name="parent">the parent object to which this web request tracer belongs to</param> /// <param name="beacon">the <see cref="Dynatrace.OpenKit.Protocol.Beacon"/> for sending data and tag creation</param> internal WebRequestTracer(ILogger logger, IOpenKitComposite parent, IBeacon beacon) { this.logger = logger; this.beacon = beacon; this.parent = parent; parentActionId = parent.ActionId; // creating start sequence number has to be done here, because it's needed for the creation of the tag StartSequenceNo = beacon.NextSequenceNumber; tag = beacon.CreateTag(parentActionId, StartSequenceNo); StartTime = beacon.CurrentTimestamp; }
public void EnterActionAddsLeafActionToListOfChildObjects() { // given var target = CreateRootAction(); IOpenKitComposite targetComposite = target; // when var obtained = target.EnterAction(ChildActionName); // then var childObjects = targetComposite.GetCopyOfChildObjects(); Assert.That(childObjects.Count, Is.EqualTo(1)); Assert.That(childObjects[0], Is.SameAs(obtained)); }
public void TraceWebRequestAttachesWebRequestTracerAsChildObject() { // given var target = CreateStubAction(); IOpenKitComposite targetComposite = target; // when var obtained = target.TraceWebRequest("http://example.com/pages/"); // then var childObjects = targetComposite.GetCopyOfChildObjects(); Assert.That(childObjects.Count, Is.EqualTo(1)); Assert.That(childObjects[0], Is.SameAs(obtained)); }
internal BaseAction(ILogger logger, IOpenKitComposite parent, string name, IBeacon beacon) { Logger = logger; this.parent = parent; Id = beacon.NextId; Name = name; StartTime = beacon.CurrentTimestamp; StartSequenceNo = beacon.NextSequenceNumber; Beacon = beacon; }
public void LeavingAnActionClosesAllChildObjects() { // given var childObjectOne = Substitute.For <IOpenKitObject>(); var childObjectTwo = Substitute.For <IOpenKitObject>(); var target = CreateStubAction(); IOpenKitComposite targetComposite = target; targetComposite.StoreChildInList(childObjectOne); targetComposite.StoreChildInList(childObjectTwo); // when target.LeaveAction(); // then childObjectOne.Received(1).Dispose(); childObjectTwo.Received(1).Dispose(); }
internal SessionProxy( ILogger logger, IOpenKitComposite parent, ISessionCreator sessionCreator, ITimingProvider timingProvider, IBeaconSender beaconSender, ISessionWatchdog sessionWatchdog) { this.logger = logger; this.parent = parent; this.sessionCreator = sessionCreator; this.timingProvider = timingProvider; this.beaconSender = beaconSender; this.sessionWatchdog = sessionWatchdog; var currentServerConfig = beaconSender.LastServerConfiguration; CreateInitialSessionAndMakeCurrent(currentServerConfig); }
public void CancelingAnActionCancelsAllChildObjects() { // given var childObjectOne = Substitute.For <ICancelableOpenKitObject>(); var childObjectTwo = Substitute.For <ICancelableOpenKitObject>(); var target = CreateStubAction(); IOpenKitComposite targetComposite = target; targetComposite.StoreChildInList(childObjectOne); targetComposite.StoreChildInList(childObjectTwo); // when target.CancelAction(); // then childObjectOne.Received(1).Cancel(); childObjectTwo.Received(1).Cancel(); }
public void ShutdownDisposesAllChildObjects() { // given var target = CreateOpenKit().Build(); IOpenKitComposite targetComposite = target; var childObjectOne = Substitute.For <IOpenKitObject>(); var childObjectTwo = Substitute.For <IOpenKitObject>(); targetComposite.StoreChildInList(childObjectOne); targetComposite.StoreChildInList(childObjectTwo); // when target.Shutdown(); // then childObjectOne.Received(1).Dispose(); childObjectTwo.Received(1).Dispose(); }
internal TestWebRequestTracerBuilder With(IOpenKitComposite parent) { parentComposite = parent; return(this); }
internal TestWebRequestTracerBuilder() { beacon = Substitute.For <IBeacon>(); logger = Substitute.For <ILogger>(); parentComposite = Substitute.For <OpenKitComposite>(); }
internal StubBaseAction(ILogger logger, IOpenKitComposite parentComposite, string name, IBeacon beacon, IAction parentAction) : base(logger, parentComposite, name, beacon) { ParentAction = parentAction; }