public void ConstructorWithDescriptors_SingleImmediateEvaluation() { var sequence = new CountingSequence(); var descriptor = new ApiMetadata("Test", () => sequence); Assert.Equal(0, sequence.EvaluationCount); // Fetching the first time immediately evaluates the sequence var protobufDescriptors = descriptor.ProtobufDescriptors; Assert.Equal(1, sequence.EvaluationCount); // Using the returned list doesn't change the evaluation count Assert.Equal(0, protobufDescriptors.Count()); Assert.Equal(1, sequence.EvaluationCount); // Fetching a second time doesn't change the evaluation count protobufDescriptors = descriptor.ProtobufDescriptors; Assert.Equal(1, sequence.EvaluationCount); }
public void ConstructorWithDescriptorsProvider_LazyEvaluation() { var sequence = new CountingSequence(); var descriptor = new ApiMetadata("Test", sequence); // By the time the constructor returns, it's already evaluated the sequence. Assert.Equal(1, sequence.EvaluationCount); // Fetching the first time doesn't change the evaluation count var protobufDescriptors = descriptor.ProtobufDescriptors; Assert.Equal(1, sequence.EvaluationCount); // Using the returned list doesn't change the evaluation count Assert.Equal(0, protobufDescriptors.Count()); Assert.Equal(1, sequence.EvaluationCount); // Fetching a second time doesn't change the evaluation count protobufDescriptors = descriptor.ProtobufDescriptors; Assert.Equal(1, sequence.EvaluationCount); }