public void Creates_mixed_entry_when_entity_CLR_entity_type_and_shadow_properties()
        {
            var entityType = new EntityType(typeof(RedHook));

            entityType.AddProperty("Long", typeof(int));
            entityType.AddProperty("Hammer", typeof(string), shadowProperty: true, concurrencyToken: false);

            var servicesMock = new Mock <ContextServices>();

            servicesMock.Setup(m => m.ClrPropertyGetterSource).Returns(new ClrPropertyGetterSource());
            var configurationMock = new Mock <DbContextConfiguration>();

            configurationMock.Setup(m => m.Services).Returns(servicesMock.Object);

            var entity = new RedHook();
            var entry  = new StateEntryFactory(
                configurationMock.Object,
                new EntityMaterializerSource(new MemberMapper(new FieldMatcher()))).Create(entityType, entity);

            Assert.IsType <MixedStateEntry>(entry);

            Assert.Same(configurationMock.Object, entry.Configuration);
            Assert.Same(entityType, entry.EntityType);
            Assert.Same(entity, entry.Entity);
        }
        public StateManager(
            [NotNull] StateEntryFactory factory,
            [NotNull] EntityKeyFactorySource entityKeyFactorySource,
            [NotNull] StateEntrySubscriber subscriber,
            [NotNull] StateEntryNotifier notifier,
            [NotNull] ValueGenerationManager valueGeneration,
            [NotNull] DbContextService <IModel> model,
            [NotNull] DbContextService <DataStore> dataStore)
        {
            Check.NotNull(factory, "factory");
            Check.NotNull(entityKeyFactorySource, "entityKeyFactorySource");
            Check.NotNull(subscriber, "subscriber");
            Check.NotNull(notifier, "notifier");
            Check.NotNull(model, "model");
            Check.NotNull(dataStore, "dataStore");
            Check.NotNull(valueGeneration, "valueGeneration");

            _keyFactorySource = entityKeyFactorySource;
            _factory          = factory;
            _subscriber       = subscriber;
            _notifier         = notifier;
            _valueGeneration  = valueGeneration;
            _model            = model;
            _dataStore        = dataStore;
        }
        public void Creates_mixed_entry_from_value_buffer_when_entity_CLR_entity_type_and_shadow_properties()
        {
            var entityType = new EntityType(typeof(RedHook));
            var property1  = entityType.AddProperty("Long", typeof(int));
            var property2  = entityType.AddProperty("Hammer", typeof(string), shadowProperty: true, concurrencyToken: false);

            var servicesMock = new Mock <ContextServices>();

            servicesMock.Setup(m => m.ClrPropertyGetterSource).Returns(new ClrPropertyGetterSource());
            var configurationMock = new Mock <DbContextConfiguration>();

            configurationMock.Setup(m => m.Services).Returns(servicesMock.Object);

            var entry = new StateEntryFactory(configurationMock.Object, new EntityMaterializerSource(new MemberMapper(new FieldMatcher())))
                        .Create(entityType, new ObjectArrayValueReader(new object[] { "Green", 77 }));

            Assert.IsType <MixedStateEntry>(entry);

            Assert.Same(configurationMock.Object, entry.Configuration);
            Assert.Same(entityType, entry.EntityType);
            Assert.Equal(77, entry[property1]);
            Assert.Equal("Green", entry[property2]);

            var entity = (RedHook)entry.Entity;

            Assert.Equal(77, entity.Long);
            Assert.Null(entity.Hammer);
        }
 public ThrowingMonsterStateManager(
     DbContextConfiguration configuration,
     StateEntryFactory factory,
     EntityKeyFactorySource entityKeyFactorySource,
     StateEntrySubscriber subscriber)
     : base(configuration, factory, entityKeyFactorySource, subscriber)
 {
 }
