コード例 #1
0
        public void GetPossibleValues_WithSubsetForEachCondition()
        {
            // arrange
            ConditionFactory    factory    = new ConditionFactory();
            ConditionDictionary conditions = factory.BuildEmpty();

            conditions.Add(ConditionKey.Day, new[] { "1" /*Monday*/, "2" /*Tuesday*/, "17" /*Wednesday*/, "26" /*Friday*/, "28" /*Sunday*/ });
            conditions.Add(ConditionKey.DayOfWeek, new[] { DayOfWeek.Monday.ToString(), DayOfWeek.Thursday.ToString(), DayOfWeek.Saturday.ToString(), DayOfWeek.Sunday.ToString() });
            conditions.Add(ConditionKey.Language, new[] { LocalizedContentManager.LanguageCode.en.ToString(), LocalizedContentManager.LanguageCode.pt.ToString() });
            conditions.Add(ConditionKey.Season, new[] { "Spring", "Fall" });
            conditions.Add(ConditionKey.Weather, new InvariantHashSet {
                Weather.Rain.ToString(), Weather.Sun.ToString()
            });

            // act
            IDictionary <ConditionKey, InvariantHashSet> possibleValues = factory.GetPossibleTokenisableValues(conditions);

            // assert
            this.SortAndCommaDelimit(possibleValues[ConditionKey.Day]).Should().Be("1, 28", $"should match for {ConditionKey.Day}");
            this.SortAndCommaDelimit(possibleValues[ConditionKey.DayOfWeek]).Should().Be($"{DayOfWeek.Monday}, {DayOfWeek.Sunday}", $"should match for {ConditionKey.DayOfWeek}");
            this.SortAndCommaDelimit(possibleValues[ConditionKey.Language]).Should().Be($"{LocalizedContentManager.LanguageCode.en}, {LocalizedContentManager.LanguageCode.pt}", $"should match for {ConditionKey.Language}");
            this.SortAndCommaDelimit(possibleValues[ConditionKey.Season]).Should().Be("Fall, Spring", $"should match for {ConditionKey.Season}");
            this.SortAndCommaDelimit(possibleValues[ConditionKey.Weather]).Should().Be($"{Weather.Rain}, {Weather.Sun}", $"should match for {ConditionKey.Weather}");
        }
コード例 #2
0
        public void CanConditionsOverlap_WhenWeathersDistinct()
        {
            // arrange
            ConditionFactory    factory = new ConditionFactory();
            ConditionDictionary left    = factory.BuildEmpty();
            ConditionDictionary right   = factory.BuildEmpty();

            left.Add(ConditionKey.Weather, new[] { Weather.Rain.ToString(), Weather.Snow.ToString() });
            right.Add(ConditionKey.Weather, new[] { Weather.Storm.ToString(), Weather.Sun.ToString() });

            // act
            bool canOverlap = factory.CanConditionsOverlap(left, right);

            // assert
            canOverlap.Should().BeFalse();
        }
コード例 #3
0
        public void CanConditionsOverlap_WhenDaysAndDaysOfWeekDistinct()
        {
            // arrange
            ConditionFactory    factory = new ConditionFactory();
            ConditionDictionary left    = factory.BuildEmpty();
            ConditionDictionary right   = factory.BuildEmpty();

            left.Add(ConditionKey.Day, new[] { "1", "2" });
            right.Add(ConditionKey.DayOfWeek, new[] { DayOfWeek.Wednesday.ToString(), DayOfWeek.Thursday.ToString() });

            // act
            bool canOverlap = factory.CanConditionsOverlap(left, right);

            // assert
            canOverlap.Should().BeFalse();
        }
コード例 #4
0
        public void CanConditionsOverlap_WhenSeasonsDistinct()
        {
            // arrange
            ConditionFactory    factory = new ConditionFactory();
            ConditionDictionary left    = factory.BuildEmpty();
            ConditionDictionary right   = factory.BuildEmpty();

            left.Add(ConditionKey.Season, new[] { "Spring", "Summer" });
            right.Add(ConditionKey.Season, new[] { "Fall", "Winter" });

            // act
            bool canOverlap = factory.CanConditionsOverlap(left, right);

            // assert
            canOverlap.Should().BeFalse();
        }
コード例 #5
0
        public void CanConditionsOverlap_WhenSeasonsOverlap()
        {
            // arrange
            ConditionFactory    factory = new ConditionFactory();
            ConditionDictionary left    = factory.BuildEmpty();
            ConditionDictionary right   = factory.BuildEmpty();

            left.Add(ConditionKey.Season, new[] { "Spring", "SUMMer" }); // should match case-insensitively
            right.Add(ConditionKey.Season, new[] { "Summer", "Fall" });

            // act
            bool canOverlap = factory.CanConditionsOverlap(left, right);

            // assert
            canOverlap.Should().BeTrue();
        }
コード例 #6
0
        public void GetPossibleValues_WithImpliedConditionsAndRestrictedDaysOfWeek()
        {
            // arrange
            ConditionFactory    factory    = new ConditionFactory();
            ConditionDictionary conditions = factory.BuildEmpty();

            conditions.Add(ConditionKey.DayOfWeek, new[] { DayOfWeek.Tuesday.ToString(), DayOfWeek.Wednesday.ToString() });

            // act
            IDictionary <ConditionKey, InvariantHashSet> possibleValues = factory.GetPossibleTokenisableValues(conditions);

            // assert
            this.SortAndCommaDelimit(possibleValues[ConditionKey.Day]).Should().Be("10, 16, 17, 2, 23, 24, 3, 9", $"should match for {ConditionKey.Day}");
            this.SortAndCommaDelimit(possibleValues[ConditionKey.DayOfWeek]).Should().Be($"{DayOfWeek.Tuesday}, {DayOfWeek.Wednesday}", $"should match for {ConditionKey.DayOfWeek}");
            this.SortAndCommaDelimit(possibleValues[ConditionKey.Language]).Should().Be(this.CommaDelimitedValues[ConditionKey.Language], $"should match for {ConditionKey.Language}");
            this.SortAndCommaDelimit(possibleValues[ConditionKey.Season]).Should().Be(this.CommaDelimitedValues[ConditionKey.Season], $"should match for {ConditionKey.Season}");
            this.SortAndCommaDelimit(possibleValues[ConditionKey.Weather]).Should().Be(this.CommaDelimitedValues[ConditionKey.Weather], $"should match for {ConditionKey.Weather}");
        }