Example #1
0
        public void MembershipWithIncludesAndExcludes()
        {
            var m0 = NewMembershipFromSegmentRefs(
                new string[] { "key1", "key2" },
                new string[] { "key2", "key3" }
                );
            // key1 is included; key2 is included and excluded, therefore it's included; key3 is excluded

            var m1 = NewMembershipFromSegmentRefs(
                new string[] { "key2", "key1" },
                new string[] { "key3", "key2" }
                );

            Assert.NotSame(m0, m1);
            TypeBehavior.AssertEqual(m0, m0);

            Assert.True(m0.CheckMembership("key1"));
            Assert.True(m0.CheckMembership("key2"));
            Assert.False(m0.CheckMembership("key3"));
            Assert.Null(m0.CheckMembership("key4"));


            TypeBehavior.AssertNotEqual(m0, NewMembershipFromSegmentRefs(
                                            new string[] { "key1", "key2" }, new string[] { "key2", "key3", "key4" }));
            TypeBehavior.AssertNotEqual(m0, NewMembershipFromSegmentRefs(
                                            new string[] { "key1", "key2", "key3" }, new string[] { "key2", "key3" }));
            TypeBehavior.AssertNotEqual(m0, NewMembershipFromSegmentRefs(new string[] { "key1" }, null));
            TypeBehavior.AssertNotEqual(m0, NewMembershipFromSegmentRefs(null, null));
        }
Example #2
0
        public void EmptyMembership()
        {
            var m0 = NewMembershipFromSegmentRefs(null, null);
            var m1 = NewMembershipFromSegmentRefs(new string[0], null);
            var m2 = NewMembershipFromSegmentRefs(null, new string[0]);

            Assert.Same(m0, m1);
            Assert.Same(m0, m2);
            TypeBehavior.AssertEqual(m0, m1);

            Assert.Null(m0.CheckMembership("arbitrary"));
        }
Example #3
0
 public void EqualsUsesDeepEqualityForArrays()
 {
     TypeBehavior.CheckEqualsAndHashCode(
         () => LdValue.BuildArray().Add("a")
         .Add(LdValue.BuildArray().Add("b").Add("c").Build())
         .Build(),
         () => LdValue.BuildArray().Add("a").Build(),
         () => LdValue.BuildArray().Add("a").Add("b").Add("c").Build(),
         () => LdValue.BuildArray().Add("a")
         .Add(LdValue.BuildArray().Add("b").Add("x").Build())
         .Build()
         );
 }
Example #4
0
 public void TestEqualsAndHashCodeForPrimitives()
 {
     TypeBehavior.CheckEqualsAndHashCode(
         // each value in this list should be unequal to all the other values and equal to itself
         () => LdValue.Null,
         () => LdValue.Of(true),
         () => LdValue.Of(false),
         () => LdValue.Of(1),
         () => LdValue.Of(2),
         () => LdValue.Of("a"),
         () => LdValue.Of("b")
         );
 }
Example #5
0
        public void MembershipWithSingleExcludeOnly()
        {
            var m0 = NewMembershipFromSegmentRefs(null, new string[] { "key1" });
            var m1 = NewMembershipFromSegmentRefs(null, new string[] { "key1" });

            Assert.NotSame(m0, m1);
            TypeBehavior.AssertEqual(m0, m1);

            Assert.False(m0.CheckMembership("key1"));
            Assert.Null(m0.CheckMembership("key2"));

            TypeBehavior.AssertNotEqual(m0, NewMembershipFromSegmentRefs(new string[] { "key1" }, null));
            TypeBehavior.AssertNotEqual(m0, NewMembershipFromSegmentRefs(null, new string[] { "key2" }));
            TypeBehavior.AssertNotEqual(m0, NewMembershipFromSegmentRefs(null, null));
        }
 public void TestEqualityAndHashCode()
 {
     TypeBehavior.CheckEqualsAndHashCode(
         // each value in this list should be unequal to all the other values and equal to itself
         () => EvaluationReason.OffReason,
         () => EvaluationReason.FallthroughReason,
         () => EvaluationReason.FallthroughReason.WithInExperiment(true),
         () => EvaluationReason.RuleMatchReason(0, "rule1"),
         () => EvaluationReason.RuleMatchReason(0, "rule1").WithInExperiment(true),
         () => EvaluationReason.RuleMatchReason(0, "rule1").WithBigSegmentsStatus(BigSegmentsStatus.Stale),
         () => EvaluationReason.RuleMatchReason(1, "rule2"),
         () => EvaluationReason.PrerequisiteFailedReason("a"),
         () => EvaluationReason.PrerequisiteFailedReason("b"),
         () => EvaluationReason.ErrorReason(EvaluationErrorKind.FlagNotFound),
         () => EvaluationReason.ErrorReason(EvaluationErrorKind.Exception)
         );
 }
