示例#1
0
        public void ConstructorSetsSkipStackFramesCorrectly()
        {
            var expectedSkipStackFrames = 123;

            var sut = new DataDrivenTest(expectedSkipStackFrames);

            Assert.AreEqual(expectedSkipStackFrames, sut.SkipStackFrames);
        }
示例#2
0
        public void ArrangeWithNoArgumentsSetsTestCaseCorrectly()
        {
            var sut = new DataDrivenTest().Arrange();

            Assert.AreEqual(1, sut.TestCases.Count, "There should only be a single test case");
            Assert.AreEqual(0, sut.TestCaseArgumentCount, "The test case should not have any arguments");
            Assert.AreEqual(0, sut.TestCases.First().Length, "There should not be any arguments in the first test case");
        }
示例#3
0
        public void ArrangeFromAttributesSetsTestCaseCorrectly()
        {
            var sut = new DataDrivenTest().ArrangeFromAttributes();

            Assert.AreEqual(1, sut.TestCases.Count, "There should only be a single test case");
            Assert.AreEqual(1, sut.TestCaseArgumentCount, "The test case should only have one argument");
            Assert.AreEqual("test", sut.TestCases.First().First(), "Incorrect argument value");
        }
示例#4
0
        public void ArrangeSetsTestCasesCorrectly()
        {
            var sut = new DataDrivenTest()
                      .Arrange("test", "case")
                      .Arrange("test 2", "case 2")
                      .Arrange("test 3", "case 3");

            Assert.AreEqual(3, sut.TestCases.Count, "There should be three test cases");
            Assert.AreEqual(2, sut.TestCaseArgumentCount, "Each test case should have two arguments");
            Assert.AreEqual("case 2", sut.TestCases.ElementAt(1)[1], "Incorrect value in the second argument of the second test case");
        }
示例#5
0
        public void ArrangeFuncSetsTestCaseCorrectly()
        {
            Func <IEnumerable <object> > expected = () => new List <object> {
                "test", "case"
            };

            var sut = new DataDrivenTest().Arrange(expected);

            Assert.AreEqual(1, sut.TestCases.Count, "There should only be a single test case");
            Assert.AreEqual(2, sut.TestCaseArgumentCount, "The test case should have two arguments");
            Assert.AreEqual("test", sut.TestCases.First().First(), "Incorrect value of the first argument");
        }
        /// <summary>
        /// Runs a client test with both Atom and Json OData formats.
        /// </summary>
        /// <typeparam name="TContext">The DataServiceContext type.</typeparam>
        /// <param name="testBase">The test class running the test.</param>
        /// <param name="createContext">A delegate to create the context.</param>
        /// <param name="test">The test action to execute.</param>
        public static void RunOnAtomAndJsonFormats <TContext>(
            this EndToEndTestBase testBase,
            Func <DataServiceContextWrapper <TContext> > createContext,
            Action <DataServiceContextWrapper <TContext> > test) where TContext : DataServiceContext
        {
            var jsonContext = createContext();

            jsonContext.ContextLabel = "Json";
            jsonContext.Format.UseJson();

            testBase.InvokeDataDrivenTest(test, DataDrivenTest.CreateData(jsonContext));
        }
示例#7
0
        public void ActAndAssertThrowsWhenNoTestCasesHaveBeenArranged()
        {
            var expected = "Assert.Fail failed. There are no test cases. Have you forgotten to arrange them?";

            try
            {
                var sut = new DataDrivenTest();
                sut.ActAndAssert((object x) => { });
            }
            catch (AssertFailedException ex)
            {
                Assert.AreEqual(expected, ex.Message);
            }
        }
示例#8
0
        public void ActAndAssertIsCalledCorrectly()
        {
            var sut = new DataDrivenTest()
                      .Arrange("test 0", "case 0")
                      .Arrange("test 1", "case 1");

            var actualCallCount = 0;
            var act             = new Action <string, string>((test, expected) =>
            {
                Assert.AreEqual(test, $"test {actualCallCount}");
                Assert.AreEqual(expected, $"case {actualCallCount}");

                actualCallCount++;
            });

            sut.ActAndAssert(act);

            Assert.AreEqual(2, actualCallCount, "Act should be called twice");
        }
示例#9
0
        public void ArrangeTestCasesFuncSetsTestCasesCorrectly()
        {
            Func <IEnumerable <IEnumerable <object> > > expected = () => new List <List <object> >
            {
                new List <object> {
                    "test", "case"
                },
                new List <object> {
                    "test 2", "case 2"
                },
                new List <object> {
                    "test 3", "case 3"
                }
            };

            var sut = new DataDrivenTest().ArrangeTestCases(expected);

            Assert.AreEqual(3, sut.TestCases.Count, "There should be three test cases");
            Assert.AreEqual(2, sut.TestCaseArgumentCount, "Each test case should have two arguments");
            Assert.AreEqual("case 2", sut.TestCases.ElementAt(1)[1], "Incorrect value in the second argument of the second test case");
        }
示例#10
0
        public void ActAndAssertThrowsWhenActAndAssertDelegateIsNull()
        {
            var sut = new DataDrivenTest();

            sut.ActAndAssert(null);
        }
示例#11
0
        public void ActAndAssertThrows()
        {
            var sut = new DataDrivenTest().Arrange("testcase");

            sut.ActAndAssert((string x) => { throw new InvalidOperationException(); });
        }
示例#12
0
        public void EmptyConstructorSetsSkipStackFramesCorrectly()
        {
            var sut = new DataDrivenTest();

            Assert.AreEqual(1, sut.SkipStackFrames);
        }
示例#13
0
 /// <summary>
 /// To data driven parameter data
 /// </summary>
 /// <typeparam name="T">The item type</typeparam>
 /// <param name="collection">The item collecion</param>
 /// <returns>The parameter data</returns>
 public static ParameterData<T> ToParamData<T>(this IEnumerable<T> collection)
 {
     return DataDrivenTest.CreateData(collection.ToArray());
 }