public void ConstructorInitializesDeviceId()
        {
            // given, when
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // then
            Assert.That(target.DeviceId, Is.EqualTo(DeviceId));
        }
        public void ApplicationVersionUsesDefaultIfNotSet()
        {
            // given, when
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // then
            Assert.That(target.ApplicationVersion, Is.EqualTo(OpenKitConstants.DefaultApplicationVersion));
        }
        public void ConstructorInitializesNumericDeviceIdString()
        {
            // given
            const long deviceId = 42;
            var        target   = new StubOpenKitBuilder(EndpointUrl, deviceId.ToString());

            // when, then
            Assert.That(target.DeviceId, Is.EqualTo(deviceId));
            Assert.That(target.OrigDeviceId, Is.EqualTo(deviceId.ToString()));
        }
        public void ConstructorTrimsDeviceIdString()
        {
            // given
            const string deviceIdString = " 42 ";
            var          target         = new StubOpenKitBuilder(EndpointUrl, deviceIdString);

            // when, then
            Assert.That(target.DeviceId, Is.EqualTo(42L));
            Assert.That(target.OrigDeviceId, Is.EqualTo(deviceIdString));
        }
        public void ApplicationVersionCanBeChanged()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithApplicationVersion(ApplicationVersion);

            // then
            Assert.That(target.ApplicationVersion, Is.EqualTo(ApplicationVersion));
        }
        public void BeaconCacheMaxRecordAgeReturnsADefaultValue()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            var obtained = target.BeaconCacheMaxBeaconAge;

            // then
            Assert.That(obtained, Is.EqualTo(ConfigurationDefaults.DefaultMaxRecordAgeInMillis));
        }
        public void DefaultCrashReportingLevelIsOptInCrashes()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            var obtained = target.CrashReportingLevel;

            // then
            Assert.That(obtained, Is.EqualTo(CrashReportingLevel.OPT_IN_CRASHES));
        }
        public void LoggerGivesADefaultImplementationIfNoneHasBeenProvided()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            var obtained = target.Logger;

            // then
            Assert.That(obtained, Is.Not.Null.And.InstanceOf <DefaultLogger>());
        }
        public void BeaconCacheUpperMemoryBoundaryReturnsADefaultValue()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            var obtained = target.BeaconCacheUpperMemoryBoundary;

            // then
            Assert.That(obtained, Is.EqualTo(ConfigurationDefaults.DefaultUpperMemoryBoundaryInBytes));
        }
        public void DefaultDataCollectionLevelIsUserBehavior()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            var obtained = target.DataCollectionLevel;

            // then
            Assert.That(obtained, Is.EqualTo(DataCollectionLevel.USER_BEHAVIOR));
        }
        public void HttpResponseInterceptorGivesNullHttpResponseInterceptorByDefault()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            var obtained = target.HttpResponseInterceptor;

            // then
            Assert.That(obtained, Is.Not.Null.And.InstanceOf <NullHttpResponseInterceptor>());
        }
        public void ModelIdReturnsADefaultValue()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            var obtained = target.ModelId;

            // then
            Assert.That(obtained, Is.EqualTo(OpenKitConstants.DefaultModelId));
        }
        public void ModelIdCannotBeChangedToEmptyString()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithModelId(string.Empty);
            var obtained = target.ModelId;

            // then
            Assert.That(obtained, Is.Not.EqualTo(string.Empty));
        }
        public void DataCollectionLevelReturnsChangedDataCollectionLevel()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithDataCollectionLevel(DataCollectionLevel.PERFORMANCE);
            var obtained = target.DataCollectionLevel;

            // then
            Assert.That(obtained, Is.EqualTo(DataCollectionLevel.PERFORMANCE));
        }
        public void TrustManagerGivesStrictTrustManagerByDefault()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            var obtained = target.TrustManager;

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained, Is.InstanceOf <SSLStrictTrustManager>());
        }
        public void OperatingSystemReturnsADefaultValue()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            var obtained = target.OperatingSystem;

            // then
            Assert.That(obtained, Is.Not.Null.And.Not.EqualTo(string.Empty));
            Assert.That(obtained, Is.EqualTo(OpenKitConstants.DefaultOperatingSystem));
        }
        public void BeaconCacheMaxRecordAgeGivesChangedValue()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithBeaconCacheMaxRecordAge(MaxRecordAgeInMillis);
            var obtained = target.BeaconCacheMaxBeaconAge;

            // then
            Assert.That(obtained, Is.EqualTo(MaxRecordAgeInMillis));
        }
        public void CrashReportingLevelReturnsChangedCrashReportingLevel()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithCrashReportingLevel(CrashReportingLevel.OPT_OUT_CRASHES);
            var obtained = target.CrashReportingLevel;

            // then
            Assert.That(obtained, Is.EqualTo(CrashReportingLevel.OPT_OUT_CRASHES));
        }
        public void ModelIdCannotBeChangedToNull()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithModelId(null);
            var obtained = target.ModelId;

            // then
            Assert.That(obtained, Is.Not.Null);
        }
        public void ModelIdGivesChangedModelId()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithModelId(ModelId);
            var obtained = target.ModelId;

            // then
            Assert.That(obtained, Is.EqualTo(ModelId));
        }
        public void ManufacturerGivesChangedManufacturer()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithManufacturer(Manufacturer);
            var obtained = target.Manufacturer;

            // then
            Assert.That(obtained, Is.EqualTo(Manufacturer));
        }
        public void OperatingSystemCannotBeChangedToNull()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithOperatingSystem(null);
            var obtained = target.OperatingSystem;

            // then
            Assert.That(obtained, Is.Not.Null);
        }
        public void OperatingSystemGivesChangedOperatingSystem()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithOperatingSystem(OperatingSystem);
            var obtained = target.OperatingSystem;

            // then
            Assert.That(obtained, Is.EqualTo(OperatingSystem));
        }
        public void BeaconCacheUpperMemoryBoundaryGivesChangedValue()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithBeaconCacheUpperMemoryBoundary(UpperMemoryBoundaryInBytes);
            var obtained = target.BeaconCacheUpperMemoryBoundary;

            // then
            Assert.That(obtained, Is.EqualTo(UpperMemoryBoundaryInBytes));
        }
        public void TrustManagerCannotBeChangedToNull()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithTrustManager(null);
            var obtained = target.TrustManager;

            // then
            Assert.That(obtained, Is.Not.Null.And.InstanceOf <SSLStrictTrustManager>());
        }
        public void ApplicationVersionCannotBeChangedToEmptyString()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithApplicationVersion(string.Empty);

            // then
            Assert.That(target.ApplicationVersion, Is.Not.EqualTo(string.Empty));
            Assert.That(target.ApplicationVersion, Is.EqualTo(OpenKitConstants.DefaultApplicationVersion));
        }
        public void HttpResponseInterceptorCannotBeChangedToNull()
        {
            // given
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithHttpResponseInterceptor(null);
            var obtained = target.HttpResponseInterceptor;

            // then
            Assert.That(obtained, Is.Not.Null.And.InstanceOf <NullHttpResponseInterceptor>());
        }
        public void ConstructorInitializesAndHashesStringDeviceId()
        {
            // given
            const string deviceIdAsString = "stringDeviceID";
            var          target           = new StubOpenKitBuilder(EndpointUrl, deviceIdAsString);

            // when, then
            var hashedDeviceId = StringUtil.To64BitHash(deviceIdAsString);

            Assert.That(target.DeviceId, Is.EqualTo(hashedDeviceId));
            Assert.That(target.OrigDeviceId, Is.EqualTo(deviceIdAsString));
        }
        public void HttpResponseInterceptorGivesPreviouslySetHttpResponseInterceptor()
        {
            // given
            var httpResponseInterceptor = Substitute.For <IHttpResponseInterceptor>();
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithHttpResponseInterceptor(httpResponseInterceptor);
            var obtained = target.HttpResponseInterceptor;

            // then
            Assert.That(obtained, Is.SameAs(httpResponseInterceptor));
        }
        public void LoggerReturnsPreviouslySetLogger()
        {
            // given
            var logger = Substitute.For <ILogger>();
            var target = new StubOpenKitBuilder(EndpointUrl, DeviceId);

            // when
            target.WithLogger(logger);
            var obtained = target.Logger;

            // then
            Assert.That(obtained, Is.SameAs(logger));
        }