Example #1
0
        public void AlphaNumericWithNumericCodesShouldSkipBadCodes()
        {
            Cleanup();
            int attemptCombination = 0;

            try
            {
                var            codeList = new List <string>();
                AttendanceCode code     = null;
                for (int i = 0; i < 676; i++)
                {
                    attemptCombination = i;
                    code = AttendanceCodeService.GetNew(2, 0, 2, true);
                    codeList.Add(code.Code);
                }

                bool hasMatchIsBad = codeList.Where(c => noGood.Any(ng => c.Contains(ng))).Any();

                Assert.False(hasMatchIsBad);
            }
            catch (TimeoutException)
            {
                // If an infinite loop was detected, but we tried at least 616 codes then
                // we'll consider this a pass.
                Assert.True(attemptCombination >= 616);
            }
        }
Example #2
0
        public void TwoAlphaWithFourRandomNumericCodesShouldSkipBadCodes()
        {
            var stopWatch = new System.Diagnostics.Stopwatch();

            stopWatch.Start();

            int attemptCombination = 0;

            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 2500; i++)
            {
                attemptCombination = i;
                code = AttendanceCodeService.GetNew(0, 2, 4, true);
                codeList.Add(code.Code);
            }

            // TODO: Once the combination of codes issue is addressed, this next line should be uncommented
            // and replace the one below it:
            //var matches = codeList.Where( c => AttendanceCodeService.noGood.Any( ng => c.Contains( ng ) ) );
            var matches = codeList.Select(x => x).Intersect(AttendanceCodeService.noGood);

            bool hasMatchIsBad = matches.Any();

            Assert.That.IsFalse(hasMatchIsBad, "bad codes were: " + string.Join(", ", matches));

            stopWatch.Stop();
            System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out));
            System.Diagnostics.Trace.WriteLine(string.Format("Test AlphaOnlyWithNumericOnlyCodesShouldSkipBadCodes took {0} ms.", stopWatch.ElapsedMilliseconds));
        }
Example #3
0
        public void Cleanup()
        {
            using (var rockContext = new RockContext())
            {
                var acService         = new AttendanceCodeService(rockContext);
                var attendanceService = new AttendanceService(rockContext);

                DateTime today       = RockDateTime.Today;
                DateTime tomorrow    = today.AddDays(1);
                var      todaysCodes = acService.Queryable()
                                       .Where(c => c.IssueDateTime >= today && c.IssueDateTime < tomorrow)
                                       .ToList();
                if (todaysCodes.Any())
                {
                    var ids = todaysCodes.Select(c => c.Id).ToList();

                    // get the corresponding attendance records and delete them first.
                    var todayTestAttendance = attendanceService.Queryable().Where(a => ids.Contains(a.AttendanceCodeId.Value));
                    if (todayTestAttendance.Any())
                    {
                        attendanceService.DeleteRange(todayTestAttendance);
                    }
                    acService.DeleteRange(todaysCodes);
                    rockContext.SaveChanges();
                }
            }
            AttendanceCodeService.FlushTodaysCodes();
        }
Example #4
0
        public void AlphaNumericWithNumericCodesShouldSkipBadCodes()
        {
            int attemptCombination = 0;

            try
            {
                var            codeList = new List <string>();
                AttendanceCode code     = null;
                for (int i = 0; i < 600; i++)
                {
                    attemptCombination = i;
                    code = AttendanceCodeService.GetNew(2, 0, 3, true);
                    codeList.Add(code.Code);
                }

                var  matches       = codeList.Where(c => AttendanceCodeService.noGood.Any(ng => c.Contains(ng)));
                bool hasMatchIsBad = matches.Any();

                Assert.IsFalse(hasMatchIsBad, "bad codes were: " + string.Join(", ", matches));
            }
            catch (TimeoutException)
            {
                // If an infinite loop was detected, but we tried at least 600 codes then
                // we'll consider this a pass.
                Assert.IsTrue(attemptCombination >= 600);
            }
        }
Example #5
0
        public void NumericCodeWithLengthOf2ShouldNotGoBeyond99()
        {
            var stopWatch = new System.Diagnostics.Stopwatch();

            stopWatch.Start();

            try
            {
                var            codeList = new List <string>();
                AttendanceCode code     = null;
                for (int i = 0; i < 101; i++)
                {
                    code = AttendanceCodeService.GetNew(0, 0, 2, false);
                    codeList.Add(code.Code);
                }

                // should not be longer than 2 characters
                // This is a known bug in v7.4 and earlier, and possibly fixed via PR #3071
                Assert.That.IsTrue(codeList.Last().Length == 2, "last code was " + codeList.Last().Length + " characters long.");
            }
            catch (TimeoutException)
            {
                // An exception in this case is considered better than hanging (since there is
                // no actual solution).
                Assert.That.IsTrue(true);
            }
            finally
            {
                stopWatch.Stop();
                System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out));
                System.Diagnostics.Trace.WriteLine(string.Format("Test NumericCodeWithLengthOf2ShouldNotGoBeyond99 took {0} ms.", stopWatch.ElapsedMilliseconds));
            }
        }
