public void should_create_context_with_preconfigured_schema() { var schema = new SchemaConfiguration(c => { c.FriendlyNameColumn = "Name"; c.IdColumn = "KeyId"; c.Table = "DataKeys"; c.XmlColumn = "KeyXml"; }); _context = new KeyStorageContext(_builder.Options, schema); var dataProtectionKeyEntity = _context.Model.FindEntityType(typeof(DataProtectionKey)); dataProtectionKeyEntity.ShouldNotBeNull(); dataProtectionKeyEntity.GetTableName().ShouldEqual("DataKeys"); var expectedProperties = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("FriendlyName", "Name"), new KeyValuePair <string, string>("Id", "KeyId"), new KeyValuePair <string, string>("Xml", "KeyXml") }; should_have_correct_properties(dataProtectionKeyEntity, expectedProperties); }
public void should_store_key() { var dataProtectionKey = new DataProtectionKey { FriendlyName = "Key1", Xml = "NotReallyXML" }; _context = new KeyStorageContext(_builder.Options); _context.DataProtectionKeys.Add(dataProtectionKey); _context.SaveChanges(); _context.DataProtectionKeys.Count().ShouldEqual(1); var updatedEntity = _context.DataProtectionKeys.Find(dataProtectionKey.Id); updatedEntity.FriendlyName.ShouldEqual(dataProtectionKey.FriendlyName); updatedEntity.Id.ShouldEqual(1); updatedEntity.Xml.ShouldEqual(dataProtectionKey.Xml); }
public DatabaseFixture(bool createSchema = true) { var configuration = new ConfigurationBuilder() .AddUserSecrets("57a04ea5-19b4-483f-af4d-a96930e166e5") .Build(); TestDatabase = new TestDatabaseBuilder() .WithConfiguration(configuration) .Build(); TestDatabase.Create(); var builder = new DbContextOptionsBuilder <KeyStorageContext>() .UseNpgsql(TestDatabase.ConnectionString); Context = new KeyStorageContext(builder.Options); if (createSchema) { Context.Database.EnsureCreated(); } }
public void Teardown() { _context = null; }