Ejemplo n.º 1
0
 public void CheckAllProductPricesAreCorrect()
 {
     foreach (var product in products)
     {
         Assert.AreEqual(product.Price, CheckoutSolution.ComputePrice(product.Id.ToString()));
     }
 }
Ejemplo n.º 2
0
        public int ShouldApplyPromotions(string skus)
        {
            // When
            var result = CheckoutSolution.ComputePrice(skus);

            // Then
            return(result);
        }
Ejemplo n.º 3
0
        public int ShouldReturnDiscountedValue_IfThereIsASpecialOffer(string skus)
        {
            // When
            var result = CheckoutSolution.ComputePrice(skus);

            // Then
            return(result);
        }
Ejemplo n.º 4
0
        public int ShouldReturnTotalWhenItemsAreAllValid(string skus)
        {
            // When
            var result = CheckoutSolution.ComputePrice(skus);

            // Then
            return(result);
        }
Ejemplo n.º 5
0
        public void ShouldReturnMinus1_WhenAtLeastOneItemIsNotValid(string skus)
        {
            // When
            var result = CheckoutSolution.ComputePrice(skus);

            //Then
            Assert.AreEqual(-1, result);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// ~~~~~~~~~~ Running the system: ~~~~~~~~~~~~~
 ///
 ///   From IDE:
 ///      Configure the "BeFaster.App" solution to Run on External Console then run.
 ///
 ///   From command line:
 ///      msbuild befaster.sln; src\BeFaster.App\bin\Debug\BeFaster.App.exe
 ///
 ///   To run your unit tests locally:
 ///      Run the "BeFaster.App.Tests - Unit Tests" configuration.
 ///
 /// ~~~~~~~~~~ The workflow ~~~~~~~~~~~~~
 ///
 ///   By running this file you interact with a challenge server.
 ///   The interaction follows a request-response pattern:
 ///        * You are presented with your current progress and a list of actions.
 ///        * You trigger one of the actions by typing it on the console.
 ///        * After the action feedback is presented, the execution will stop.
 ///
 ///   +------+-------------------------------------------------------------+
 ///   | Step | The usual workflow                                          |
 ///   +------+-------------------------------------------------------------+
 ///   |  1.  | Run this file.                                              |
 ///   |  2.  | Start a challenge by typing "start".                        |
 ///   |  3.  | Read description from the "challenges" folder               |
 ///   |  4.  | Implement the required method in                            |
 ///   |      |   .\src\BeFaster.App\Solutions                              |
 ///   |  5.  | Deploy to production by typing "deploy".                    |
 ///   |  6.  | Observe output, check for failed requests.                  |
 ///   |  7.  | If passed, go to step 3.                                    |
 ///   +------+-------------------------------------------------------------+
 ///
 /// </summary>
 /// <param name="args">Action.</param>
 private static void Main(string[] args)
 {
     ClientRunner
     .ForUsername(CredentialsConfigFile.Get("tdl_username"))
     .WithServerHostname(CredentialsConfigFile.Get("tdl_hostname"))
     .WithActionIfNoArgs(RunnerAction.TestConnectivity)
     .WithSolutionFor("sum", p => SumSolution.Sum(p[0].AsInt(), p[1].AsInt()))
     .WithSolutionFor("hello", p => HelloSolution.Hello(p[0]))
     .WithSolutionFor("fizz_buzz", p => FizzBuzzSolution.FizzBuzz(p[0].AsInt()))
     .WithSolutionFor("checkout", p => CheckoutSolution.Checkout(p[0]))
     .Start(args);
 }
        /// <summary>
        /// ~~~~~~~~~~ Running the system: ~~~~~~~~~~~~~
        ///
        ///   From IDE:
        ///      Configure the "BeFaster.App" solution to Run on External Console then run.
        ///
        ///   From command line:
        ///      msbuild befaster.sln; src\BeFaster.App\bin\Debug\BeFaster.App.exe
        ///
        ///   To run your unit tests locally:
        ///      Run the "BeFaster.App.Tests - Unit Tests" configuration.
        ///
        /// ~~~~~~~~~~ The workflow ~~~~~~~~~~~~~
        ///
        ///   By running this file you interact with a challenge server.
        ///   The interaction follows a request-response pattern:
        ///        * You are presented with your current progress and a list of actions.
        ///        * You trigger one of the actions by typing it on the console.
        ///        * After the action feedback is presented, the execution will stop.
        ///
        ///   +------+-------------------------------------------------------------+
        ///   | Step | The usual workflow                                          |
        ///   +------+-------------------------------------------------------------+
        ///   |  1.  | Run this file.                                              |
        ///   |  2.  | Start a challenge by typing "start".                        |
        ///   |  3.  | Read description from the "challenges" folder               |
        ///   |  4.  | Implement the required method in                            |
        ///   |      |   .\src\BeFaster.App\Solutions                              |
        ///   |  5.  | Deploy to production by typing "deploy".                    |
        ///   |  6.  | Observe output, check for failed requests.                  |
        ///   |  7.  | If passed, go to step 3.                                    |
        ///   +------+-------------------------------------------------------------+
        ///
        ///   You are encouraged to change this project as you please:
        ///        * You can use your preferred libraries.
        ///        * You can use your own test framework.
        ///        * You can change the file structure.
        ///        * Anything really, provided that this file stays runnable.
        ///
        /// </summary>
        /// <param name="args">Action.</param>
        private static void Main(string[] args)
        {
            var runner = new QueueBasedImplementationRunner.Builder()
                         .SetConfig(Utils.GetRunnerConfig())
                         .WithSolutionFor("sum", p => SumSolution.Sum(p[0].AsInt(), p[1].AsInt()))
                         .WithSolutionFor("hello", p => HelloSolution.Hello(p[0]))
                         .WithSolutionFor("fizz_buzz", p => FizzBuzzSolution.FizzBuzz(p[0].AsInt()))
                         .WithSolutionFor("checkout", p => CheckoutSolution.Checkout(p[0]))
                         .Create();

            ChallengeSession.ForRunner(runner)
            .WithConfig(Utils.GetConfig())
            .WithActionProvider(new UserInputAction(args))
            .Start();

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// ~~~~~~~~~~ Running the system: ~~~~~~~~~~~~~
        ///
        ///   From IDE:
        ///      Configure the "BeFaster.App" solution to Run on External Console then run.
        ///
        ///   From command line:
        ///      msbuild befaster.sln; src\BeFaster.App\bin\Debug\BeFaster.App.exe
        ///        or
        ///      msbuild befaster.sln; mono src/BeFaster.App/bin/Debug/BeFaster.App.exe
        ///
        ///   To run your unit tests locally:
        ///      Run the "BeFaster.App.Tests - Unit Tests" configuration.
        ///
        /// ~~~~~~~~~~ The workflow ~~~~~~~~~~~~~
        ///
        ///   By running this file you interact with a challenge server.
        ///   The interaction follows a request-response pattern:
        ///        * You are presented with your current progress and a list of actions.
        ///        * You trigger one of the actions by typing it on the console.
        ///        * After the action feedback is presented, the execution will stop.
        ///
        ///   +------+-------------------------------------------------------------+
        ///   | Step | The usual workflow                                          |
        ///   +------+-------------------------------------------------------------+
        ///   |  1.  | Run this file.                                              |
        ///   |  2.  | Start a challenge by typing "start".                        |
        ///   |  3.  | Read description from the "challenges" folder               |
        ///   |  4.  | Implement the required method in                            |
        ///   |      |   .\src\BeFaster.App\Solutions                              |
        ///   |  5.  | Deploy to production by typing "deploy".                    |
        ///   |  6.  | Observe output, check for failed requests.                  |
        ///   |  7.  | If passed, go to step 3.                                    |
        ///   +------+-------------------------------------------------------------+
        ///
        ///   You are encouraged to change this project as you please:
        ///        * You can use your preferred libraries.
        ///        * You can use your own test framework.
        ///        * You can change the file structure.
        ///        * Anything really, provided that this file stays runnable.
        ///
        /// </summary>
        /// <param name="args">Action.</param>
        private static void Main(string[] args)
        {
            var runner = new QueueBasedImplementationRunner.Builder().
                         SetConfig(Utils.GetRunnerConfig()).
                         WithSolutionFor("sum", (List <JToken> p) => SumSolution.Sum(p[0].ToObject <int>(), p[1].ToObject <int>())).
                         WithSolutionFor("hello", (List <JToken> p) => HelloSolution.Hello(p[0].ToObject <string>())).
                         WithSolutionFor("array_sum", (List <JToken> p) => ArraySumSolution.Compute((p[0].ToObject <List <int> >()))).
                         WithSolutionFor("int_range", (List <JToken> p) => IntRangeSolution.Generate(p[0].ToObject <int>(), p[1].ToObject <int>())).
                         WithSolutionFor("fizz_buzz", (List <JToken> p) => FizzBuzzSolution.FizzBuzz(p[0].ToObject <int>())).
                         WithSolutionFor("checkout", (List <JToken> p) => CheckoutSolution.Checkout(p[0].ToObject <string>())).
                         Create();

            ChallengeSession.ForRunner(runner)
            .WithConfig(Utils.GetConfig())
            .WithActionProvider(new UserInputAction(args))
            .Start();

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey();
        }
Ejemplo n.º 9
0
 public void FreeBBasketOddB()
 {
     Assert.AreEqual(165, CheckoutSolution.Checkout("EEEBBB"));
 }
Ejemplo n.º 10
0
 public void FreeBBasketEvenE()
 {
     Assert.AreEqual(80, CheckoutSolution.Checkout("EEB"));
 }
Ejemplo n.º 11
0
 public void CheckoutIsInvalid()
 {
     Assert.AreEqual(-1, CheckoutSolution.Checkout("123"));
 }
Ejemplo n.º 12
0
 public void SimpleBasketE()
 {
     Assert.AreEqual(40, CheckoutSolution.Checkout("E"));
 }
Ejemplo n.º 13
0
 public void MultipleBasketENoB()
 {
     Assert.AreEqual(80, CheckoutSolution.Checkout("EE"));
 }
Ejemplo n.º 14
0
 public void CheckoutEmptyBasket()
 {
     Assert.AreEqual(0, CheckoutSolution.Checkout(""));
 }
Ejemplo n.º 15
0
 public void CheckSTXYZDeal1()
 {
     Assert.AreEqual(82, CheckoutSolution.Checkout("STXYZ"));
 }
Ejemplo n.º 16
0
 public void CheckSTXYZSingle2()
 {
     Assert.AreEqual(37, CheckoutSolution.Checkout("XY"));
 }
Ejemplo n.º 17
0
 public void MultipleSkuBasketD()
 {
     Assert.AreEqual(60, CheckoutSolution.Checkout("DDDD"));
 }
Ejemplo n.º 18
0
 public void SpecialOfferBasketA()
 {
     Assert.AreEqual(180, CheckoutSolution.Checkout("AAAA"));
 }
Ejemplo n.º 19
0
 public void ComputePrice_Should_Return_CorrectPrice_For_Product_R_Given_MultipleValues_Combined_With_Q()
 {
     Assert.AreEqual(150, CheckoutSolution.ComputePrice("RRRQ"));
 }
Ejemplo n.º 20
0
 public void MultipleSkuBasketA()
 {
     Assert.AreEqual(100, CheckoutSolution.Checkout("AA"));
 }
Ejemplo n.º 21
0
 public void SimpleBasket()
 {
     Assert.AreEqual(185, CheckoutSolution.Checkout("ABCDK"));
 }
Ejemplo n.º 22
0
 public void CheckSTXYZDeal3()
 {
     Assert.AreEqual(135, CheckoutSolution.Checkout("STXYYYZZZ"));
 }
Ejemplo n.º 23
0
 public void CheckSTXYZSingle1()
 {
     Assert.AreEqual(40, CheckoutSolution.Checkout("ST"));
 }
Ejemplo n.º 24
0
 public void UnorderedBasket()
 {
     Assert.AreEqual(245, CheckoutSolution.Checkout("DACDBCADA"));
 }
Ejemplo n.º 25
0
        public void TestCheckout(string skus, int expectedTotal)
        {
            int actualTotal = CheckoutSolution.ComputePrice(skus);

            Assert.That(actualTotal, Is.EqualTo(expectedTotal), skus);
        }
Ejemplo n.º 26
0
 public void LowerCaseNotAllowed()
 {
     Assert.AreEqual(-1, CheckoutSolution.Checkout("a"));
 }
Ejemplo n.º 27
0
 public void SpecialOfferBasketB()
 {
     Assert.AreEqual(45, CheckoutSolution.Checkout("BB"));
 }
Ejemplo n.º 28
0
 public void CheckSTXYZSingle3()
 {
     Assert.AreEqual(21, CheckoutSolution.Checkout("Z"));
 }
Ejemplo n.º 29
0
 public void ComputePrice_Should_Return_CorrectPrice_For_Product_U_Given_MultipleValues()
 {
     Assert.AreEqual(120, CheckoutSolution.ComputePrice("UUUU"));
 }
Ejemplo n.º 30
0
 public void MultipleSkuBasketC()
 {
     Assert.AreEqual(80, CheckoutSolution.Checkout("CCCC"));
 }