コード例 #1
0
        public async Task Test_CreateAsMaximum_LoadAndCheckEqual()
        {
            var p0 = new TrackableTypeTestPoco();

            p0.Id                = 4;
            p0.ValBool           = true;
            p0.ValByte           = byte.MaxValue;
            p0.ValShort          = short.MaxValue;
            p0.ValChar           = char.MaxValue;
            p0.ValInt            = int.MaxValue;
            p0.ValLong           = long.MaxValue;
            p0.ValFloat          = float.MaxValue;
            p0.ValDouble         = double.MaxValue;
            p0.ValDecimal        = decimal.MaxValue;
            p0.ValDateTime       = DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc);
            p0.ValDateTimeOffset = DateTimeOffset.MaxValue;
            p0.ValTimeSpan       = TimeSpan.MaxValue;
            p0.ValString         = "\xAC00\xD7A3";
            p0.ValBytes          = new byte[] { 0, 127, 255 };
            p0.ValGuid           = new Guid(0xFFFFFFFF, 0xFFFF, 0xFFFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
            p0.ValEnum           = (TestEnum)0xFF;

            OnDataInitialized(p0);
            await CreateAsync(p0);

            var p1 = await LoadAsync(p0.Id);

            AssertEqual(p0, p1);
        }
コード例 #2
0
        public async Task Test_CreateAsMinimum_LoadAndCheckEqual()
        {
            var p0 = new TrackableTypeTestPoco();

            p0.Id                = 3;
            p0.ValBool           = false;
            p0.ValByte           = byte.MinValue;
            p0.ValShort          = short.MinValue;
            p0.ValChar           = char.MinValue;
            p0.ValInt            = int.MinValue;
            p0.ValLong           = long.MinValue;
            p0.ValFloat          = float.MinValue;
            p0.ValDouble         = double.MinValue;
            p0.ValDecimal        = decimal.MinValue;
            p0.ValDateTime       = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc);
            p0.ValDateTimeOffset = DateTimeOffset.MinValue;
            p0.ValTimeSpan       = TimeSpan.MinValue;
            p0.ValString         = "0";
            p0.ValBytes          = new byte[] { 0 };
            p0.ValGuid           = Guid.Empty;
            p0.ValEnum           = (TestEnum)0;

            OnDataInitialized(p0);
            await CreateAsync(p0);

            var p1 = await LoadAsync(p0.Id);

            AssertEqual(p0, p1);
        }
コード例 #3
0
        public async Task Test_CreateAsZero_LoadAndCheckEqual()
        {
            var p0 = new TrackableTypeTestPoco();

            p0.Id = 1;

            OnDataInitialized(p0);
            await CreateAsync(p0);

            var p1 = await LoadAsync(p0.Id);

            AssertEqual(p0, p1);
        }
コード例 #4
0
        public async Task Test_CreateAsZero_SaveAsIdentity()
        {
            var p0 = new TrackableTypeTestPoco();

            p0.Id = 5;

            OnDataInitialized(p0);
            await CreateAsync(p0);

            p0.SetDefaultTracker();
            SetIdentity(p0);
            OnDataInitialized(p0);
            await SaveAsync(p0);

            var p1 = await LoadAsync(p0.Id);

            AssertEqual(p0, p1);
        }
コード例 #5
0
 private void AssertEqual(TrackableTypeTestPoco p0, TrackableTypeTestPoco p1)
 {
     Assert.Equal(p0.ValBool, p1.ValBool);
     Assert.Equal(p0.ValByte, p1.ValByte);
     Assert.Equal(p0.ValShort, p1.ValShort);
     Assert.Equal(p0.ValChar, p1.ValChar);
     Assert.Equal(p0.ValInt, p1.ValInt);
     Assert.Equal(p0.ValLong, p1.ValLong);
     Assert.Equal(p0.ValFloat, p1.ValFloat);
     Assert.Equal(p0.ValDouble, p1.ValDouble);
     Assert.Equal(p0.ValDecimal, p1.ValDecimal);
     Assert.Equal(p0.ValDateTime, p1.ValDateTime);
     Assert.Equal(p0.ValDateTimeOffset, p1.ValDateTimeOffset);
     Assert.Equal(p0.ValTimeSpan, p1.ValTimeSpan);
     Assert.Equal(p0.ValString, p1.ValString);
     Assert.Equal(p0.ValBytes, p1.ValBytes);
     Assert.Equal(p0.ValGuid, p1.ValGuid);
     Assert.Equal(p0.ValEnum, p1.ValEnum);
 }
