Beispiel #1
0
        public void Can_Convert_Test_With_Results()
        {
            using (var req = MvcMockHelpers.SimulateRequest("http://localhost/Test.aspx"))
            {
                ABTester.Start();

                Assert.IsNotNull(ABTester.Current);

                var testname = "Can_Convert_Test_With_Results";

                var option1 = "one";
                var option2 = "two";

                var output = ABTester.Test(testname, option1, option2);

                Assert.IsTrue(output == option1 || output == option2);

                ABTester.Convert(testname);

                var results = ABTester.GetResults(testname);

                Assert.IsNotNull(results);
                Assert.AreEqual(1, results.Count);
                Assert.IsTrue(results[0].Converted);
            }
        }
Beispiel #2
0
        public void Can_Run_Two_Tests_And_Convert_One()
        {
            using (var req = MvcMockHelpers.SimulateRequest("http://localhost/Test.aspx"))
            {
                ABTester.Start();

                Assert.IsNotNull(ABTester.Current);

                var testname = "Can_Run_Two_Tests_And_Convert_One";

                var option1 = "one";
                var option2 = "two";

                var output = ABTester.Test(testname, option1, option2);

                Assert.IsTrue(output == option1 || output == option2);

                //Call Start again to similate next request with new ABTester instance
                ABTester.Start();

                var output2 = ABTester.Test(testname, option1, option2);

                Assert.IsTrue(output2 == option1 || output2 == option2);

                ABTester.Convert(testname);

                var results = ABTester.GetResults(testname);

                Assert.IsNotNull(results);
                Assert.AreEqual(2, results.Count);
                Assert.IsFalse(results[0].Converted);
                Assert.IsTrue(results[1].Converted);
            }
        }
Beispiel #3
0
        public void Can_Get_Test_Results()
        {
            using (var req = MvcMockHelpers.SimulateRequest("http://localhost/Test.aspx"))
            {
                var results = ABTester.GetResults("Can_Get_Test_Results");

                Assert.IsNotNull(results);
            }
        }
Beispiel #4
0
        private string showResults(List <string> extras)
        {
            var testName = extras.FirstOrDefault();
            var results  = ABTester.GetResults(testName);
            var sw       = new StringWriter();

            if (!results.Any())
            {
                throw new ApplicationException(string.Format("Test: {0} not found", testName));
            }

            var options = from r in results
                          group r by r.Option into g
                          select new
            {
                Option      = g.Key,
                Total       = g.Count(),
                Conversions = g.Count(or => or.Converted)
            };

            var format = "{0,-18}{1,-12}{2,-12}{3,-12}";

            sw.WriteLine(testName + " Results");
            sw.WriteLine();

            sw.WriteLine(format, "OPTION", "TOTAL", "CONVERT", "%");

            foreach (var o in options)
            {
                var percentage = (double)o.Conversions / (double)o.Total;
                sw.WriteLine(format, o.Option, o.Total, o.Conversions, percentage.ToString("P"));
            }

            sw.WriteLine(format, "TOTAL:", options.Sum(o => o.Total), options.Sum(o => o.Conversions), "");

            return(sw.ToString());
        }