示例#1
0
 public void HiloSettings(HiloSettings hilo)
 {
     if (IdStrategy is HiloIdGeneration)
     {
         IdStrategy = new HiloIdGeneration(DocumentType, hilo);
     }
     else
     {
         throw new InvalidOperationException(
                   $"DocumentMapping for {DocumentType.FullName} is using {IdStrategy.GetType().FullName} as its Id strategy so cannot override Hilo sequence configuration");
     }
 }
示例#2
0
        public void build_assignment_for_long()
        {
            var settings = new HiloSettings();

            var sequence  = Substitute.For <ISequence>();
            var sequences = Substitute.For <ISequences>();
            var schema    = Substitute.For <IDocumentSchema>();

            schema.Sequences.Returns(sequences);
            sequences.Hilo(typeof(Target), settings).Returns(sequence);

            var generation = new HiloIdGeneration(typeof(Target), settings);


            generation.Build <long>(schema).ShouldBeOfType <LongHiloGenerator>()
            .Sequence.ShouldBeSameAs(sequence);
        }
        public void build_assignment_for_long()
        {
            var settings = new HiloSettings();

            var sequence = Substitute.For<ISequence>();
            var sequences = Substitute.For<ISequences>();
            var schema = Substitute.For<IDocumentSchema>();

            schema.Sequences.Returns(sequences);
            sequences.Hilo(typeof(Target), settings).Returns(sequence);

            var generation = new HiloIdGeneration(typeof(Target), settings);


            generation.Build<long>(schema).ShouldBeOfType<LongHiloGenerator>()
                .Sequence.ShouldBeSameAs(sequence);
        }
示例#4
0
        private void assignIdStrategy(Type documentType, StoreOptions options)
        {
            var idType = IdMember.GetMemberType();

            if (idType == typeof(string))
            {
                IdStrategy = new StringIdGeneration();
            }
            else if (idType == typeof(Guid))
            {
                IdStrategy = new GuidIdGeneration();
            }
            else if (idType == typeof(int) || idType == typeof(long))
            {
                IdStrategy = new HiloIdGeneration(documentType, options.HiloSequenceDefaults);
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(documentType),
                                                      $"Marten cannot use the type {idType.FullName} as the Id for a persisted document. Use int, long, Guid, or string");
            }
        }
示例#5
0
        public void key_types()
        {
            var generation = new HiloIdGeneration(typeof(Target), new HiloSettings());

            generation.KeyTypes.ShouldHaveTheSameElementsAs(typeof(int), typeof(long));
        }
示例#6
0
        public void arguments_just_returns_itself()
        {
            var generation = new HiloIdGeneration(typeof(Target), new HiloSettings());

            generation.ToArguments().Single().ShouldBeSameAs(generation);
        }
 public void key_types()
 {
     var generation = new HiloIdGeneration(typeof(Target), new HiloSettings());
     generation.KeyTypes.ShouldHaveTheSameElementsAs(typeof(int), typeof(long));
 }