public void SubDomainModel_FindEntity_ExpressionWithInvalidIncludePaths_ExceptionIsThrown() { TestSubDomainModel testSubject = new TestSubDomainModel(); Repository <TestDummy> mockedRepository = MockRepository.GeneratePartialMock <Repository <TestDummy> >(); TestDummy result = testSubject.FindEntity(td => td.RecordId > 1, new string[] { "PropA.PropB", null, "dummy" }); }
public void SubDomainModel_CreateEmptyEntity_TemplateMethodIsCalled() { TestSubDomainModel testSubject = new TestSubDomainModel(); TestDummy result = testSubject.CreateEmptyEntity(); Assert.IsTrue(testSubject.CreateEmptyEntityCoreWasCalled); }
public void SubDomainModel_FindEntity_Specification_TemplateMethodIsCalled() { TestSubDomainModel testSubject = new TestSubDomainModel(); ISpecification <TestDummy> spec = Specification.Lambda <TestDummy>(td => td.RecordId > 1); TestDummy result = testSubject.FindEntity(spec); Assert.IsTrue(testSubject.FindEntityCoreWasCalled); Assert.AreSame(spec, testSubject.FindEntityCoreParameter); }
public void SubDomainModel_AddEntity_TemplateMethodIsCalled() { TestSubDomainModel testSubject = new TestSubDomainModel(); TestDummy entity = new TestDummy { TestNumber = 30 }; TestDummy result = testSubject.AddEntity(entity); Assert.IsTrue(testSubject.AddEntityCoreWasCalled); Assert.AreEqual(entity, testSubject.AddEntityCoreParameter); }
/// <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); }
public void SubDomainModel_FindEntity_Expression_TemplateMethodIsCalled() { TestSubDomainModel testSubject = new TestSubDomainModel(); Repository <TestDummy> mockedRepository = MockRepository.GeneratePartialMock <Repository <TestDummy> >(); TestDummy result = testSubject.FindEntity(td => td.RecordId > 1); 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); }
public void SubDomainModel_FindEntities_NoSpecificationNoIncludePaths_TemplateMethodIsCalled() { TestSubDomainModel testSubject = new TestSubDomainModel(); Repository <TestDummy> mockedRepository = MockRepository.GeneratePartialMock <Repository <TestDummy> >(); IList <TestDummy> result = testSubject.FindEntities(); ISpecification <TestDummy> specificationResult = testSubject.FindEntitiesCoreParameter; Expression <Func <TestDummy, bool> > expressionResult = specificationResult.Visit(mockedRepository); Assert.IsTrue(testSubject.FindEntitiesCoreWasCalled); Assert.AreEqual(ExpressionType.Lambda, expressionResult.NodeType); Assert.AreEqual(typeof(bool), expressionResult.ReturnType); bool constantValue = (bool)((ConstantExpression)expressionResult.Body).Value; Assert.AreEqual(true, constantValue); }
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); }
public void SubDomainModel_FindEntity_ExpressionWithIncludePaths_TemplateMethodIsCalled() { TestSubDomainModel testSubject = new TestSubDomainModel(); Repository <TestDummy> mockedRepository = MockRepository.GeneratePartialMock <Repository <TestDummy> >(); TestDummy result = testSubject.FindEntity(td => td.RecordId > 1, new string[] { "PropA.PropB", "dummy" }); Assert.IsTrue(testSubject.FindEntityCoreWasCalled); ISpecification <TestDummy> specificationResult = testSubject.FindEntityCoreParameter; Assert.AreEqual(2, specificationResult.IncludePaths.Count()); CollectionAssert.AreEquivalent(new string[] { "dummy", "PropA.PropB" }, specificationResult.IncludePaths.ToList()); Expression <Func <TestDummy, bool> > expressionResult = specificationResult.Visit(mockedRepository); Assert.AreEqual(ExpressionType.Lambda, expressionResult.NodeType); Assert.AreEqual(typeof(bool), expressionResult.ReturnType); }