Ejemplo n.º 1
0
        public void Entry_methods_delegate_to_underlying_state_manager()
        {
            var entity = new Random();
            var stateManagerMock = new Mock<StateManager>();
            var stateEntry = new Mock<StateEntry>().Object;
            stateManagerMock.Setup(m => m.GetOrCreateEntry(entity)).Returns(stateEntry);

            var changeTracker = new ChangeTracker(stateManagerMock.Object, Mock.Of<ChangeDetector>());

            Assert.Same(stateEntry, changeTracker.Entry(entity).StateEntry);
            Assert.Same(stateEntry, changeTracker.Entry((object)entity).StateEntry);
        }
Ejemplo n.º 2
0
        public void Entry_methods_delegate_to_underlying_state_manager()
        {
            var entity           = new Random();
            var stateManagerMock = new Mock <StateManager>();
            var stateEntry       = new Mock <StateEntry>().Object;

            stateManagerMock.Setup(m => m.GetOrCreateEntry(entity)).Returns(stateEntry);

            var changeTracker = new ChangeTracker(stateManagerMock.Object, Mock.Of <ChangeDetector>());

            Assert.Same(stateEntry, changeTracker.Entry(entity).StateEntry);
            Assert.Same(stateEntry, changeTracker.Entry((object)entity).StateEntry);
        }
Ejemplo n.º 3
0
        public virtual TEntity Delete <TEntity>([NotNull] TEntity entity)
        {
            Check.NotNull(entity, "entity");

            ChangeTracker.Entry(entity).State = EntityState.Deleted;

            return(entity);
        }
Ejemplo n.º 4
0
        public virtual TEntity Update<TEntity>([NotNull] TEntity entity)
        {
            Check.NotNull(entity, "entity");

            ChangeTracker.Entry(entity).State = EntityState.Modified;

            return entity;
        }
Ejemplo n.º 5
0
        public void Members_check_arguments()
        {
            Assert.Equal(
                "stateManager",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws <ArgumentNullException>(() => new ChangeTracker(null, null)).ParamName);

            var changeTracker = new ChangeTracker(Mock.Of <StateManager>(), Mock.Of <ChangeDetector>());

            Assert.Equal(
                "entity",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws <ArgumentNullException>(() => changeTracker.Entry(null)).ParamName);
            Assert.Equal(
                "entity",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws <ArgumentNullException>(() => changeTracker.Entry <Random>(null)).ParamName);
        }
Ejemplo n.º 6
0
        public void Members_check_arguments()
        {
            Assert.Equal(
                "stateManager",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => new ChangeTracker(null, null)).ParamName);

            var changeTracker = new ChangeTracker(Mock.Of<StateManager>(), Mock.Of<ChangeDetector>());

            Assert.Equal(
                "entity",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => changeTracker.Entry(null)).ParamName);
            Assert.Equal(
                "entity",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => changeTracker.Entry<Random>(null)).ParamName);
        }