public void Returns_null_when_no_value_generation_configured()
        {
            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory<GuidValueGenerator>(),
                new SimpleValueGeneratorFactory<TemporaryValueGenerator>(),
                new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor()),
                new SimpleValueGeneratorFactory<SequentialGuidValueGenerator>());

            Assert.Null(selector.Select(CreateProperty(typeof(int), ValueGenerationOnAdd.None)));
        }
        public void Returns_sequential_GUID_generator_for_GUID_types_setup_for_client_values()
        {
            var sequentialGuidFactory = new SimpleValueGeneratorFactory<SequentialGuidValueGenerator>();

            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory<GuidValueGenerator>(),
                new SimpleValueGeneratorFactory<TemporaryValueGenerator>(),
                new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor()),
                sequentialGuidFactory);

            Assert.Same(sequentialGuidFactory, selector.Select(CreateProperty(typeof(Guid), ValueGenerationOnAdd.Client)));
        }
        public void Returns_in_temp_generator_for_all_integer_types_except_byte_setup_for_client_values()
        {
            var tempFactory = new SimpleValueGeneratorFactory<TemporaryValueGenerator>();

            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory<GuidValueGenerator>(),
                tempFactory,
                new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor()),
                new SimpleValueGeneratorFactory<SequentialGuidValueGenerator>());

            Assert.Same(tempFactory, selector.Select(CreateProperty(typeof(long), ValueGenerationOnAdd.Client)));
            Assert.Same(tempFactory, selector.Select(CreateProperty(typeof(int), ValueGenerationOnAdd.Client)));
            Assert.Same(tempFactory, selector.Select(CreateProperty(typeof(short), ValueGenerationOnAdd.Client)));
        }
        public void Throws_for_unsupported_combinations()
        {
            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory<GuidValueGenerator>(),
                new SimpleValueGeneratorFactory<TemporaryValueGenerator>(),
                new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor()),
                new SimpleValueGeneratorFactory<SequentialGuidValueGenerator>());

            var typeMock = new Mock<IEntityType>();
            typeMock.Setup(m => m.Name).Returns("AnEntity");

            var property = CreateProperty(typeof(double), ValueGenerationOnAdd.Client);

            Assert.Equal(
                GetString("FormatNoValueGenerator", "client", "MyType", "MyProperty", "Double"),
                Assert.Throws<NotSupportedException>(() => selector.Select(property)).Message);
        }
        public void Throws_for_unsupported_combinations()
        {
            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory <GuidValueGenerator>(),
                new SimpleValueGeneratorFactory <TemporaryValueGenerator>(),
                new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor()),
                new SimpleValueGeneratorFactory <SequentialGuidValueGenerator>());

            var typeMock = new Mock <IEntityType>();

            typeMock.Setup(m => m.Name).Returns("AnEntity");

            var property = CreateProperty(typeof(double), ValueGenerationOnAdd.Client);

            Assert.Equal(
                GetString("FormatNoValueGenerator", "client", "MyType", "MyProperty", "Double"),
                Assert.Throws <NotSupportedException>(() => selector.Select(property)).Message);
        }
        public void Throws_for_unsupported_combinations()
        {
            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory <GuidValueGenerator>(),
                new SimpleValueGeneratorFactory <TemporaryValueGenerator>(),
                new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory())),
                new SimpleValueGeneratorFactory <SequentialGuidValueGenerator>());

            var property = new BasicModelBuilder()
                           .Entity <Robot>()
                           .Property(e => e.String)
                           .GenerateValueOnAdd()
                           .Metadata;

            Assert.Equal(
                CoreStrings.NoValueGenerator("String", typeof(Robot).FullName, "String"),
                Assert.Throws <NotSupportedException>(() => selector.Select(property)).Message);
        }
        public void Returns_sequence_generator_when_explicitly_configured_on_model()
        {
            var sequenceFactory = new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory()));

            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory <GuidValueGenerator>(),
                new SimpleValueGeneratorFactory <TemporaryValueGenerator>(),
                sequenceFactory,
                new SimpleValueGeneratorFactory <SequentialGuidValueGenerator>());

            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <long>()));
            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <int>()));
            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <short>()));
            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <byte>()));
            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <long?>()));
            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <int?>()));
            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <short?>()));
            Assert.Same(sequenceFactory, selector.Select(CreateModelSequenceProperty <byte?>()));
        }
        public void Returns_null_when_no_value_generation_configured()
        {
            var selector = new SqlServerValueGeneratorSelector(
                new SimpleValueGeneratorFactory <GuidValueGenerator>(),
                new SimpleValueGeneratorFactory <TemporaryValueGenerator>(),
                new SqlServerSequenceValueGeneratorFactory(new SqlStatementExecutor(new LoggerFactory())),
                new SimpleValueGeneratorFactory <SequentialGuidValueGenerator>());

            var property = new BasicModelBuilder()
                           .Entity <Robot>()
                           .Property(e => e.Int32)
                           .Metadata;

            Assert.Null(selector.Select(property));

            property = new BasicModelBuilder()
                       .Entity <Robot>()
                       .Property(e => e.Int32)
                       .StoreComputed()
                       .Metadata;

            Assert.Null(selector.Select(property));
        }