Example #6
0
        public void RandomNumericCodesShouldNotRepeat()
        {
            var stopWatch = new System.Diagnostics.Stopwatch();

            stopWatch.Start();

            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 998; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 3, true);
                codeList.Add(code.Code);
            }

            var duplicates = codeList.GroupBy(x => x)
                             .Where(group => group.Count() > 1)
                             .Select(group => group.Key);

            Assert.That.IsTrue(duplicates.Count() == 0, "repeated codes: " + string.Join(", ", duplicates));

            stopWatch.Stop();
            System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out));
            System.Diagnostics.Trace.WriteLine(string.Format("Test RandomNumericCodesShouldNotRepeat took {0} ms.", stopWatch.ElapsedMilliseconds));
        }
Example #7
0
        public void RequestingMoreCodesThanPossibleShouldThrowException()
        {
            var            codeList = new List <string>();
            AttendanceCode code     = null;

            // Generate 99 codes (the maximum number of valid codes).
            for (int i = 0; i < 100; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 2, true);
                codeList.Add(code.Code);
            }

            // Now try to generate one more... which should NOT hang but instead, may
            // throw one of two exceptions.
            try
            {
                code = AttendanceCodeService.GetNew(0, 0, 2, true);
            }
            catch (InvalidOperationException)
            {
                Assert.IsTrue(true);
            }
            catch (TimeoutException)
            {
                // An exception in this case is considered better than hanging (since there is
                // no actual solution).
                Assert.IsTrue(true);
            }
        }
Example #8
0
        public void NumericCodeWithLengthOf2ShouldNotGoBeyond99()
        {
            Cleanup();

            try
            {
                var            codeList = new List <string>();
                AttendanceCode code     = null;
                for (int i = 0; i < 101; i++)
                {
                    code = AttendanceCodeService.GetNew(0, 0, 2, false);
                    codeList.Add(code.Code);
                }

                // should not be longer than 4 characters
                // This is a known bug in v7.4 and earlier, and possibly fixed via PR #3071
                Assert.True(codeList.Last().Length == 4);
            }
            catch (TimeoutException)
            {
                // An exception in this case is considered better than hanging (since there is
                // no actual solution).
                Assert.True(true);
            }
        }
Example #9
0
        public void AlphaOnlyCodesShouldNotRepeat()
        {
            var stopWatch = new System.Diagnostics.Stopwatch();

            stopWatch.Start();

            var            codeList = new List <string>();
            AttendanceCode code     = null;

            // 4847 (17*17*17 minus ~50 bad codes) possible combinations of 17 letters
            for (int i = 0; i < 4860; i++)
            {
                //System.Diagnostics.Debug.WriteIf( i > 4700, "code number " + i + " took... " );
                code = AttendanceCodeService.GetNew(0, 3, 0, false);
                codeList.Add(code.Code);
                //System.Diagnostics.Debug.WriteLineIf( i > 4700, "" );
            }

            var duplicates = codeList.GroupBy(x => x)
                             .Where(group => group.Count() > 1)
                             .Select(group => group.Key);

            Assert.That.IsTrue(duplicates.Count() == 0);

            stopWatch.Stop();
            System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out));
            System.Diagnostics.Trace.WriteLine(string.Format("Test AlphaOnlyCodesShouldNotRepeat took {0} ms.", stopWatch.ElapsedMilliseconds));
        }
        public void AlphaNumericWith1NumericCodeShouldGenerateAtLeast5100Codes()
        {
            int attemptCombination = 0;
            var stopWatch          = new System.Diagnostics.Stopwatch();
            var stopWatchSingle    = new System.Diagnostics.Stopwatch();

            stopWatch.Start();
            stopWatchSingle.Start();
            var outputDebug = false;

            try
            {
                var            codeList = new List <string>();
                AttendanceCode code     = null;
                for (int i = 1; i < 5100; i++)
                {
                    attemptCombination = i;
                    if (i > 4000 && i % 100 == 0)
                    {
                        outputDebug = true;
                        stopWatchSingle.Restart();
                        System.Diagnostics.Debug.Write("code number " + i + " took... ");
                    }
                    code = AttendanceCodeService.GetNew(2, 0, 1, true);
                    if (outputDebug)
                    {
                        System.Diagnostics.Debug.WriteLine(stopWatchSingle.ElapsedMilliseconds + " ms");
                        outputDebug = false;
                    }
                    codeList.Add(code.Code);
                }

                var  matches       = codeList.Where(c => AttendanceCodeService.NoGood.Any(ng => c.Contains(ng)));
                bool hasMatchIsBad = matches.Any();

                Assert.That.IsFalse(hasMatchIsBad, "bad codes were: " + string.Join(", ", matches));

                var duplicates = codeList.GroupBy(x => x)
                                 .Where(group => group.Count() > 1)
                                 .Select(group => group.Key);

                Assert.That.True(duplicates.Count() == 0);
            }
            catch (TimeoutException)
            {
                // If an infinite loop was detected, but we tried at least 5100 codes then
                // we'll consider this a pass.
                Assert.That.IsTrue(attemptCombination >= 5100);
            }
            finally
            {
                stopWatch.Stop();
                System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out));
                System.Diagnostics.Trace.WriteLine(string.Format("Test AlphaNumericWith1NumericCodeShouldGenerateAtLeast5100Codes took {0} ms.", stopWatch.ElapsedMilliseconds));
            }
        }