示例#5
0
        public StateManager(
            [NotNull] DbContextConfiguration configuration,
            [NotNull] StateEntryFactory factory,
            [NotNull] EntityKeyFactorySource entityKeyFactorySource,
            [NotNull] StateEntrySubscriber subscriber)
        {
            Check.NotNull(entityKeyFactorySource, "entityKeyFactorySource");
            Check.NotNull(factory, "factory");
            Check.NotNull(entityKeyFactorySource, "entityKeyFactorySource");

            _configuration    = configuration;
            _keyFactorySource = entityKeyFactorySource;
            _factory          = factory;
            _subscriber       = subscriber;
        }
        public StateManager(
            [NotNull] DbContextConfiguration configuration,
            [NotNull] StateEntryFactory factory,
            [NotNull] EntityKeyFactorySource entityKeyFactorySource,
            [NotNull] StateEntrySubscriber subscriber)
        {
            Check.NotNull(configuration, "configuration");
            Check.NotNull(factory, "factory");
            Check.NotNull(entityKeyFactorySource, "entityKeyFactorySource");
            Check.NotNull(subscriber, "subscriber");

            _configuration = configuration;
            _keyFactorySource = entityKeyFactorySource;
            _factory = factory;
            _subscriber = subscriber;
        }
        public void Creates_shadow_state_only_entry_when_entity_is_fully_shadow_state()
        {
            var entityType = new EntityType("RedHook");
            entityType.AddProperty("Long", typeof(int), shadowProperty: true, concurrencyToken: false);
            entityType.AddProperty("Hammer", typeof(string), shadowProperty: true, concurrencyToken: false);

            var servicesMock = new Mock<ContextServices>();
            servicesMock.Setup(m => m.ClrPropertyGetterSource).Returns(new ClrPropertyGetterSource());
            var configurationMock = new Mock<DbContextConfiguration>();
            configurationMock.Setup(m => m.Services).Returns(servicesMock.Object);

            var entry = new StateEntryFactory(
                configurationMock.Object,
                new EntityMaterializerSource(new MemberMapper(new FieldMatcher()))).Create(entityType, new Random());

            Assert.IsType<ShadowStateEntry>(entry);

            Assert.Same(configurationMock.Object, entry.Configuration);
            Assert.Same(entityType, entry.EntityType);
            Assert.Null(entry.Entity);
        }
        public void Creates_CLR_only_entry_when_entity_has_no_shadow_properties()
        {
            var entityType = new EntityType(typeof(RedHook));
            entityType.AddProperty("Long", typeof(int));
            entityType.AddProperty("Hammer", typeof(string));

            var servicesMock = new Mock<ContextServices>();
            servicesMock.Setup(m => m.ClrPropertyGetterSource).Returns(new ClrPropertyGetterSource());
            var configurationMock = new Mock<DbContextConfiguration>();
            configurationMock.Setup(m => m.Services).Returns(servicesMock.Object);

            var entity = new RedHook();
            var entry = new StateEntryFactory(
                configurationMock.Object,
                new EntityMaterializerSource(new MemberMapper(new FieldMatcher()))).Create(entityType, entity);

            Assert.IsType<ClrStateEntry>(entry);

            Assert.Same(configurationMock.Object, entry.Configuration);
            Assert.Same(entityType, entry.EntityType);
            Assert.Same(entity, entry.Entity);
        }
        public void Creates_mixed_entry_from_value_buffer_when_entity_CLR_entity_type_and_shadow_properties()
        {
            var entityType = new EntityType(typeof(RedHook));
            var property1 = entityType.AddProperty("Long", typeof(int));
            var property2 = entityType.AddProperty("Hammer", typeof(string), shadowProperty: true, concurrencyToken: false);

            var servicesMock = new Mock<ContextServices>();
            servicesMock.Setup(m => m.ClrPropertyGetterSource).Returns(new ClrPropertyGetterSource());
            var configurationMock = new Mock<DbContextConfiguration>();
            configurationMock.Setup(m => m.Services).Returns(servicesMock.Object);

            var entry = new StateEntryFactory(configurationMock.Object, new EntityMaterializerSource(new MemberMapper(new FieldMatcher())))
                .Create(entityType, new ObjectArrayValueReader(new object[] { "Green", 77 }));

            Assert.IsType<MixedStateEntry>(entry);

            Assert.Same(configurationMock.Object, entry.Configuration);
            Assert.Same(entityType, entry.EntityType);
            Assert.Equal(77, entry[property1]);
            Assert.Equal("Green", entry[property2]);

            var entity = (RedHook)entry.Entity;
            Assert.Equal(77, entity.Long);
            Assert.Null(entity.Hammer);
        }