コード例 #1
0
ファイル: FunctionTests.cs プロジェクト: codamadtrek/DataMoq
        public void MockFunctionWithExactParameters()
        {
            var dataMock = new DataMock<DataMockDataContext>
            {
                Log = Console.Out
            };

            const int QUERY_INT = 10;
            const string QUERY_STRING = "TEST";
            var queryGuid = Guid.NewGuid();
            var queryDate = DateTime.Today;
            const bool QUERY_BIT = true;
            const char QUERY_CHAR = ' ';

            const int RESULT_INT = 1;
            const string RESULT_STRING = "12345";
            var resultGuid = Guid.Empty;
            var resultDate = new DateTime(2012, 1, 1);
            const bool RESULT_BIT = true;
            const char RESULT_CHAR = 'A';

            dataMock
                .Setup(context => context.DataTypesFunction(QUERY_INT, QUERY_STRING, queryGuid, queryDate, QUERY_BIT, QUERY_CHAR))
                .Returns(new DataTypesFunctionResult
                {
                    c1 = RESULT_INT,
                    c2 = RESULT_STRING,
                    c3 = resultGuid,
                    c4 = resultDate,
                    c5 = RESULT_BIT,
                    c6 = RESULT_CHAR
                });
            dataMock.Execute(Settings.Default.DataMockConnectionString);

            using (var context = new DataMockDataContext(Settings.Default.DataMockConnectionString))
            {
                DataTypesFunctionResult result = context.DataTypesFunction(QUERY_INT, QUERY_STRING, queryGuid, queryDate, QUERY_BIT, QUERY_CHAR).Single();
                Assert.AreEqual(RESULT_INT, result.c1);
                Assert.AreEqual(RESULT_STRING, result.c2);
                Assert.AreEqual(resultGuid, result.c3);
                Assert.AreEqual(resultDate, result.c4);
                Assert.AreEqual(RESULT_BIT, result.c5);
                Assert.AreEqual(RESULT_CHAR, result.c6);
            }
        }
コード例 #2
0
ファイル: FunctionTests.cs プロジェクト: codamadtrek/DataMoq
        public void MockFunctionWithNewGuidExpression()
        {
            var dataMock = new DataMock<DataMockDataContext>
            {
                Log = Console.Out
            };

            const int QUERY_INT = 10;
            const string QUERY_STRING = "TEST";
            var queryGuid = new Guid("F255039E-7809-E211-BDD9-08002704F29D");

            const int RESULT_INT = 1;
            const string RESULT_STRING = "12345";
            var resultGuid = Guid.Empty;

            dataMock
                .Setup(context => context.DataTypesFunction(QUERY_INT, QUERY_STRING, new Guid("F255039E-7809-E211-BDD9-08002704F29D"), DateTime.Today, Param.IsAny<bool>(), Param.IsAny<char>()))
                .Returns(new DataTypesFunctionResult
                {
                    c1 = RESULT_INT,
                    c2 = RESULT_STRING,
                    c3 = resultGuid
                });
            dataMock.Execute(Settings.Default.DataMockConnectionString);

            using (var context = new DataMockDataContext(Settings.Default.DataMockConnectionString))
            {
                DataTypesFunctionResult result = context.DataTypesFunction(QUERY_INT, QUERY_STRING, queryGuid, DateTime.Today, true, ' ').Single();
                Assert.AreEqual(RESULT_INT, result.c1);
                Assert.AreEqual(RESULT_STRING, result.c2);
                Assert.AreEqual(resultGuid, result.c3);
            }
        }
コード例 #3
0
ファイル: FunctionTests.cs プロジェクト: codamadtrek/DataMoq
        public void NullParameterValue()
        {
            var dataMock = new DataMock<DataMockDataContext>
            {
                Log = Console.Out
            };

            dataMock
                .Setup(context => context.DataTypesFunction(null, null, null, null, null, null))
                .Returns(new DataTypesFunctionResult
                {
                    c1 = 1,
                    c2 = "<NULL>",
                    c3 = Guid.Empty,
                    c4 = DateTime.Today,
                    c5 = true
                });
            dataMock.Execute(Settings.Default.DataMockConnectionString);

            using (var context = new DataMockDataContext(Settings.Default.DataMockConnectionString))
            {
                DataTypesFunctionResult result = context.DataTypesFunction(null, null, null, null, null, null).SingleOrDefault();
                Assert.IsNotNull(result);
                Assert.AreEqual(1, result.c1);
            }
        }