Example #7
0
        public void MembershipWithMultipleIncludesOnly()
        {
            var m0 = NewMembershipFromSegmentRefs(new string[] { "key1", "key2" }, null);
            var m1 = NewMembershipFromSegmentRefs(new string[] { "key2", "key1" }, null);

            Assert.NotSame(m0, m1);
            TypeBehavior.AssertEqual(m0, m1);

            Assert.True(m0.CheckMembership("key1"));
            Assert.True(m0.CheckMembership("key2"));
            Assert.Null(m0.CheckMembership("key3"));

            TypeBehavior.AssertNotEqual(m0, NewMembershipFromSegmentRefs(
                                            new string[] { "key1", "key2" }, new string[] { "key3" }));
            TypeBehavior.AssertNotEqual(m0, NewMembershipFromSegmentRefs(
                                            new string[] { "key1", "key3" }, null));
            TypeBehavior.AssertNotEqual(m0, NewMembershipFromSegmentRefs(new string[] { "key1" }, null));
            TypeBehavior.AssertNotEqual(m0, NewMembershipFromSegmentRefs(null, null));
        }
Example #8
0
 public void EqualsUsesDeepEqualityForObjects()
 {
     TypeBehavior.CheckEqualsAndHashCode(
         () => LdValue.BuildObject()
         .Add("a", "b")
         .Add("c", LdValue.BuildObject().Add("d", "e").Build())
         .Build(),
         () => LdValue.BuildObject()
         .Add("a", "b")
         .Build(),
         () => LdValue.BuildObject()
         .Add("a", "b")
         .Add("c", LdValue.BuildObject().Add("d", "e").Build())
         .Add("f", "g")
         .Build(),
         () => LdValue.BuildObject()
         .Add("a", "b")
         .Add("c", LdValue.BuildObject().Add("d", "f").Build())
         .Build()
         );
 }
Example #9
0
 public TypeBehaviorBuilder CreateInstancePerTestClass()
 {
     Behavior = new CreateInstancePerTestClass(Construct);
     return this;
 }
Example #10
0
 public TypeBehaviorBuilder CreateInstancePerCase()
 {
     Behavior = new CreateInstancePerCase(Construct);
     return this;
 }
Example #11
0
 public WrapBehavior(TypeBehaviorAction outer, TypeBehavior inner)
 {
     this.outer = outer;
     this.inner = inner;
 }
Example #12
0
 public WrapBehavior(TypeBehaviorAction outer, TypeBehavior inner)
 {
     this.outer = outer;
     this.inner = inner;
 }
Example #13
0
 public TypeBehaviorBuilder Wrap(TypeBehaviorAction outer)
 {
     Behavior = new WrapBehavior(outer, Behavior);
     return(this);
 }
Example #14
0
 public TypeBehaviorBuilder CreateInstancePerTestClass(Func <Type, object> construct)
 {
     Behavior = new CreateInstancePerTestClass(construct);
     return(this);
 }
Example #15
0
 public TypeBehaviorBuilder CreateInstancePerTestClass()
 {
     Behavior = new CreateInstancePerTestClass(Construct);
     return(this);
 }
Example #16
0
 public TypeBehaviorBuilder CreateInstancePerTestClass(Func<Type, object> construct)
 {
     Behavior = new CreateInstancePerTestClass(construct);
     return this;
 }
Example #17
0
 public TypeBehaviorBuilder Wrap(TypeBehaviorAction outer)
 {
     Behavior = new WrapBehavior(outer, Behavior);
     return this;
 }
Example #18
0
 public TypeBehaviorBuilder CreateInstancePerCase()
 {
     Behavior = new CreateInstancePerCase(Lifecycle.Construct);
     return(this);
 }