示例#1
0
        public static SeatStatus Classify(EttCode code)
        {
            if (code.BaseTypeHex == "00")
            {
                return(SeatStatus.AvailableForPurchase);
            }

            if (code.BaseTypeHex == "1E")
            {
                return(SeatStatus.HeldByTicketMasterApplication);
            }

            if (IsKnownBorteSvinCode(code))
            {
                return(SeatStatus.Bortesvin);
            }

            if (IsKnownSeasonTicketCode(code))
            {
                return(SeatStatus.SeasonTicket);
            }

            if (IsKnownSoldCode(code))
            {
                return(SeatStatus.Sold);
            }

            return(ClassifyByRange(code));
        }
            public void GetMatchingRule_WhenMatchingRuleExists_ReturnsCorrectRule()
            {
                // Arrange
                var sut = new SeatClassificationEngine();

                sut.AddRule(new SeatClassificationRule
                {
                    RuleName = "Test",
                    Field    = ClassificationRuleField.BaseType,
                    Operator = "Equals",
                    Value    = "1",
                    Status   = SeatStatus.Sold
                }, false);
                var wantedRule = new SeatClassificationRule
                {
                    RuleName = "Test 2",
                    Field    = ClassificationRuleField.BaseType,
                    Operator = "Equals",
                    Value    = "0",
                    Status   = SeatStatus.Unknown
                };

                sut.AddRule(wantedRule, false);
                var code = new EttCode("000004130000");

                // Act
                var res = sut.GetMatchingRule(code);

                // Assert
                res.Should().BeSameAs(wantedRule, "this is the rule that should match");
            }
示例#3
0
        public static bool IsKnownSoldCode(EttCode code)
        {
            var juba = code.JubaFlags;

            return(juba == 12 || juba == 8);

            // Pre-juba

            /*
             *
             * if (code.QualifierBitsHex == "414")
             *  return true;
             * if (code.QualifierBitsHex == "5C2") // Solgt basert på antagelser fra vegardj
             *  return true;
             * if (code.QualifierBitsHex == "409") // Solgt - Vennebillett? Ihvertfall solgt.
             *  return true;
             *
             * if (code.QualifierBitsHex == "406") // Solgt bortesupporter?
             *  return true;
             * if (code.QualifierBitsHex == "41C") // Solgt bortesupporter?
             *  return true;
             *
             * if (code.QualifierBitsHex == "401") // Solgt (vegardj)?
             *  return true;
             * if (code.QualifierBitsHex == "417") // Solgt (vegardj)?
             *  return true;
             *
             * return false;
             */
        }
示例#4
0
        public static bool IsKnownBorteSvinCode(EttCode code)
        {
            // 4060001,4230001,4240001,46a0001
            if (code.QualifierBitsHex == "406")
            {
                return(true);
            }
            if (code.QualifierBitsHex == "423")
            {
                return(true);
            }
            if (code.QualifierBitsHex == "424")
            {
                return(true);
            }
            if (code.QualifierBitsHex == "46A")
            {
                return(true);
            }
            if (code.QualifierBitsHex == "465")
            {
                return(true);
            }

            return(false);
        }
示例#5
0
        public static bool IsKnownSoldCode(EttCode code)
        {
            if (code.QualifierBitsHex == "414")
            {
                return(true);
            }
            if (code.QualifierBitsHex == "5C2") // Solgt basert på antagelser fra vegardj
            {
                return(true);
            }
            if (code.QualifierBitsHex == "409") // Solgt - Vennebillett? Ihvertfall solgt.
            {
                return(true);
            }

            if (code.QualifierBitsHex == "406") // Solgt bortesupporter?
            {
                return(true);
            }
            if (code.QualifierBitsHex == "41C") // Solgt bortesupporter?
            {
                return(true);
            }

            if (code.QualifierBitsHex == "401") // Solgt (vegardj)?
            {
                return(true);
            }
            if (code.QualifierBitsHex == "417") // Solgt (vegardj)?
            {
                return(true);
            }

            return(false);
        }
