Exemple #1
0
        public void ParseAndSum_EmptyString_ReturnsZero()
        {
            //Arrange
            SimpleParser sp = new SimpleParser();

            //Act
            int sum = sp.ParseAndSum("");

            //Assert
            Assert.Equal(0, sum);
        }
Exemple #2
0
        public void ParseAndSum_TwoValues_ReturnsSum()
        {
            //Arrange
            SimpleParser sp = new SimpleParser();

            //Act
            int sum = sp.ParseAndSum("10,2");

            //Assert
            Assert.Equal(12, sum);
        }
Exemple #3
0
        //https://www.richard-banks.org/2015/07/stop-using-assertthrows-in-your-bdd.html
        public async void ParseAndSum_InvalidSeparator_InvalidOperationException()
        {
            //Arrange
            SimpleParser sp = new SimpleParser();

            //Act
            int i;
            var exception = await Record.ExceptionAsync(() => i = sp.ParseAndSum("10:2"));

            //Assert
            Assert.NotNull(exception);
            Assert.IsType <InvalidOperationException>(exception);
        }
 public static void TestReturnsZeroWhenEmptyString()
 {
     try
     {
         SimpleParser p      = new SimpleParser();
         int          result = p.ParseAndSum(string.Empty);
         if (result != 0)
         {
             Console.WriteLine(@"SimplePArserTests.TestReturnsZeroWhenEmptyString: ParseAndSum은 빈 문자열에 대해 0을 반환해야한다.");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
        public static void TestReturnsZeroWhenEmptyString()
        {
            //use reflection to get the current method's name
            string testName = MethodBase.GetCurrentMethod().Name;

            try
            {
                SimpleParser p      = new SimpleParser();
                int          result = p.ParseAndSum("1");
                if (result != 0)
                {
                    TestUtil.ShowProblem(testName, "Parse and sum should have returned 0 on an empty string");
                }
            }
            catch (Exception e)
            {
                TestUtil.ShowProblem(testName, e.ToString());
            }
        }
Exemple #6
0
 public static void TestReturnsZeroWhenEmptyString()
 {
     try
     {
         SimpleParser p      = new SimpleParser();
         int          result = p.ParseAndSum(string.Empty);
         if (result != 0)
         {
             Console.WriteLine(
                 @"***SimpleParserTests.TestReturnsZeroWhenEmptyString: 
                 -------
                 Parse and sum should have returned 0 on an empty string");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Exemple #7
0
        public static void TestReturnsZeroWhenEmptyString()
        {
            // 현재 메서드의 이름을 얻기위해 리플렉션 API사용.
            string testName = MethodBase.GetCurrentMethod().Name;

            try
            {
                SimpleParser p      = new SimpleParser();
                int          result = p.ParseAndSum(string.Empty);
                if (result != 0)
                {
                    Console.WriteLine(@"SimplePArserTests.TestReturnsZeroWhenEmptyString: ParseAndSum은 빈 문자열에 대해 0을 반환해야한다.");
                }
            }
            catch (Exception e)
            {
                TestUtil.ShowProblem(testName, e.ToString());
            }
        }
        public static void TestReturnsZeroWhenEmptyString()
        {
            string testName = MethodBase.GetCurrentMethod().Name;

            try
            {
                SimpleParser p      = new SimpleParser();
                int          result = p.ParseAndSum(string.Empty);
                if (result != 0)
                {
                    TestUtility.ShowProblem(testName, "FAILED: Parse and sum should have returned 0 on an empty string");
                }
                else
                {
                    TestUtility.ShowProblem(testName, "PASSED");
                }
            }
            catch (Exception e)
            {
                TestUtility.ShowProblem(testName, string.Format("FAILED: {0}", e.ToString()));
            }
        }
        public static void TestReturnsSumWhenStringContainsMoreThanOneNumber()
        {
            string testName = MethodBase.GetCurrentMethod().Name;

            try
            {
                SimpleParser p       = new SimpleParser();
                string       numbers = "5,10,15,20,25,30,40";
                int          result  = p.ParseAndSum(numbers);
                if (result == 145)
                {
                    TestUtility.ShowProblem(testName, "PASSED");
                }
                else
                {
                    TestUtility.ShowProblem(testName, "FAILED: Parse and sum should have returned the correct summation");
                }
            }
            catch (Exception e)
            {
                TestUtility.ShowProblem(testName, string.Format("FAILED: {0}", e.ToString()));
            }
        }
        public static void TestReturnsNumberWhenStringContainsOneNumber()
        {
            string testName = MethodBase.GetCurrentMethod().Name;

            try
            {
                SimpleParser p       = new SimpleParser();
                string       numbers = "324";
                int          result  = p.ParseAndSum(numbers);
                if (result == Convert.ToInt32(numbers))
                {
                    TestUtility.ShowProblem(testName, "PASSED");
                }
                else
                {
                    TestUtility.ShowProblem(testName, "FAILED: Parse and sum should have returned a single number.");
                }
            }
            catch (Exception e)
            {
                TestUtility.ShowProblem(testName, string.Format("FAILED: {0}", e.ToString()));
            }
        }
Exemple #11
0
        public static void TestReturnsZeroWhenEmptyString()
        {
            //wykorzystanie API refleksji frameworka .NET
            // do uzyskania bieżącej nazwy metody
            // można by ją zakodować na sztywno,
            //ale posługiwanie się refleksjami jest użyteczną techniką, którą warto znać
            string testName = MethodBase.GetCurrentMethod().Name;

            try
            {
                SimpleParser p      = new SimpleParser();
                int          result = p.ParseAndSum("1");
                if (result != 0)
                {
                    // Wywołanie metody pomocniczej
                    TestUtil.ShowProblem(testName,
                                         "Metoda ParseAndSum powinna zwrócić 0 w przypadku przekazania pustego ciągu znaków");
                }
            }
            catch (Exception e)
            {
                TestUtil.ShowProblem(testName, e.ToString());
            }
        }