public void HasKey_should_add_key_properties() { var mockEntityTypeConfiguration = new Mock <EntityTypeConfiguration>(typeof(Fixture)); var entityConfiguration = new EntityTypeConfiguration <Fixture>(mockEntityTypeConfiguration.Object); mockEntityTypeConfiguration.Setup(e => e.Key(new[] { typeof(Fixture).GetDeclaredProperty("Id") })) .Throws(new Exception("Bang!")); var thrownException = Assert.Throws <Exception>( () => entityConfiguration.HasKey(f => f.Id)); Assert.Equal("Bang!", thrownException.Message); }