示例#6
0
        public static bool IsKnownSeasonTicketCode(EttCode code)
        {
            var knownSeasonCodes = new List <string>
            {
                // Liste hentet ut ved å finne koder 0x400 - 0x600 fra to siste kamper 2015 før de er lagt ut for salg
                "4C7",  // Sesongkort gull voksen (jubajuba m.fl.)
                "596",
                "4CF",  // Sesongkort - Kjernen?
                "4C8",  // Sesongkort voksen "svart" (FA) kontant (RoarO)
                "5C2",
                "4CD",  // Sesongkort familierabatt (hoboj0e)
                "4CB",  // Sesongkort studentrabatt normal betaling (Kjello)
                "4CE",
                "4C9",  // Sesongkort hvit voksen
                "590",
                "4CC",  // Sesongkort hvit honnør/barn/student
                "5C8",
                "5C3",
                "4CA",  // Sesongkort gull honnør/barn/student
                "501",
                "592",
                "591",  // Sponsor-sesongkort o.l.
                "4FA",
                "4FB",  // Sesongkort "svart" (Brego)
                "500",
                "4FF",
                "4D0",
                "52C",
                "595",
                "4FD",  // Sesongkort studentrabatt avtalegiro (Kjello)
                "4FC",  // Sesongkort (vegardj)
                "502",
                "4FE",
                "593",
                "5C4",
                "5CC",
                "4F9",

                // Test i forbindelse med seriestart 2016
                "5FD",
                "5FB",
                "5FA",
                "5F4",
                "5F5",
                "5F8",
                "46C",
                "5F6",
                "40E",
                "5F9",
                "5F7",
                "5FC"
                // Slutt på seriestart-test
            };

            return(knownSeasonCodes.Contains(code.QualifierBitsHex));

            //if (code.QualifierBitsHex == "413") // hoboj0e sesongkort familierabatt 1
            //    return true;
        }
示例#7
0
        public void Constructor_WhenGivenEmptyInput_ThrowsArgumentException()
        {
            // Arrange
            EttCode code;

            // Act
            Assert.Throws <ArgumentException>(() => code = new EttCode(String.Empty));

            // Assert
        }
示例#8
0
        public void Constructor_GivenGoodValue_DoesNotThrow()
        {
            // Arrange

            // Act
            var sut = new EttCode("000004C70001");

            // Assert
            sut.Should().NotBeNull("because that would be bad");
        }
示例#9
0
        public void Constructor_WhenGivenNullInput_ThrowsArgumentException()
        {
            // Arrange
            EttCode code;

            // Act
            Assert.Throws <ArgumentException>(() => code = new EttCode(null));

            // Assert
        }
示例#10
0
        public void Code_WhenGivenTypicalEttCode_ReturnsExpectedValue()
        {
            // Arrange
            const string ettCode = "000004C70001";
            var          sut     = new EttCode(ettCode);

            // Act
            var res = sut.Code;

            // Assert
            res.Should().Be(ettCode, "it should match the original input");
        }
示例#11
0
        public void QualifierBitsHex_WhenGivenTypicalEttCode_ReturnsExpectedValue()
        {
            // Arrange
            const string ettCode = "000004C70001";
            var          sut     = new EttCode(ettCode);

            // Act
            var res = sut.QualifierBitsHex;

            // Assert
            res.Should().Be("4C7", "those are the qualifier bits of the ETT code");
        }
示例#12
0
        public void SeatFlagsHex_WhenGivenTypicalEttCode_ReturnsExpectedValue()
        {
            // Arrange
            const string ettCode = "000004C70001";
            var          sut     = new EttCode(ettCode);

            // Act
            var res = sut.SeatFlagsHex;

            // Assert
            res.Should().Be("00", "those are the seat flags of the ETT code");
        }
示例#13
0
        public void BaseTypeHex_WhenGivenTypicalEttCode_ReturnsExpectedValue()
        {
            // Arrange
            const string ettCode = "000004C70001";
            var          sut     = new EttCode(ettCode);

            // Act
            var res = sut.BaseTypeHex;

            // Assert
            res.Should().Be("01", "that is the base type of the ETT code");
        }