Example #11
0
        public void CheckThreeChar002Code()
        {
            AttendanceCode code = null;

            for (int i = 0; i < 2; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 3, false);
            }

            Assert.AreEqual("002", code.Code);
        }
        public void CheckThreeCharNumericNonRandom002Code()
        {
            AttendanceCode code = null;

            for (int i = 0; i < 2; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 3, false);
            }

            Assert.That.Equal("002", code.Code);
        }
        public void Increment100SequentialNumericCodes()
        {
            AttendanceCode code = null;

            for (int i = 0; i < 100; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 3, false);
            }

            Assert.That.Equal("100", code.Code);
        }
        public void EnsureGetNextNumericCodeAsStringReturnsGoodCodesTest2()
        {
            int    alphaNumericLength = 0;
            int    alphaLength        = 2;
            int    numericLength      = 4;
            bool   isRandomized       = false;
            string lastCode           = "AN6665";

            var generatedCode = AttendanceCodeService.GetNextNumericCodeAsString(alphaNumericLength, alphaLength, numericLength, isRandomized, lastCode);

            Assert.AreEqual("6670", generatedCode);
        }
Example #15
0
        public void AvoidTripleSix()
        {
            int    alphaNumericLength = 0;
            int    alphaLength        = 0;
            int    numericLength      = 4;
            bool   isRandomized       = false;
            string lastCode           = "0665";

            string code = AttendanceCodeService.GetNextNumericCodeAsString(alphaNumericLength, alphaLength, numericLength, isRandomized, lastCode);

            Assert.Equal("0667", code);
        }
        public void NumericCodesShouldSkip911And666()
        {
            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 2000; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 4, false);
                codeList.Add(code.Code);
            }

            Assert.That.DoesNotContain(codeList, "911");
            Assert.That.DoesNotContain(codeList, "666");
        }
Example #17
0
        public void NumericCodesShouldNotContain911And666()
        {
            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 2000; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 4, false);
                codeList.Add(code.Code);
            }

            Assert.IsFalse(codeList.Any(s => s.Contains("911")));
            Assert.IsFalse(codeList.Any(s => s.Contains("666")));
        }
Example #18
0
        public void AlphaOnlyCodesShouldSkipBadCodes()
        {
            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 1000; i++)
            {
                code = AttendanceCodeService.GetNew(0, 3, 0, true);
                codeList.Add(code.Code);
            }

            bool hasMatchIsBad = codeList.Where(c => AttendanceCodeService.noGood.Any(ng => c.Contains(ng))).Any();

            Assert.That.IsFalse(hasMatchIsBad);
        }
        public void ThreeCharAlphaWithFourCharNumericCodesShouldSkipBadCodes()
        {
            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 6000; i++)
            {
                code = AttendanceCodeService.GetNew(0, 3, 4, true);
                codeList.Add(code.Code);
            }

            bool hasMatchIsBad = codeList.Where(c => AttendanceCodeService.NoGood.Any(ng => c.Contains(ng))).Any();

            Assert.That.False(hasMatchIsBad);
        }
Example #20
0
        public void AlphaOnlyWithNumericOnlyCodesShouldSkipBadCodes()
        {
            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 6000; i++)
            {
                code = AttendanceCodeService.GetNew(0, 1, 4, true);
                codeList.Add(code.Code);
            }

            var  matches       = codeList.Where(c => AttendanceCodeService.noGood.Any(ng => c.Contains(ng)));
            bool hasMatchIsBad = matches.Any();

            Assert.IsFalse(hasMatchIsBad, "bad codes were: " + string.Join(", ", matches));
        }
