public async Task TestEntity_ConvertValuesWithDecimalOverflow_Fails() { var sql = $"SELECT `t`.`Id`, `t`.`ByteCol`, `t`.`DecimalCol`, `t`.`FloatCol`" + $"{Environment.NewLine}FROM `TestEntities` AS `t`{Environment.NewLine}" + $"WHERE `t`.`Id` = @__p_0{Environment.NewLine}LIMIT 1"; _fixture.SpannerMock.AddOrUpdateStatementResult(sql, StatementResult.CreateResultSet( new List <Tuple <V1.Type, string> > { new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Int64 }, "Id"), new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Int64 }, "ByteCol"), new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Numeric }, "DecimalCol"), new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Float64 }, "FloatCol"), }, new List <object[]> { new object[] { 1L, 1L, $"99999999999999999999999999999", 1d }, } )); using var db = new TypeConversionDbContext(ConnectionString); await Assert.ThrowsAsync <OverflowException>(() => db.TestEntities.FindAsync(1L).AsTask()); }
public async Task TestEntity_ConvertValuesWithFloatOverflow_Succeeds() { var sql = $"SELECT `t`.`Id`, `t`.`ByteCol`, `t`.`DecimalCol`, `t`.`FloatCol`" + $"{Environment.NewLine}FROM `TestEntities` AS `t`{Environment.NewLine}" + $"WHERE `t`.`Id` = @__p_0{Environment.NewLine}LIMIT 1"; _fixture.SpannerMock.AddOrUpdateStatementResult(sql, StatementResult.CreateResultSet( new List <Tuple <V1.Type, string> > { new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Int64 }, "Id"), new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Int64 }, "ByteCol"), new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Numeric }, "DecimalCol"), new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Float64 }, "FloatCol"), }, new List <object[]> { new object[] { 1L, 1L, "3.14", float.MaxValue * 2d }, } )); using var db = new TypeConversionDbContext(ConnectionString); var row = await db.TestEntities.FindAsync(1L); Assert.Equal(float.PositiveInfinity, row.FloatCol); }
public async Task TestEntity_ConvertValuesWithoutPrecisionLossOrOverflow_Succeeds() { var sql = $"SELECT `t`.`Id`, `t`.`ByteCol`, `t`.`DecimalCol`, `t`.`FloatCol`" + $"{Environment.NewLine}FROM `TestEntities` AS `t`{Environment.NewLine}" + $"WHERE `t`.`Id` = @__p_0{Environment.NewLine}LIMIT 1"; _fixture.SpannerMock.AddOrUpdateStatementResult(sql, StatementResult.CreateResultSet( new List <Tuple <V1.Type, string> > { new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Int64 }, "Id"), new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Int64 }, "ByteCol"), new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Numeric }, "DecimalCol"), new Tuple <V1.Type, string>(new V1.Type { Code = V1.TypeCode.Float64 }, "FloatCol"), }, new List <object[]> { new object[] { 1L, 1L, "3.14", 1.0d }, } )); using var db = new TypeConversionDbContext(ConnectionString); var row = await db.TestEntities.FindAsync(1L); Assert.Equal(1L, row.Id); Assert.Equal((byte)1, row.ByteCol); Assert.Equal(SpannerNumeric.Parse("3.14"), SpannerNumeric.FromDecimal(row.DecimalCol, LossOfPrecisionHandling.Truncate)); Assert.Equal(1.0d, row.FloatCol); }