コード例 #1
0
        public void Caches_model_by_context_type()
        {
            var modelSource = new DefaultModelSource(new DbSetFinder());

            var model1 = modelSource.GetModel(new Context1(), new ModelBuilderFactory());
            var model2 = modelSource.GetModel(new Context2(), new ModelBuilderFactory());

            Assert.NotSame(model1, model2);
            Assert.Same(model1, modelSource.GetModel(new Context1(), new ModelBuilderFactory()));
            Assert.Same(model2, modelSource.GetModel(new Context2(), new ModelBuilderFactory()));
        }
コード例 #2
0
        public void Members_check_arguments()
        {
            Assert.Equal(
                "setFinder",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => new DefaultModelSource(null)).ParamName);

            var modelSource = new DefaultModelSource(new Mock<DbSetFinder>().Object);

            Assert.Equal(
                "context",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => modelSource.GetModel(null, new ModelBuilderFactory())).ParamName);
        }
コード例 #3
0
        public void Adds_all_entities_based_on_all_distinct_entity_types_found()
        {
            var setFinderMock = new Mock<DbSetFinder>();
            setFinderMock.Setup(m => m.FindSets(It.IsAny<DbContext>())).Returns(
                new[]
                    {
                        new DbSetFinder.DbSetProperty(typeof(JustAClass), "One", typeof(Random), hasSetter: true),
                        new DbSetFinder.DbSetProperty(typeof(JustAClass), "Two", typeof(object), hasSetter: true),
                        new DbSetFinder.DbSetProperty(typeof(JustAClass), "Three", typeof(string), hasSetter: true),
                        new DbSetFinder.DbSetProperty(typeof(JustAClass), "Four", typeof(string), hasSetter: true)
                    });

            var model = new DefaultModelSource(setFinderMock.Object).GetModel(new Mock<DbContext>().Object, new ModelBuilderFactory());

            Assert.Equal(
                new[] { "Object", "Random", "String" },
                model.EntityTypes.Select(e => e.Name).ToArray());
        }