コード例 #1
0
        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));
        }
コード例 #2
0
        public void BuildWithKeyValueDefaultsHasNoAttributeSetOnInstance()
        {
            // given
            var target = ResponseAttributes.WithKeyValueDefaults().Build();

            // when, then
            foreach (var attribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                Assert.That(target.IsAttributeSet(attribute), Is.False);
            }
        }
コード例 #3
0
        public void IsErroneousResponseGivesFalseIfStatusResponseAttributeIsNotSet()
        {
            // given
            var attributes = ResponseAttributes.WithUndefinedDefaults().Build();

            var target = StatusResponse.CreateSuccessResponse(
                logger, attributes, StatusResponse.HttpOk, new Dictionary <string, List <string> >());

            // when, then
            Assert.That(target.IsErroneousResponse, Is.False);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        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));
        }
コード例 #13
0
        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));
        }
コード例 #14
0
        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));
        }
コード例 #15
0
        public void MergeTakesMultiplicityFromMergeSourceIfSetInSourceAndTarget()
        {
            // given
            const int multiplicity = 73;
            var       source       = ResponseAttributes.WithUndefinedDefaults().WithMultiplicity(multiplicity).Build();
            var       target       = ResponseAttributes.WithUndefinedDefaults().WithMultiplicity(37).Build();

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

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.Multiplicity, Is.EqualTo(multiplicity));
        }
コード例 #16
0
        public void MergeTakesTimestampFromMergeSourceIfSetInSourceAndTarget()
        {
            // given
            const long timestamp = 73;
            var        source    = ResponseAttributes.WithUndefinedDefaults().WithTimestampInMilliseconds(timestamp).Build();
            var        target    = ResponseAttributes.WithUndefinedDefaults().WithTimestampInMilliseconds(37).Build();

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

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.TimestampInMilliseconds, Is.EqualTo(timestamp));
        }
コード例 #17
0
        public void MergeTakesStatusFromMergeSourceIfSetInSourceAndTarget()
        {
            // given
            const string status = "status";
            var          source = ResponseAttributes.WithUndefinedDefaults().WithStatus(status).Build();
            var          target = ResponseAttributes.WithUndefinedDefaults().WithStatus("foobar").Build();

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

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.Status, Is.EqualTo(status));
        }
コード例 #18
0
        public void MergeTakesServerIdFromMergeSourceIfSetInSourceAndTarget()
        {
            // given
            const int serverId = 73;
            var       source   = ResponseAttributes.WithUndefinedDefaults().WithServerId(serverId).Build();
            var       target   = ResponseAttributes.WithUndefinedDefaults().WithServerId(37).Build();

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

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.ServerId, Is.EqualTo(serverId));
        }
コード例 #19
0
        public void MergeTakesCaptureFromMergeSourceIfSetInSource()
        {
            // given
            var capture = !ResponseAttributesDefaults.Undefined.IsCapture;
            var source  = ResponseAttributes.WithUndefinedDefaults().WithCapture(capture).Build();
            var target  = ResponseAttributes.WithUndefinedDefaults().Build();

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

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.IsCapture, Is.EqualTo(capture));
        }
コード例 #20
0
        public void MergeTakesApplicationIdFromMergeSourceIfSetInSourceAndTarget()
        {
            // given
            var applicationId = Guid.NewGuid().ToString();
            var source        = ResponseAttributes.WithUndefinedDefaults().WithApplicationId(applicationId).Build();
            var target        = ResponseAttributes.WithUndefinedDefaults().WithApplicationId(Guid.NewGuid().ToString()).Build();

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

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.ApplicationId, Is.EqualTo(applicationId));
        }
コード例 #21
0
        public void MergeTakesVisitStoreVersionFromMergeSourceIfSetInSourceAndTarget()
        {
            // given
            const int visitStoreVersion = 73;
            var       source            = ResponseAttributes.WithUndefinedDefaults().WithVisitStoreVersion(visitStoreVersion).Build();
            var       target            = ResponseAttributes.WithUndefinedDefaults().WithVisitStoreVersion(37).Build();

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

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.VisitStoreVersion, Is.EqualTo(visitStoreVersion));
        }
コード例 #22
0
        public void MergeTakesEventsPerSessionFromMergeTargetIfNotSetInSource()
        {
            // given
            const int eventsPerSession = 73;
            var       source           = ResponseAttributes.WithUndefinedDefaults().Build();
            var       target           = ResponseAttributes.WithUndefinedDefaults().WithMaxEventsPerSession(eventsPerSession).Build();

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

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.MaxEventsPerSession, Is.EqualTo(eventsPerSession));
        }
コード例 #23
0
        public void MergeTakesBeaconSizeFromMergeSourceIfSetInSourceAndTarget()
        {
            // given
            const int beaconSize = 73;
            var       source     = ResponseAttributes.WithUndefinedDefaults().WithMaxBeaconSizeInBytes(beaconSize).Build();
            var       target     = ResponseAttributes.WithUndefinedDefaults().WithMaxBeaconSizeInBytes(37).Build();

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

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.MaxBeaconSizeInBytes, Is.EqualTo(beaconSize));
        }
コード例 #24
0
        public void MergeTakesSendIntervalFromMergeSourceIfSetInSource()
        {
            // given
            const int sendInterval = 73;
            var       source       = ResponseAttributes.WithUndefinedDefaults().WithSendIntervalInMilliseconds(sendInterval)
                                     .Build();
            var target = ResponseAttributes.WithUndefinedDefaults().Build();

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

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.SendIntervalInMilliseconds, Is.EqualTo(sendInterval));
        }
コード例 #25
0
        public void MergeTakesSessionTimeoutFromMergeSourceIfSetInSourceAndTarget()
        {
            // given
            const int sessionTimeout = 73;
            var       source         = ResponseAttributes.WithUndefinedDefaults().WithSessionTimeoutInMilliseconds(sessionTimeout)
                                       .Build();
            var target = ResponseAttributes.WithUndefinedDefaults().WithSessionTimeoutInMilliseconds(37).Build();

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

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.SessionTimeoutInMilliseconds, Is.EqualTo(sessionTimeout));
        }
コード例 #26
0
        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);
            }
        }
コード例 #27
0
        public static IResponseAttributes Parse(string keyValuePairResponse)
        {
            var keyValuePairs = ParseKeyValuePairs(keyValuePairResponse);

            var builder = ResponseAttributes.WithKeyValueDefaults();

            ApplyBeaconSizeInKb(builder, keyValuePairs);
            ApplySendIntervalInSec(builder, keyValuePairs);
            ApplyCapture(builder, keyValuePairs);
            ApplyReportCrashes(builder, keyValuePairs);
            ApplyReportErrors(builder, keyValuePairs);
            ApplyServerId(builder, keyValuePairs);
            ApplyMultiplicity(builder, keyValuePairs);

            return(builder.Build());
        }
コード例 #28
0
        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());
        }
コード例 #29
0
        public void MergeResponseWithAllValuesSetToDefaultResponse()
        {
            // given
            var toMerge = Substitute.For <IResponseAttributes>();

            toMerge.IsAttributeSet(Arg.Any <ResponseAttribute>()).Returns(true);
            var target = ResponseAttributes.WithUndefinedDefaults().Build();

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

            // then
            foreach (var attribute in Enum.GetValues(typeof(ResponseAttribute)).Cast <ResponseAttribute>())
            {
                Assert.That(obtained.IsAttributeSet(attribute), Is.True);
            }
        }
コード例 #30
0
        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);
            }
        }