示例#14
0
        public SeatClassificationRule GetMatchingRule(EttCode code)
        {
            if (_cache.ContainsKey(code.Code))
            {
                return(_cache[code.Code]);
            }

            var matchingRule = AllRules.FirstOrDefault(r => r.IsMatch(code));

            if (matchingRule != null)
            {
                _cache.Add(code.Code, matchingRule);
            }

            return(matchingRule);
        }
示例#15
0
            public void IsMatch_WhenRuleIsMatch_ReturnsTrue()
            {
                // Arrange
                var sut = new SeatClassificationRule
                {
                    RuleName = "Test rule",
                    Field    = ClassificationRuleField.BaseType,
                    Operator = "Equals",
                    Value    = "1"
                };

                var code = new EttCode("000004130001");

                // Act
                var res = sut.IsMatch(code);

                // Assert
                res.Should().BeTrue("BaseType equals 1 in this case");
            }
示例#16
0
        /// <summary>
        /// Checks to see if the provided EttCode object matches this SeatClassificationRule
        /// </summary>
        /// <param name="code">The EttCode object to test</param>
        /// <returns>True if the EttCode matches, False otherwise</returns>
        public bool IsMatch(EttCode code)
        {
            if (code == null)
            {
                return(false);
            }

            if (_operator == null)
            {
                SetupOperator();
            }
            if (_operator == null)
            {
                return(false);
            }

            var codeValue = ExtractDesiredValueFromCode(code);

            return(_operator.OperatorIsMatch(codeValue));
        }
            public void Classify_WhenMatchingRuleExists_ClassifiesCorrectly()
            {
                // Arrange
                var sut = new SeatClassificationEngine();

                sut.AddRule(new SeatClassificationRule
                {
                    RuleName = "Test",
                    Field    = ClassificationRuleField.BaseType,
                    Operator = "Equals",
                    Value    = "1",
                    Status   = SeatStatus.Sold
                }, false);
                var code = new EttCode("000004130001");

                // Act
                var res = sut.Classify(code);

                // Assert
                res.Should().Be(SeatStatus.Sold, "the rule should match");
            }
示例#18
0
        public static SeatStatus ClassifyByRange(EttCode code)
        {
            if (code.QualifierBits > 0x0 && code.QualifierBits < 0x30)
            {
                return(SeatStatus.Reserved);
            }

            if (code.QualifierBits > 0x400 && code.QualifierBits < 0x600)
            {
                return(SeatStatus.Sold);
            }

            //if(code.QualifierBits >= 0x464 && code.QualifierBits < 0x600)
            //    return SeatStatus.SeasonTicket;

            if (code.QualifierBits > 0x800)
            {
                return(SeatStatus.Unknown);
            }

            return(SeatStatus.Unknown);
        }
示例#19
0
        private int ExtractDesiredValueFromCode(EttCode code)
        {
            switch (Field)
            {
            case ClassificationRuleField.BaseType:
                return(code.BaseType);

            case ClassificationRuleField.Code:
                return(code.CodeValue);

            case ClassificationRuleField.SeatFlags:
                return(code.SeatFlags);

            case ClassificationRuleField.QualifierBits:
                return(code.QualifierBits);

            case ClassificationRuleField.JubaFlags:
                return(code.JubaFlags);

            default:
                return(code.CodeValue);
            }
        }
示例#20
0
 public SeatSummary(string ettCode, int count)
 {
     EttCode = new EttCode(ettCode);
     Count   = count;
 }
示例#21
0
        /// <summary>
        /// Classifies a single EttCode using the defined ruleset
        /// </summary>
        /// <param name="code">The EttCode to classify</param>
        /// <returns>A SeatStatus for the match, or SeatStatus.Unknown in the case of no rules matching</returns>
        public SeatStatus Classify(EttCode code)
        {
            var match = GetMatchingRule(code);

            return(match?.Status ?? SeatStatus.Unknown);
        }