Esempio n. 1
0
        public void MoneyPropertySizeAndDecimals()
        {
            using (var scope = TestScope.Create(builder =>
            {
                var options = new CommonConceptsRuntimeOptions()
                {
                    AutoRoundMoney = true
                };
                builder.RegisterInstance(options);
                builder.RegisterType <GenericRepositories>().AsImplementedInterfaces();
            }))
            {
                var context = scope.Resolve <Common.ExecutionContext>();

                var tests = new List <(decimal Save, decimal Load)>
                {
                    (-922337203685477.58m, -922337203685477.58m), // T-SQL money limits.
                    (922337203685477.58m, 922337203685477.58m),   // T-SQL money limits.
                    (0m, 0m),
                };

                foreach (var test in tests)
                {
                    var entity = new TestStorage.AllProperties
                    {
                        ID            = Guid.NewGuid(),
                        MoneyProperty = test.Save
                    };
                    context.PersistenceStorage.Insert(entity);
                    Assert.AreEqual(test.Load, context.Repository.TestStorage.AllProperties.Load(x => x.ID == entity.ID).Single().MoneyProperty,
                                    $"The money property should be cut off on the second decimal position ({test.Save}).");
                }
            }
        }
        public void AutoRoundOn()
        {
            using (var scope = TestScope.Create(builder =>
            {
                var options = new CommonConceptsRuntimeOptions()
                {
                    AutoRoundMoney = true
                };
                builder.RegisterInstance(options);
            }))
            {
                var context = scope.Resolve <Common.ExecutionContext>();
                var tests   = new List <(decimal ValueToWrite, decimal ExpectedPersistedValue)>()
                {
                    (0.001m, 0m),
                    (0.009m, 0m),
                    (0.019m, 0.01m),
                    (-0.001m, 0m),
                    (-0.009m, 0m),
                    (-0.019m, -0.01m),
                };

                foreach (var test in tests)
                {
                    var entity = new TestStorage.AllProperties
                    {
                        ID            = Guid.NewGuid(),
                        MoneyProperty = test.ValueToWrite
                    };
                    context.Repository.TestStorage.AllProperties.Save(new[] { entity }, null, null);
                    var actualPersistedValue = context.Repository.TestStorage.AllProperties.Load(x => x.ID == entity.ID).Single().MoneyProperty;

                    Assert.AreEqual(test.ExpectedPersistedValue, actualPersistedValue);
                }
            }
        }