Beispiel #1
0
        public void ResultWithCaseHelper()
        {
            var qry = SqlBuilder
                      .Select <UserGroup>()
                      .Result(x => new
            {
                Name = x.Name.Case(z => SqlCase.Case <UserGroup>(y => y.Id > 3, y => 3).Else(x => x.CreatedBy).End())
            });

            Assert.AreEqual(124, qry.CommandText.Length);
            Assert.AreEqual(2, qry.CommandParameters.Count);
        }
Beispiel #2
0
        public void CaseHelper()
        {
            var day = 4;
            var qry = SqlBuilder
                      .Select <DailySchedule>(x => new DailySchedule
            {
                Id = x.Id.Case(z => SqlCase.Case <DailySchedule>(x => 1)      //day
                               .When(x => 1, x => x.ID_DailyScheduleSun)
                               .When(x => 2, x => x.ID_DailyScheduleMon)
                               .When(x => 3, x => x.ID_DailyScheduleTue)
                               .When(x => 4, x => x.ID_DailyScheduleWed)
                               .When <User>((x, y) => y.Email, (x, y) => 1)
                               .When(x => 5, x => x.ID_DailyScheduleThu)
                               .When(x => 6, x => x.ID_DailyScheduleFri)
                               .When(x => 7, x => x.ID_DailyScheduleSat)
                               .End()),
                Name = x.Name.Case(z => SqlCase.Case <UserGroup>(x => day > 0, x => 3).Else(x => x.CreatedBy).End()),
            });

            //this result is dynamic since case param is from guid randomizer
            //Assert.AreEqual("SELECT CASE @Case713e01 WHEN @Case713e02 THEN [tDailySchedule].[ID_DailyScheduleSun] WHEN @Case713e03 THEN [tDailySchedule].[ID_DailyScheduleMon] WHEN @Case713e04 THEN [tDailySchedule].[ID_DailyScheduleTue] WHEN @Case713e05 THEN [tDailySchedule].[ID_DailyScheduleWed] WHEN [Users].[Email] THEN @Case713e06 WHEN @Case713e07 THEN [tDailySchedule].[ID_DailyScheduleThu] WHEN @Case713e08 THEN [tDailySchedule].[ID_DailyScheduleFri] WHEN @Case713e09 THEN [tDailySchedule].[ID_DailyScheduleSat] END [Id], CASE WHEN (@Case5e6141 > @Case5e6142) THEN @Case5e6143 ELSE [UsersGroup].[CreatedBy] END [Name] FROM [tDailySchedule]", qry.CommandText);
            Assert.AreEqual(12, qry.CommandParameters.Count);
        }