Beispiel #1
0
        /// <summary>Replays the bug described in bug 12. Querying entities by RecordID causes an entity framework exception.</summary>
        /// <seealso href="https://humanprinter.visualstudio.com/DefaultCollection/Enkoni.Framework/_workitems/edit/12"/>
        //[TestMethod]
        public void Bug01_QueryById()
        {
            Database.SetInitializer <DatabaseRepositoryTestContext>(null);
            DbContext      context    = new DatabaseRepositoryTestContext("BugScenarios");
            DataSourceInfo sourceInfo = new DatabaseSourceInfo(context);

            SubDomainModel <TestDummy> subDomain = new TestSubDomainModel(new TestDatabaseRepository(sourceInfo));

            TestDummy result = subDomain.FindEntityById(2);

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.RecordId);
            Assert.AreEqual("TestDummy 2", result.TextValue);
        }
Beispiel #2
0
        public void SubDomainModel_FindEntityById_TemplateMethodIsCalled()
        {
            TestSubDomainModel     testSubject      = new TestSubDomainModel();
            Repository <TestDummy> mockedRepository = MockRepository.GeneratePartialMock <Repository <TestDummy> >();

            TestDummy result = testSubject.FindEntityById(42);

            Assert.IsTrue(testSubject.FindEntityCoreWasCalled);

            Expression <Func <TestDummy, bool> > expressionResult = testSubject.FindEntityCoreParameter.Visit(mockedRepository);

            Assert.AreEqual(ExpressionType.Lambda, expressionResult.NodeType);
            Assert.AreEqual(typeof(bool), expressionResult.ReturnType);

            object container     = ((ConstantExpression)((MemberExpression)((BinaryExpression)expressionResult.Body).Right).Expression).Value;
            int    constantValue = (int)((FieldInfo)((MemberExpression)((BinaryExpression)expressionResult.Body).Right).Member).GetValue(container);

            Assert.AreEqual(42, constantValue);
        }