public void GetAnalysisResult_GivenOneEdgeCasePassedWithNoEdgeCaseHintAttribute_ShouldReturnListWithEdgeCaseAndEdgeCaseMessageSetToNull()
        {
            //---------------Set up test pack-------------------
            var playerTestsLevelAnalyser = Substitute.For <IPlayerTestsLevelAnalyser>();
            var analyser = new PlayerTestsEdgeCaseCoverageAnalyser(playerTestsLevelAnalyser);
            var goldenImplementation1     = new GoldenImplementation(new ClassWithShouldFailEdgeCaseTestAttributesWithNoHint().GetType());
            var goldenImplementation2     = new GoldenImplementation(new ClassWithAttributes().GetType());
            var implementationTestResults = CreateImplementationTestResults(goldenImplementation1, CreateTestResult(true));

            implementationTestResults.Add(goldenImplementation2, new ITestResult[] { CreateTestResult(true) });
            playerTestsLevelAnalyser.GetAnalysisResult(implementationTestResults)
            .Returns(new PlayerTestsLevelResult {
                FirstGoldenImplementationPassingAllTests = goldenImplementation1
            });
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var results = analyser.GetAnalysisResult(implementationTestResults);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, results.Count);
            Assert.IsNull(results[0].EdgeCaseMessage);
            Assert.AreEqual(2, results[0].Level);
            Assert.AreEqual(false, results[0].IsCovered);
        }
        public void GetAnalysisResult_GivenPassingTestInNextLevelAndEdgeCaseFailingInPreviousLevel_ShouldReturnListWithEdgeCase()
        {
            //---------------Set up test pack-------------------
            var playerTestsLevelAnalyser = Substitute.For <IPlayerTestsLevelAnalyser>();
            var analyser = new PlayerTestsEdgeCaseCoverageAnalyser(playerTestsLevelAnalyser);
            var goldenImplementation2     = new GoldenImplementation(new ClassWithAttributes().GetType());
            var implementationTestResults = CreateImplementationTestResults(goldenImplementation2, CreateTestResult(true));

            implementationTestResults.Add(new GoldenImplementation(new AnotherClassWithAttributes().GetType()), new ITestResult[] { CreateTestResult(true) });
            implementationTestResults.Add(new GoldenImplementation(new AnotherClassWithShouldFailEdgeCaseTestAttributes().GetType()), new ITestResult[] { CreateTestResult(true) });

            playerTestsLevelAnalyser.GetAnalysisResult(implementationTestResults)
            .Returns(new PlayerTestsLevelResult {
                FirstGoldenImplementationPassingAllTests = goldenImplementation2
            });
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var results = analyser.GetAnalysisResult(implementationTestResults);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("This is a another hint", results[0].EdgeCaseMessage);
            Assert.AreEqual(1, results[0].Level);
            Assert.AreEqual(false, results[0].IsCovered);
        }
        public void Constructor_GivenTypeWithNoShouldFailEdgeCaseTestAttribute_ShouldNotBeIncludedInKataAnnotations()
        {
            //---------------Set up test pack-------------------
            var classWithNoAttribute = new MyClassWithNoAttribute();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var goldenImplementation = new GoldenImplementation(classWithNoAttribute.GetType());

            //---------------Test Result -----------------------
            Assert.AreEqual(0, goldenImplementation.KataAnnotations.Count);
        }
        public void Constructor_GivenTypeWithNoTestStepAttribute_ShouldNotSetStepNumber()
        {
            //---------------Set up test pack-------------------
            var classWithNoTestStepAnnotation = new MyClassWithNoAttribute();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var goldenImplementation = new GoldenImplementation(classWithNoTestStepAnnotation.GetType());

            //---------------Test Result -----------------------
            Assert.AreEqual(0, goldenImplementation.StepNumber);
        }
        public void Constructor_GivenTypeWithAttributes_ShouldBeIncludedInKataAnnotations()
        {
            //---------------Set up test pack-------------------
            var classWithAttribute = new MyClassWithTestStepAttribute();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var goldenImplementation = new GoldenImplementation(classWithAttribute.GetType());
            //---------------Test Result -----------------------
            var kataAnnotations = goldenImplementation.KataAnnotations;

            Assert.AreEqual(3, kataAnnotations.Count);
        }
        public void GetAnalysisResult_WhenNoneOfThePlayersTestArePassing_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            var analyser                  = CreateAnalyser();
            var goldenImplementation      = new GoldenImplementation(new ClassWithAttributes().GetType());
            var testResult                = CreateTestResult(false);
            var implementationTestResults = CreateImplementationTestResults(goldenImplementation, testResult);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var result = analyser.GetAnalysisResult(implementationTestResults);

            //---------------Test Result -----------------------
            Assert.IsNull(result.FirstGoldenImplementationPassingAllTests);
        }
        public void GetAnalysisResult_GivenNoEdgeCases_ShouldReturnEmptyList()
        {
            //---------------Set up test pack-------------------
            var playerTestsLevelAnalyser = Substitute.For <IPlayerTestsLevelAnalyser>();
            var analyser                  = new PlayerTestsEdgeCaseCoverageAnalyser(playerTestsLevelAnalyser);
            var goldenImplementation      = new GoldenImplementation(new ClassWithAttributes().GetType());
            var implementationTestResults = CreateImplementationTestResults(goldenImplementation, CreateTestResult(true));

            playerTestsLevelAnalyser.GetAnalysisResult(implementationTestResults)
            .Returns(new PlayerTestsLevelResult {
                FirstGoldenImplementationPassingAllTests = goldenImplementation
            });
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var results = analyser.GetAnalysisResult(implementationTestResults);

            //---------------Test Result -----------------------
            CollectionAssert.IsEmpty(results);
        }
        public void GetAnalysisResult_GivenPassingTestInCurrentLevelAndEdgeCaseFailingInNextLevel_ShouldReturnEmptyList()
        {
            //---------------Set up test pack-------------------
            var playerTestsLevelAnalyser = Substitute.For <IPlayerTestsLevelAnalyser>();
            var analyser = new PlayerTestsEdgeCaseCoverageAnalyser(playerTestsLevelAnalyser);
            var goldenImplementation2     = new GoldenImplementation(new ClassWithAttributes().GetType());
            var implementationTestResults = CreateImplementationTestResults(goldenImplementation2, CreateTestResult(true));

            implementationTestResults.Add(new GoldenImplementation(new Step3WithAttributes().GetType()), new ITestResult[] { CreateTestResult(false) });
            implementationTestResults.Add(new GoldenImplementation(new Step3WithShouldFailEdgeCaseTestAttributes().GetType()), new ITestResult[] { CreateTestResult(true) });

            playerTestsLevelAnalyser.GetAnalysisResult(implementationTestResults)
            .Returns(new PlayerTestsLevelResult {
                FirstGoldenImplementationPassingAllTests = goldenImplementation2
            });
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var results = analyser.GetAnalysisResult(implementationTestResults);

            //---------------Test Result -----------------------
            CollectionAssert.IsEmpty(results);
        }
        public void GetAnalysisResult_WhenTypeHasShouldFailEdgeCaseTestAttribute_ShouldBeIgnored()
        {
            //---------------Set up test pack-------------------
            var analyser = CreateAnalyser();
            var goldenImplementation1     = new GoldenImplementation(new ClassWithShouldFailEdgeCaseTestAttributes().GetType());
            var goldenImplementation2     = CreateGoldenImplementation();
            var goldenImplementation3     = CreateGoldenImplementation();
            var testResults1              = CreateTestResults(1, 1, true);
            var testResults2              = CreateTestResults(2, 2, true, false);
            var testResults3              = CreateTestResults(3, 1, false);
            var implementationTestResults = new Dictionary <GoldenImplementation, ITestResult[]>
            {
                { goldenImplementation3, testResults3 },
                { goldenImplementation2, testResults2 },
                { goldenImplementation1, testResults1 }
            };
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var result = analyser.GetAnalysisResult(implementationTestResults);

            //---------------Test Result -----------------------
            Assert.IsNull(result.FirstGoldenImplementationPassingAllTests);
        }
        private static Dictionary <GoldenImplementation, ITestResult[]> CreateImplementationTestResults(GoldenImplementation goldenImplementation,
                                                                                                        TestResult testResult)
        {
            var implementationTestResults = new Dictionary <GoldenImplementation, ITestResult[]>
            {
                {
                    goldenImplementation, new ITestResult[]
                    {
                        testResult
                    }
                }
            };

            return(implementationTestResults);
        }
 private static bool HasEdgeCaseFailureAnnotation(GoldenImplementation goldenImplementation)
 {
     return(goldenImplementation.KataAnnotations.OfType <ShouldFailEdgeCaseTestAttribute>().Any());
 }
        private string GetEdgeCaseHint(GoldenImplementation edgeCaseImplementation)
        {
            var edgeCaseHintAttribute = edgeCaseImplementation.KataAnnotations.OfType <EdgeCaseHintAttribute>().FirstOrDefault();

            return(edgeCaseHintAttribute == null ? null : edgeCaseHintAttribute.EdgeCaseHint);
        }