public void BuildForwardsKeyValueDefaultsToInstance()
        {
            // given
            var defaults = ResponseAttributesDefaults.JsonResponse;
            var target   = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.Build();

            // then
            Assert.That(obtained.MaxBeaconSizeInBytes, Is.EqualTo(defaults.MaxBeaconSizeInBytes));
            Assert.That(obtained.MaxSessionDurationInMilliseconds,
                        Is.EqualTo(defaults.MaxSessionDurationInMilliseconds));
            Assert.That(obtained.MaxEventsPerSession, Is.EqualTo(defaults.MaxEventsPerSession));
            Assert.That(obtained.SessionTimeoutInMilliseconds, Is.EqualTo(defaults.SessionTimeoutInMilliseconds));
            Assert.That(obtained.SendIntervalInMilliseconds, Is.EqualTo(defaults.SendIntervalInMilliseconds));
            Assert.That(obtained.VisitStoreVersion, Is.EqualTo(defaults.VisitStoreVersion));

            Assert.That(obtained.IsCapture, Is.EqualTo(defaults.IsCapture));
            Assert.That(obtained.IsCaptureCrashes, Is.EqualTo(defaults.IsCaptureCrashes));
            Assert.That(obtained.IsCaptureErrors, Is.EqualTo(defaults.IsCaptureErrors));
            Assert.That(obtained.ApplicationId, Is.EqualTo(defaults.ApplicationId));

            Assert.That(obtained.Multiplicity, Is.EqualTo(defaults.Multiplicity));
            Assert.That(obtained.ServerId, Is.EqualTo(defaults.ServerId));
            Assert.That(obtained.Status, Is.EqualTo(defaults.Status));

            Assert.That(obtained.TimestampInMilliseconds, Is.EqualTo(defaults.TimestampInMilliseconds));
        }
        public void BuildWithJsonDefaultsHasNoAttributesSetOnInstance()
        {
            // given
            var target = ResponseAttributes.WithJsonDefaults().Build();

            // when, then
            foreach (var attribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                Assert.That(target.IsAttributeSet(attribute), Is.False);
            }
        }
        public void BuildPropagatesMaxBeaconSizeToInstance()
        {
            // given
            const int beaconSize = 73;
            var       target     = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithMaxBeaconSizeInBytes(beaconSize).Build();

            // then
            Assert.That(obtained.MaxBeaconSizeInBytes, Is.EqualTo(beaconSize));
        }
        public void BuildPropagatesMultiplicityToInstance()
        {
            // given
            const int multiplicity = 73;
            var       target       = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithMultiplicity(multiplicity).Build();

            // then
            Assert.That(obtained.Multiplicity, Is.EqualTo(multiplicity));
        }
        public void BuildPropagatesVisitStoreVersionToInstance()
        {
            // given
            const int visitStoreVersion = 73;
            var       target            = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithVisitStoreVersion(visitStoreVersion).Build();

            // then
            Assert.That(obtained.VisitStoreVersion, Is.EqualTo(visitStoreVersion));
        }
        public void BuildPropagatesSendIntervalToInstance()
        {
            // given
            const int sendInterval = 73;
            var       target       = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithSendIntervalInMilliseconds(sendInterval).Build();

            // then
            Assert.That(obtained.SendIntervalInMilliseconds, Is.EqualTo(sendInterval));
        }
        public void BuildPropagatesStatusToInstance()
        {
            // given
            const string status = "status";
            var          target = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithStatus(status).Build();

            // then
            Assert.That(obtained.Status, Is.EqualTo(status));
        }
        public void BuildPropagatesServerIdToInstance()
        {
            // given
            const int serverId = 73;
            var       target   = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithServerId(serverId).Build();

            // then
            Assert.That(obtained.ServerId, Is.EqualTo(serverId));
        }
        public void BuildPropagatesMaxEventsPerSessionToInstance()
        {
            // given
            const int eventsPerSession = 73;
            var       target           = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithMaxEventsPerSession(eventsPerSession).Build();

            // then
            Assert.That(obtained.MaxEventsPerSession, Is.EqualTo(eventsPerSession));
        }
        public void BuildPropagatesMaxSessionDurationToInstance()
        {
            // given
            const int sessionDuration = 73;
            var       target          = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithMaxSessionDurationInMilliseconds(sessionDuration).Build();

            // then
            Assert.That(obtained.MaxSessionDurationInMilliseconds, Is.EqualTo(sessionDuration));
        }
        public void BuildPropagatesTimestampToInstance()
        {
            // given
            const long timestamp = 73;
            var        target    = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithTimestampInMilliseconds(timestamp).Build();

            // then
            Assert.That(obtained.TimestampInMilliseconds, Is.EqualTo(timestamp));
        }
        public void BuildPropagatesApplicationIdToInstance()
        {
            // given
            var applicationId = Guid.NewGuid().ToString();
            var target        = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithApplicationId(applicationId).Build();

            // then
            Assert.That(obtained.ApplicationId, Is.EqualTo(applicationId));
        }
        public void BuildPropagatesIsCaptureErrorsToInstance()
        {
            // given
            var isCaptureErrors = !ResponseAttributesDefaults.JsonResponse.IsCaptureErrors;
            var target          = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithCaptureErrors(isCaptureErrors).Build();

            // then
            Assert.That(obtained.IsCaptureErrors, Is.EqualTo(isCaptureErrors));
        }
        public void MergingDefaultResponsesReturnsResponseWithoutAnyAttributeSet()
        {
            // given
            var toMerge = ResponseAttributes.WithUndefinedDefaults().Build();
            var target  = ResponseAttributes.WithJsonDefaults().Build();

            // when
            var obtained = target.Merge(toMerge);

            // then
            foreach (var attribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                Assert.That(obtained.IsAttributeSet(attribute), Is.False);
            }
        }
        public static IResponseAttributes Parse(string jsonResponse)
        {
            var parser = new JsonParser(jsonResponse);

            var parsedValue = parser.Parse();

            var rootObject = (JsonObjectValue)parsedValue;

            var builder = ResponseAttributes.WithJsonDefaults();

            ApplyAgentConfiguration(builder, rootObject);
            ApplyApplicationConfiguration(builder, rootObject);
            ApplyDynamicConfiguration(builder, rootObject);
            ApplyRootAttributes(builder, rootObject);

            return(builder.Build());
        }
        public void WithMaxBeaconSizeSetsAttributeOnInstance()
        {
            // given
            const ResponseAttribute attribute = ResponseAttribute.MAX_BEACON_SIZE;
            var target = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithMaxBeaconSizeInBytes(37).Build();

            // then
            Assert.That(obtained.IsAttributeSet(attribute), Is.True);

            foreach (var unsetAttribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                if (attribute == unsetAttribute)
                {
                    continue;
                }

                Assert.That(obtained.IsAttributeSet(unsetAttribute), Is.False);
            }
        }
        public void WithTimestampSetsAttributeOnInstance()
        {
            // given
            const ResponseAttribute attribute = ResponseAttribute.TIMESTAMP;
            var target = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithTimestampInMilliseconds(37L).Build();

            // then
            Assert.That(obtained.IsAttributeSet(attribute), Is.True);

            foreach (var unsetAttribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                if (attribute == unsetAttribute)
                {
                    continue;
                }

                Assert.That(obtained.IsAttributeSet(unsetAttribute), Is.False);
            }
        }
        public void WithStatusSetsAttributeOnInstance()
        {
            // given
            const ResponseAttribute attribute = ResponseAttribute.STATUS;
            var target = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithStatus("status").Build();

            // then
            Assert.That(obtained.IsAttributeSet(attribute), Is.True);

            foreach (var unsetAttribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                if (attribute == unsetAttribute)
                {
                    continue;
                }

                Assert.That(obtained.IsAttributeSet(unsetAttribute), Is.False);
            }
        }
        public void WithMaxEventsPerSessionSetsAttributeOnInstance()
        {
            // given
            const ResponseAttribute attribute = ResponseAttribute.MAX_EVENTS_PER_SESSION;
            var target = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithMaxEventsPerSession(37).Build();

            // then
            Assert.That(obtained.IsAttributeSet(attribute), Is.True);

            foreach (var unsetAttribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                if (attribute == unsetAttribute)
                {
                    continue;
                }

                Assert.That(obtained.IsAttributeSet(unsetAttribute), Is.False);
            }
        }
        public void WithSessionTimeoutSetsAttributeOnInstance()
        {
            // given
            ResponseAttribute attribute = ResponseAttribute.SESSION_IDLE_TIMEOUT;
            var target = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithSessionTimeoutInMilliseconds(37).Build();

            // then
            Assert.That(obtained.IsAttributeSet(attribute), Is.True);

            foreach (var unsetAttribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                if (attribute == unsetAttribute)
                {
                    continue;
                }

                Assert.That(obtained.IsAttributeSet(unsetAttribute), Is.False);
            }
        }
        public void WithVisitStoreVersionSetsAttributeOnInstance()
        {
            // given
            const ResponseAttribute attribute = ResponseAttribute.VISIT_STORE_VERSION;
            var target = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithVisitStoreVersion(37).Build();

            // then
            Assert.That(obtained.IsAttributeSet(attribute), Is.True);

            foreach (var unsetAttribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                if (attribute == unsetAttribute)
                {
                    continue;
                }

                Assert.That(obtained.IsAttributeSet(unsetAttribute), Is.False);
            }
        }
        public void WithApplicationIdSetsAttributeOnInstance()
        {
            // given
            const ResponseAttribute attribute = ResponseAttribute.APPLICATION_ID;
            var target = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithApplicationId(Guid.NewGuid().ToString()).Build();

            // then
            Assert.That(obtained.IsAttributeSet(attribute), Is.True);

            foreach (var unsetAttribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                if (attribute == unsetAttribute)
                {
                    continue;
                }

                Assert.That(obtained.IsAttributeSet(unsetAttribute), Is.False);
            }
        }
        public void WithCaptureErrorsSetsAttributeOnInstance()
        {
            // given
            const ResponseAttribute attribute = ResponseAttribute.IS_CAPTURE_ERRORS;
            var target = ResponseAttributes.WithJsonDefaults();

            // when
            var obtained = target.WithCaptureErrors(!ResponseAttributesDefaults.JsonResponse.IsCaptureErrors).Build();

            // then
            Assert.That(obtained.IsAttributeSet(attribute), Is.True);

            foreach (var unsetAttribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                if (attribute == unsetAttribute)
                {
                    continue;
                }

                Assert.That(obtained.IsAttributeSet(unsetAttribute), Is.False);
            }
        }
 public void SetUp()
 {
     logger     = Substitute.For <ILogger>();
     attributes = ResponseAttributes.WithJsonDefaults().Build();
 }