Example #21
0
        public void AlphaNumericCodesShouldNeverContain911And666()
        {
            Cleanup();

            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 10000; i++)
            {
                code = AttendanceCodeService.GetNew(3, 0, 2, false);
                codeList.Add(code.Code);
            }

            Assert.False(codeList.Any(s => "911".Contains(s)));
            Assert.False(codeList.Any(s => "666".Contains(s)));
        }
Example #22
0
        public void RandomNumericCodesShouldNotRepeat()
        {
            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 998; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 3, true);
                codeList.Add(code.Code);
            }

            var duplicates = codeList.GroupBy(x => x)
                             .Where(group => group.Count() > 1)
                             .Select(group => group.Key);

            Assert.IsTrue(duplicates.Count() == 0, "repeated codes: " + string.Join(", ", duplicates));
        }
Example #23
0
        public void NumericCodeWithLengthOf2ShouldNotGoBeyond99()
        {
            Cleanup();

            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 101; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 2, false);
                codeList.Add(code.Code);
            }

            // should not be longer than 4 characters
            // This is a known bug in v7.4 and earlier, and possibly fixed via PR #3071
            Assert.True(codeList.Last().Length == 4);
        }
Example #24
0
        public void AlphaNumericCodesShouldSkipBadCodes()
        {
            Cleanup();

            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 6000; i++)
            {
                code = AttendanceCodeService.GetNew(3, 0, 0, false);
                codeList.Add(code.Code);
            }

            bool hasMatchIsBad = codeList.Where(c => noGood.Any(ng => c.Contains(ng))).Any();

            Assert.False(hasMatchIsBad);
        }
        public void RandomNumericCodesShouldNotRepeat()
        {
            int            maxThreeDigitCodes = 997;
            var            codeList           = new List <string>();
            AttendanceCode code = null;

            for (int i = 1; i < maxThreeDigitCodes; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 3, true);
                codeList.Add(code.Code);
            }

            var duplicates = codeList.GroupBy(x => x)
                             .Where(group => group.Count() > 1)
                             .Select(group => group.Key);

            Assert.That.True(duplicates.Count() == 0);
        }
Example #26
0
        public void CheckThreeChar002Code()
        {
            var stopWatch = new System.Diagnostics.Stopwatch();

            stopWatch.Start();

            AttendanceCode code = null;

            for (int i = 0; i < 2; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 3, false);
            }

            Assert.That.AreEqual("002", code.Code);

            stopWatch.Stop();
            System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out));
            System.Diagnostics.Trace.WriteLine(string.Format("Test CheckThreeChar002Code took {0} ms.", stopWatch.ElapsedMilliseconds));
        }
Example #27
0
        public void AlphaNumericCodesShouldSkipBadCodes()
        {
            Cleanup();

            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 6000; i++)
            {
                code = AttendanceCodeService.GetNew(3, 0, 0, false);
                codeList.Add(code.Code);
            }

            bool hasMatchIsBad = codeList.Select(x => x)
                                 .Intersect(noGood)
                                 .Any();

            Assert.False(hasMatchIsBad);
        }
Example #28
0
        /// <summary>
        /// Deletes the test data added to the database for each tests.
        /// </summary>
        private void Cleanup()
        {
            using (var rockContext = new RockContext())
            {
                var service = new AttendanceCodeService(rockContext);

                DateTime today       = RockDateTime.Today;
                DateTime tomorrow    = today.AddDays(1);
                var      todaysCodes = service.Queryable()
                                       .Where(c => c.IssueDateTime >= today && c.IssueDateTime < tomorrow)
                                       .ToList();
                if (todaysCodes.Any())
                {
                    service.DeleteRange(todaysCodes);
                    rockContext.SaveChanges();
                }
            }
            AttendanceCodeService.FlushTodaysCodes();
        }
Example #29
0
        public void NumericCodesShouldNotRepeat()
        {
            Cleanup();

            var            codeList = new List <string>();
            AttendanceCode code     = null;

            for (int i = 0; i < 999; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 3, false);
                codeList.Add(code.Code);
            }

            var duplicates = codeList.GroupBy(x => x)
                             .Where(group => group.Count() > 1)
                             .Select(group => group.Key);

            Assert.True(duplicates.Count() == 0);
        }
Example #30
0
        public void Increment100SequentialNumericCodes()
        {
            var stopWatch = new System.Diagnostics.Stopwatch();

            stopWatch.Start();

            AttendanceCode code = null;

            for (int i = 0; i < 100; i++)
            {
                code = AttendanceCodeService.GetNew(0, 0, 3, false);
            }

            Assert.That.AreEqual("100", code.Code);

            stopWatch.Stop();
            System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out));
            System.Diagnostics.Trace.WriteLine(string.Format("Test Increment100SequentialNumericCodes took {0} ms.", stopWatch.ElapsedMilliseconds));
        }