コード例 #6
0
 private void SetIdentity(TrackableTypeTestPoco p0)
 {
     p0.ValBool           = true;
     p0.ValByte           = 1;
     p0.ValShort          = 1;
     p0.ValChar           = '\x1';
     p0.ValInt            = 1;
     p0.ValLong           = 1;
     p0.ValFloat          = 1;
     p0.ValDouble         = 1;
     p0.ValDecimal        = 1;
     p0.ValDateTime       = new DateTime(2001, 1, 1, 1, 1, 1, DateTimeKind.Utc);
     p0.ValDateTimeOffset = new DateTimeOffset(2001, 1, 1, 1, 1, 1, TimeSpan.FromHours(1));
     p0.ValTimeSpan       = new TimeSpan(1, 1, 1);
     p0.ValString         = "1";
     p0.ValBytes          = new byte[] { 1 };
     p0.ValGuid           = new Guid(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
     p0.ValEnum           = TestEnum.Spade;
 }
コード例 #7
0
ファイル: TypeTest.cs プロジェクト: SaladLab/TrackableData
        protected override void OnDataInitialized(TrackableTypeTestPoco data)
        {
            base.OnDataInitialized(data);

            if (data.ValInt == int.MinValue)
            {
                // just arbitrary value for float, double, decimal
                data.ValFloat = -9999.99f;
                data.ValDouble = -99999.99;
                data.ValDecimal = -999999.99m;

                // 1000-01-01 is minimum value of mysql datetime
                data.ValDateTime = new DateTime(1000, 1, 1, 0, 0, 0);
                data.ValDateTimeOffset = new DateTimeOffset(1000, 1, 1, 0, 0, 0, TimeSpan.Zero);

                // 00:00:00 is minimum value of mysql
                data.ValTimeSpan = new TimeSpan(0, 0, 0);
            }
            else if (data.ValInt == int.MaxValue)
            {
                // just arbitrary value for float, double, decimal
                data.ValFloat = 9999.99f;
                data.ValDouble = 99999.99;
                data.ValDecimal = 999999.99m;

                // 9999-12-31 is maxmimum value of all sql engines
                data.ValDateTime = new DateTime(9999, 12, 31, 23, 59, 59, 999);

                // 9999-12-30 is used to make PostgreSql pass test
                // (PostgreSql translates utc date to local date while passing value to .NET,
                //  which may causes overflow.)
                data.ValDateTimeOffset = new DateTimeOffset(9999, 12, 30, 23, 59, 59, 999, TimeSpan.Zero);

                // 23:59:59 is maximum value of mysql
                data.ValTimeSpan = new TimeSpan(0, 23, 59, 59, 999);
            }
            else if (data.ValInt == 1)
            {
                data.ValDateTime = new DateTime(2001, 1, 1, 1, 1, 1);
                data.ValDateTimeOffset = new DateTimeOffset(2001, 1, 1, 1, 1, 1, TimeSpan.Zero);
            }
        }
コード例 #8
0
        public TrackableTypeTestPoco Clone()
        {
            var o = new TrackableTypeTestPoco();

            o._Id                = _Id;
            o._ValBool           = _ValBool;
            o._ValByte           = _ValByte;
            o._ValShort          = _ValShort;
            o._ValChar           = _ValChar;
            o._ValInt            = _ValInt;
            o._ValLong           = _ValLong;
            o._ValFloat          = _ValFloat;
            o._ValDouble         = _ValDouble;
            o._ValDecimal        = _ValDecimal;
            o._ValDateTime       = _ValDateTime;
            o._ValDateTimeOffset = _ValDateTimeOffset;
            o._ValTimeSpan       = _ValTimeSpan;
            o._ValString         = _ValString;
            o._ValBytes          = _ValBytes;
            o._ValGuid           = _ValGuid;
            o._ValEnum           = _ValEnum;
            return(o);
        }
コード例 #9
0
 protected virtual void OnDataInitialized(TrackableTypeTestPoco data)
 {
 }
コード例 #10
0
 protected abstract Task SaveAsync(TrackableTypeTestPoco data);
コード例 #11
0
 public TrackableTypeTestPoco Clone()
 {
     var o = new TrackableTypeTestPoco();
     o._Id = _Id;
     o._ValBool = _ValBool;
     o._ValByte = _ValByte;
     o._ValShort = _ValShort;
     o._ValChar = _ValChar;
     o._ValInt = _ValInt;
     o._ValLong = _ValLong;
     o._ValFloat = _ValFloat;
     o._ValDouble = _ValDouble;
     o._ValDecimal = _ValDecimal;
     o._ValDateTime = _ValDateTime;
     o._ValDateTimeOffset = _ValDateTimeOffset;
     o._ValTimeSpan = _ValTimeSpan;
     o._ValString = _ValString;
     o._ValBytes = _ValBytes;
     o._ValGuid = _ValGuid;
     o._ValEnum = _ValEnum;
     return o;
 }
コード例 #12
0
ファイル: TypeTest.cs プロジェクト: SaladLab/TrackableData
 protected override Task SaveAsync(TrackableTypeTestPoco data)
 {
     return _mapper.SaveAsync(_db.Connection, data.Tracker);
 }
コード例 #13
0
ファイル: TypeTest.cs プロジェクト: SaladLab/TrackableData
 protected override Task CreateAsync(TrackableTypeTestPoco data)
 {
     return _mapper.CreateAsync(_db.Connection, data);
 }