public void AddSchema_TransitivelyForwardIncompatibleWithOlderSchemas_ShouldReturnRuleViolations() { this.ruleMock .Setup(rule => rule.Validate(It.Is <ProtoBufSchema>(schema => schema.Version == Version.Initial.Next()), It.IsAny <ProtoBufSchema>())) .Returns(new ValidationResult(true, this.fixture.Create <string>())); this.ruleMock .Setup(rule => rule.Validate(It.Is <ProtoBufSchema>(schema => schema.Version == Version.Initial), It.IsAny <ProtoBufSchema>())) .Returns(new ValidationResult(false, this.fixture.Create <string>())); this.schemaFactoryMock .Setup(factory => factory.CreateNew(It.IsAny <Version>(), It.IsAny <string>())) .Returns(new ProtoBufSchema(Guid.NewGuid(), Version.Initial.Next().Next(), string.Empty)); var groupId = this.fixture.Create <Guid>(); var firstSchema = new ProtoBufSchema(Guid.NewGuid(), Version.Initial, string.Empty); var previousSchema = new ProtoBufSchema(Guid.NewGuid(), Version.Initial.Next(), string.Empty); var schemaGroup = new SchemaGroup <FileDescriptorSet>( groupId, this.fixture.Create <string>(), new List <Schema <FileDescriptorSet> > { firstSchema, previousSchema }, new List <Rule <FileDescriptorSet> > { this.ruleMock.Object }); var config = new ConfigurationSet( this.fixture.Create <Guid>(), new Dictionary <RuleCode, RuleConfig> { { RuleCode.R0001, new RuleConfig(false, Severity.Error) }, }, groupId, false, true, false, true); IEnumerable <RuleViolation> ruleViolations = schemaGroup.AddSchema( this.fixture.Create <string>(), config, this.schemaFactoryMock.Object); Assert.NotEmpty(ruleViolations); }
public void AddSchema_WithBackwardIncompatibleContentsAndDisabledBackwardCompatibility_ShouldAddSchema() { this.ruleMock .Setup(rule => rule.Validate(It.IsAny <ProtoBufSchema>(), It.Is <ProtoBufSchema>(schema => schema.Version == Version.Initial))) .Returns(new ValidationResult(false, this.fixture.Create <string>())); this.ruleMock .Setup(rule => rule.Validate(It.Is <ProtoBufSchema>(schema => schema.Version == Version.Initial), It.IsAny <ProtoBufSchema>())) .Returns(new ValidationResult(true, this.fixture.Create <string>())); this.schemaFactoryMock .Setup(factory => factory.CreateNew(It.IsAny <Version>(), It.IsAny <string>())) .Returns(new ProtoBufSchema(Guid.NewGuid(), Version.Initial.Next().Next(), string.Empty)); var groupId = this.fixture.Create <Guid>(); var firstSchema = new ProtoBufSchema(Guid.NewGuid(), Version.Initial, string.Empty); var schemaGroup = new SchemaGroup <FileDescriptorSet>( groupId, this.fixture.Create <string>(), new List <Schema <FileDescriptorSet> > { firstSchema }, new List <Rule <FileDescriptorSet> > { this.ruleMock.Object }); var config = new ConfigurationSet( this.fixture.Create <Guid>(), new Dictionary <RuleCode, RuleConfig> { { RuleCode.R0001, new RuleConfig(false, Severity.Error) }, }, groupId, false, true, false, false); schemaGroup.AddSchema( this.fixture.Create <string>(), config, this.schemaFactoryMock.Object); Assert.Equal(2, schemaGroup.Schemas.Count); }
public void AddSchema_ToGroupWithoutSchemas_ShouldAddSchemaWithInitialVersion() { var schemaGroup = new SchemaGroup <FileDescriptorSet>(this.fixture.Create <string>()); var contents = this.fixture.Create <string>(); var config = new ConfigurationSet( Guid.NewGuid(), new Dictionary <RuleCode, RuleConfig>(), schemaGroup.Id, true, true, true, true); schemaGroup.AddSchema( contents, config, this.schemaFactoryMock.Object); this.schemaFactoryMock.Verify( factory => factory.CreateNew(Version.Initial, contents), "New schema should have initial version when the schema group doesn't have any schemas"); }