Exemplo n.º 1
0
        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" });
        }
Exemplo n.º 2
0
        public void SubDomainModel_CreateEmptyEntity_TemplateMethodIsCalled()
        {
            TestSubDomainModel testSubject = new TestSubDomainModel();

            TestDummy result = testSubject.CreateEmptyEntity();

            Assert.IsTrue(testSubject.CreateEmptyEntityCoreWasCalled);
        }
Exemplo n.º 3
0
        public void TestCase04_Validation_ThrowOnError_InvalidEntity()
        {
            TestDummy dummy = new TestDummy {
                TextValue = "zzzzabc12", NumericValue = 16, BooleanValue = null
            };

            EntityValidator <TestDummy>    validator = new EntityValidator <TestDummy>();
            ICollection <ValidationResult> results   = validator.PerformValidation(dummy, true);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public void SubDomainModel_ValidateEntity_InvalidEntity_ValidationResultIsReturned()
        {
            ISubDomainModel <TestDummy> testSubject = MockRepository.GeneratePartialMock <SubDomainModel <TestDummy> >();

            TestDummy entity = new TestDummy {
                TestNumber = 50
            };
            ICollection <ValidationResult> result = testSubject.ValidateEntity(entity);

            Assert.AreEqual(1, result.Count);
        }
Exemplo n.º 6
0
        public void TestCase02_Validation_InvalidEntity()
        {
            TestDummy dummy = new TestDummy {
                TextValue = "zzzzabc12", NumericValue = 16, BooleanValue = null
            };

            EntityValidator <TestDummy>    validator = new EntityValidator <TestDummy>();
            ICollection <ValidationResult> results   = validator.PerformValidation(dummy);

            Assert.IsNotNull(results);
            Assert.AreEqual(2, results.Count);
        }
Exemplo n.º 7
0
        public void TestCase03_Validation_ThrowOnError_ValidEntity()
        {
            TestDummy dummy = new TestDummy {
                TextValue = "zzzzabc12", NumericValue = 11, BooleanValue = false
            };

            EntityValidator <TestDummy>    validator = new EntityValidator <TestDummy>();
            ICollection <ValidationResult> results   = validator.PerformValidation(dummy, true);

            Assert.IsNotNull(results);
            Assert.AreEqual(0, results.Count);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        public void SubDomainModel_FindEntityByIdWithEmptyIncludePaths_ExceptionIsThrown()
        {
            ISubDomainModel <TestDummy> testSubject = MockRepository.GeneratePartialMock <SubDomainModel <TestDummy> >();

            TestDummy result = testSubject.FindEntityById(42, new string[0]);
        }
Exemplo n.º 14
0
 public void Repository_FindSingleWithNullSpecification_ExceptionIsThrown()
 {
     Repository <TestDummy> repository = MockRepository.GenerateMock <Repository <TestDummy> >();
     TestDummy result = repository.FindSingle((ISpecification <TestDummy>)null);
 }
Exemplo n.º 15
0
 public void Repository_FindFirstWithDefaultAndNullSpecification_ExceptionIsThrown()
 {
     Repository <TestDummy> repository = MockRepository.GenerateMock <Repository <TestDummy> >();
     TestDummy result = repository.FindFirst((ISpecification <TestDummy>)null, new TestDummy());
 }
Exemplo n.º 16
0
        public void SubDomainModel_AddEntity_NullEntity_ExceptionIsThrown()
        {
            ISubDomainModel <TestDummy> testSubject = MockRepository.GenerateMock <SubDomainModel <TestDummy> >();

            TestDummy result = testSubject.AddEntity(null);
        }
Exemplo n.º 17
0
        public void SubDomainModel_FindEntity_NullExpression_ExceptionIsThrown()
        {
            ISubDomainModel <TestDummy> testSubject = MockRepository.GeneratePartialMock <SubDomainModel <TestDummy> >();

            TestDummy result = testSubject.FindEntity((Expression <Func <TestDummy, bool> >)null);
        }
Exemplo n.º 18
0
 public void Repository_FindSingleWithNullExpression_ExceptionIsThrown()
 {
     Repository <TestDummy> repository = MockRepository.GenerateMock <Repository <TestDummy> >();
     TestDummy result = repository.FindSingle((Expression <Func <TestDummy, bool> >)null);
 }
Exemplo n.º 19
0
        public void SubDomainModel_FindEntityByIdWithInvalidIncludePaths_ExceptionIsThrown()
        {
            ISubDomainModel <TestDummy> testSubject = MockRepository.GeneratePartialMock <SubDomainModel <TestDummy> >();

            TestDummy result = testSubject.FindEntityById(42, new string[] { "PropA.PropB", null, "dummy" });
        }
Exemplo n.º 20
0
 public void Repository_FindFirstWithDefaultAndNullExpression_ExceptionIsThrown()
 {
     Repository <TestDummy> repository = MockRepository.GenerateMock <Repository <TestDummy> >();
     TestDummy result = repository.FindFirst((Expression <Func <TestDummy, bool> >)null, new TestDummy());
 }
Exemplo n.º 21
0
        public void SubDomainModel_FindEntity_NullSpecification_ExceptionIsThrown()
        {
            ISubDomainModel <TestDummy> testSubject = MockRepository.GeneratePartialMock <SubDomainModel <TestDummy> >();

            TestDummy result = testSubject.FindEntity((ISpecification <TestDummy>)null);
        }