Exemple #1
0
        public void Test_LaunchDarklyService_GetFeatureFlag_ErrorWithNoLogger()
        {
            // Arrange
            var mockLdClient = new Mock <ILdClient>();
            var mockLogger   = new Mock <ITelemetryLogger>();

            mockLdClient.Setup(m =>
                               m.BoolVariationDetail(It.Is <string>(x => x.Equals("Test")), It.IsAny <User>(), It.IsAny <bool>())
                               ).Returns(new EvaluationDetail <bool>(false, 0, new Error(EvaluationErrorKind.EXCEPTION)));
            mockLdClient.Setup(m => m.Initialized()).Returns(true);
            var ldService = new LaunchDarklyService(mockLdClient.Object);

            // Act
            var result = ldService.GetFeatureFlag("Test", false);

            // Assert
            mockLogger.Verify(m =>
                              m.Log(
                                  It.IsAny <LogLevel>(),
                                  It.IsAny <EventId>(),
                                  It.Is <It.IsAnyType>((object x, Type _) => x.ToString().Contains($"Failed to get feature flag. Reason: {EvaluationErrorKind.EXCEPTION}")),
                                  It.IsAny <Exception>(),
                                  (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()
                                  ),
                              Times.Never
                              );
        }
Exemple #2
0
        public void Test_LaunchDarklyService_GetFeatureFlag_NullClientThrowsInvalidOperationException()
        {
            // Arrange
            var ldService = new LaunchDarklyService();

            // Act/Assert
            Assert.Throws <InvalidOperationException>(() => ldService.GetFeatureFlag("A Key", false));
        }
Exemple #3
0
        public void Test_LaunchDarklyService_GetFeatureFlag_KeyArgumentException()
        {
            // Arrange
            var mockLdClient = new Mock <ILdClient>();
            var ldService    = new LaunchDarklyService(mockLdClient.Object);

            mockLdClient.Setup(m => m.Initialized()).Returns(true);

            // Act/Assert
            Assert.Throws <ArgumentException>(() => ldService.GetFeatureFlag(null, false));
        }
Exemple #4
0
        public void Test_LaunchDarklyService_GetFeatureFlag_NotInitialisedClientThrowsInvalidOperationException()
        {
            // Arrange
            var mockLdClient = new Mock <ILdClient>();
            var ldService    = new LaunchDarklyService(mockLdClient.Object);

            mockLdClient.Setup(m => m.Initialized()).Returns(false);

            // Act/Assert
            Assert.Throws <InvalidOperationException>(() => ldService.GetFeatureFlag("A Key", false));
        }
Exemple #5
0
        public void Test_LaunchDarklyService_GetFeatureFlag_ReturnsDefault()
        {
            // Arrange
            var config    = new Configuration().WithOffline(true);
            var ldClient  = new LdClient(config);
            var ldService = new LaunchDarklyService(ldClient, null);

            // Act
            var result = ldService.GetFeatureFlag("Test", false);

            // Assert
            Assert.False(result);
        }
Exemple #6
0
        public void Test_LaunchDarklyService_GetFeatureFlag_ReturnsTrue()
        {
            // Arrange
            var mockLdClient = new Mock <ILdClient>();

            mockLdClient.Setup(m =>
                               m.BoolVariationDetail(It.Is <string>(x => x.Equals("Test")), It.IsAny <User>(), It.IsAny <bool>())
                               ).Returns(new EvaluationDetail <bool>(true, 0, Fallthrough.Instance));
            mockLdClient.Setup(m => m.Initialized()).Returns(true);
            var ldService = new LaunchDarklyService(mockLdClient.Object, null);

            // Act
            var result = ldService.GetFeatureFlag("Test", false);

            // Assert
            Assert.True(result);
        }