Last active
January 29, 2016 18:51
-
-
Save dgg/d3fc53652df5d591976b to your computer and use it in GitHub Desktop.
a-new-nmoneys-member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MonetaryQuantity | |
| { | |
| [Obsolete("serialization only")] | |
| private MonetaryQuantity() { } | |
| public MonetaryQuantity(Money money) | |
| { | |
| Currency = money.CurrencyCode.AlphabeticCode(); | |
| Amount = money.Amount; | |
| } | |
| public string Currency { get; private set; } | |
| public decimal Amount { get; private set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class MonetaryQuantityCanonicalConfigurator | |
| { | |
| public static void Configure(DbModelBuilder modelBuilder) | |
| { | |
| modelBuilder.ComplexType<MonetaryQuantity>() | |
| .Property(c => c.Currency) | |
| .IsFixedLength().HasMaxLength(3); | |
| modelBuilder.ComplexType<MonetaryQuantity>() | |
| .Property(c => c.Amount).HasPrecision(19, 4); | |
| } | |
| public static void ConfigureMonetaryQuantity(this DbModelBuilder modelBuilder) | |
| { | |
| Configure(modelBuilder); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TestDbConfiguration : DbConfiguration | |
| { | |
| public TestDbConfiguration() | |
| { | |
| string providerName = "System.Data.SqlServerCe.4.0"; | |
| SetProviderServices(providerName, SqlCeProviderServices.Instance); | |
| SetDefaultConnectionFactory(new SqlCeConnectionFactory(providerName)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [TestFixture] | |
| public class PersistenceTester | |
| { | |
| private FileInfo _dbFile; | |
| [TestFixtureSetUp] | |
| public void SetupDb() | |
| { | |
| _dbFile = new FileInfo("Test.sdf"); | |
| _dbFile.Delete(); | |
| } | |
| [TestFixtureTearDown] | |
| public void TearDownDb() | |
| { | |
| _dbFile.Delete(); | |
| } | |
| // .. tests using a DbContext that writes to that file | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment