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"); } }
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); }
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"); } }
public void key_types() { var generation = new HiloIdGeneration(typeof(Target), new HiloSettings()); generation.KeyTypes.ShouldHaveTheSameElementsAs(typeof(int), typeof(long)); }
public void arguments_just_returns_itself() { var generation = new HiloIdGeneration(typeof(Target), new HiloSettings()); generation.ToArguments().Single().ShouldBeSameAs(generation); }