Exemplo n.º 1
0
        public void NoParameterProcedureReplacement()
        {
            var dataMock = new DataMock<DataMockDataContext>
            {
                Log = Console.Out
            };

            const string TEXT_MESSAGE = "This is a test and nothing but a test";

            dataMock.Setup( dc => dc.NoParametersProcB() )
                .Returns( new NoParametersProcBResult
                {
                    ID = 5,
                    TextMessage = TEXT_MESSAGE
                } );

            dataMock.Execute( Settings.Default.DataMockConnectionString );

            var dataContext = new DataMockDataContext();

            var result = dataContext.NoParametersProcA().ToArray();

            Assert.AreEqual( result[0].TextMessage, TEXT_MESSAGE );
            Assert.AreEqual( result[0].Id, 5 );
            Assert.AreEqual( result[1].TextMessage, "Message from Proc A" );
            Assert.AreEqual( result[1].Id, 10 );
        }
Exemplo n.º 2
0
        public void VariableOutputProcedureReplacementWithAnyParam()
        {
            var dataMock = new DataMock<DataMockDataContext>
            {
                Log = Console.Out
            };

            const string TEXT_MESSAGE = "This is a test and nothing but a test";

            dataMock.Setup( dc => dc.VariableOutputProcB( Param.IsAny<int>() ) )
                .Returns( new VariableOutputProcBResult
                {
                    Id = 5,
                    TextMessage = TEXT_MESSAGE
                } );

            dataMock.Execute( Settings.Default.DataMockConnectionString );

            var dataContext = new DataMockDataContext();

            var result = dataContext.VariableOutputProcA( 3 ).ToArray();

            Assert.AreEqual( 5, result[0].Id );
            Assert.AreEqual( 5, result[1].Id );
            Assert.AreEqual( 5, result[2].Id );
        }
