public void CompleteNullableKey() { using (var context = CreateMethodContext()) { context.KeepTestData = true; var record = new NullableElementsSample(); record.DataSet = context.DataSet; record.StringToken = "A"; record.BoolToken = true; record.IntToken = 123; record.LongToken = 12345678912345; record.LocalDateToken = new LocalDate(2003, 5, 1); record.LocalTimeToken = new LocalTime(10, 15, 30, 500); // 10:15:30.500 record.LocalMinuteToken = new LocalMinute(10, 15); // 10:15 record.LocalDateTimeToken = new LocalDateTime(2003, 5, 1, 10, 15, 30, 500); // 2003-05-01T10:15:30.500 record.InstantToken = new LocalDateTime(2003, 5, 1, 10, 15, 30, 500).ToInstant(DateTimeZone.Utc); // 2003-05-01T10:15:30.500Z record.EnumToken = SampleEnum.EnumValue2; // Verify key serialization context.Log.Verify(record.Key); // Verify key creation var key = record.ToKey(); context.Log.Verify(key.Value); // Save context.SaveOne(record, context.DataSet); // Load from storage var loadedRecord = context.LoadOrNull(key, context.DataSet); context.Log.Verify(loadedRecord.Key); } }
public void NullableElements() { using (var context = CreateMethodContext()) { for (int recordIndex = 0; recordIndex < 8; ++recordIndex) { int recordIndexMod2 = recordIndex % 2; int recordIndexMod4 = recordIndex % 4; var record = new NullableElementsSample(); record.RecordIndex = recordIndex; record.DataSet = context.DataSet; record.StringToken = "A" + recordIndexMod4.ToString(); record.BoolToken = recordIndexMod2 == 0; record.IntToken = recordIndexMod4; record.LongToken = recordIndexMod4; record.LocalDateToken = new LocalDate(2003, 5, 1).PlusDays(recordIndexMod4); record.LocalTimeToken = new LocalTime(10, 15, 30).PlusMinutes(recordIndexMod4); record.LocalMinuteToken = new LocalMinute(10, recordIndexMod4); record.LocalDateTimeToken = new LocalDateTime(2003, 5, 1, 10, 15).PlusDays(recordIndexMod4); record.InstantToken = new LocalDateTime(2003, 5, 1, 10, 15).PlusDays(recordIndexMod4).ToInstant(DateTimeZone.Utc); record.EnumToken = (SampleEnum)(recordIndexMod2 + 1); context.SaveOne(record, context.DataSet); } if (true) { // Query for all records without restrictions, // should return 4 out of 8 records because // each record has two versions var query = context.DataSource.GetQuery <NullableElementsSample>(context.DataSet); context.Log.Verify("Unconstrained query"); foreach (var obj in query.AsEnumerable()) { context.Log.Verify($" {obj.Key} (record index {obj.RecordIndex})."); } } if (true) { // Query for all records without restrictions, // should return 4 out of 8 records because // each record has two versions var query = context.DataSource.GetQuery <NullableElementsSample>(context.DataSet) .Where(p => p.StringToken == "A1") .Where(p => p.BoolToken == false) .Where(p => p.IntToken == 1) .Where(p => p.LongToken == 1) .Where(p => p.LocalDateToken == new LocalDate(2003, 5, 1).PlusDays(1)) .Where(p => p.LocalTimeToken == new LocalTime(10, 15, 30).PlusMinutes(1)) .Where(p => p.LocalMinuteToken == new LocalMinute(10, 1)) .Where(p => p.LocalDateTimeToken == new LocalDateTime(2003, 5, 1, 10, 15).PlusDays(1)) .Where(p => p.InstantToken == new LocalDateTime(2003, 5, 1, 10, 15).PlusDays(1).ToInstant(DateTimeZone.Utc)) .Where(p => p.EnumToken == (SampleEnum)2); context.Log.Verify("Constrained query"); foreach (var obj in query.AsEnumerable()) { context.Log.Verify($" {obj.Key} (record index {obj.RecordIndex})."); } } } }