Exemplo n.º 3
0
 private void _RunInsert(string name = null)
 {
     using (var context = new DataMockDataContext())
     {
         context.Parents.InsertOnSubmit(new Parent
         {
             Name = name ?? string.Empty
         });
         context.SubmitChanges();
     }
 }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        public void DropConstraintBasic()
        {
            try
            {
                _RunInsert();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            using (var context = new DataMockDataContext())
            {
                context.DisableAllCheckConstraints<DataMockDataContext, Child>();
            }

            _RunInsert("Ralph");
        }
Exemplo n.º 6
0
        public void MockBooleanScalarFunction()
        {
            var dataMock = new DataMock<DataMockDataContext>
            {
                Log = Console.Out
            };

            using (var context = new DataMockDataContext(Settings.Default.DataMockConnectionString))
            {
                Assert.AreEqual(true, context.ScalarFunctionBoolean(1));

                dataMock
                    .Setup(ctx => ctx.ScalarFunctionBoolean(Param.IsAny<int?>()))
                    .Returns(false);

                dataMock.Execute(Settings.Default.DataMockConnectionString);

                Assert.AreEqual(false, context.ScalarFunctionBoolean(1));
            }
        }
Exemplo n.º 7
0
        public void FinalizeExistingOrder()
        {
            var dataMock = new DataMock<DataMockDataContext>
            {
                Log = Console.Out
            };

            const int NEXT_SEQUENCE = 3;
            dataMock
                .Setup( context => context.GetNextOrderSequence())
                .Returns(NEXT_SEQUENCE);

            using (var context = new DataMockDataContext(Settings.Default.DataMockConnectionString))
            {
                //Disable all check constraints on the Order table to simplify inserting test data
                context.DisableAllCheckConstraints<DataMockDataContext, Order>();

                //Create an Order object, and set its properties to sensible default values
                var orderToUpdate = new Order();
                DataMockHelper.DefaultValues(orderToUpdate);

                //add the order to the database
                context.Orders.InsertOnSubmit(orderToUpdate);
                context.SubmitChanges();

                //create the mocked implementation of GetNextOrderSequence()
                dataMock.Execute(Settings.Default.DataMockConnectionString);

                //execute the FinalizeOrder procedure and verify its results
                FinalizeOrderResult finalizeOrderResult = context.FinalizeOrder(orderToUpdate.OrderId).SingleOrDefault();

                Assert.IsNotNull(finalizeOrderResult);
                Assert.AreEqual(NEXT_SEQUENCE, finalizeOrderResult.Sequence);

                //verify that the procedure updated the order table
                context.Refresh(RefreshMode.OverwriteCurrentValues, orderToUpdate);
                Assert.AreEqual(NEXT_SEQUENCE, orderToUpdate.OrderSequenceNumber);
            }
        }
Exemplo n.º 8
0
        public void MockViewWithOneRow()
        {
            var dataMock = new DataMock<DataMockDataContext>
            {
                Log = Console.Out
            };
            const string CHILD = "Robert";
            const string PARENT = "Maude";
            dataMock
                .Setup( context => context.Peoples )
                .Returns( new People
                {
                    Child = CHILD,
                    Parent = PARENT
                } );
            dataMock.Execute( Settings.Default.DataMockConnectionString );

            using( var context = new DataMockDataContext() )
            {
                People person = context.Peoples.Single();
                Assert.IsTrue( person.Child == CHILD );
                Assert.IsTrue( person.Parent == PARENT );
            }
        }
Exemplo n.º 9
0
        public void MockViewWithMultipleSetupCalls()
        {
            var dataMock = new DataMock<DataMockDataContext>();

            const string MARY = "Mary";
            const string TRACY = "Tracy";
            const string CATHERINE = "Catherine";
            const string JOE = "Joe";
            const string JOHN = "John";

            var parents = new[] { MARY, TRACY };
            var children = new [] { JOHN, JOE, CATHERINE };

            dataMock
                .Setup( context => context.Peoples )
                .Returns(
                    new People
                    {
                        Child = CATHERINE,
                        Parent = MARY
                    },
                    new People
                    {
                        Child = JOE,
                        Parent = MARY
                    },
                    new People
                    {
                        Child = JOHN,
                        Parent = MARY
                    } );

            dataMock
                .Setup( context => context.Peoples )
                .Returns(
                    new People
                    {
                        Child = CATHERINE,
                        Parent = TRACY
                    },
                    new People
                    {
                        Child = JOE,
                        Parent = TRACY
                    },
                    new People
                    {
                        Child = JOHN,
                        Parent = TRACY
                    } );
            dataMock.Execute(Settings.Default.DataMockConnectionString);

            People[] people;
            using( var context = new DataMockDataContext() )
            {
                people = context.Peoples
                    .OrderBy( person => person.Parent )
                    .ThenBy( person => person.Child )
                    .ToArray();
            }

            Assert.AreEqual( 6, people.Length );
            int counter = 0;
            foreach( string parent in parents.OrderBy( a => a ) )
            {
                foreach( var child in children.OrderBy( a => a ) )
                {
                    People person = people[counter++];
                    Assert.AreEqual(parent, person.Parent);
                    Assert.AreEqual(child, person.Child);
                }
            }
        }
Exemplo n.º 10
0
        public void MockViewWithSeveralRows()
        {
            var dataMock = new DataMock<DataMockDataContext>
            {
                Log = Console.Out
            };

            dataMock
                .Setup( context => context.Peoples )
                .Returns( new People
                {
                    Child = "Owen",
                    Parent = "Michelle"
                },
                new People
                {
                    Child = "Owen",
                    Parent = "Jacob"
                } );
            dataMock.Execute( Settings.Default.DataMockConnectionString );

            using( var context = new DataMockDataContext() )
            {
                Assert.IsTrue( context.Peoples.Count() == 2 );
            }
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
        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);
            }
        }
Exemplo n.º 13
0
        public void MockScalarFunctionReturnsConstantValue()
        {
            var dataMock = new DataMock<DataMockDataContext>
            {
                Log = Console.Out
            };

            dataMock
                .Setup(context => context.ScalarFunction(Param.IsAny<int?>(), Param.IsAny<int?>()))
                .Returns(1);

            dataMock.Execute(Settings.Default.DataMockConnectionString);

            using (var context = new DataMockDataContext(Settings.Default.DataMockConnectionString))
            {
                int? result = context.ScalarFunction(1, 1);
                Assert.AreEqual(result, 1);
            }
        }