public void Deserialize(IXunitSerializationInfo info) { String val = info.GetValue <String>("Value"); UserHabitRecordsControllerTestData_DailyNoOfCount other = JsonSerializer.Deserialize <UserHabitRecordsControllerTestData_DailyNoOfCount>(val); CompleteCondition = other.CompleteCondition; if (other.RuleList.Count > 0) { RuleList.AddRange(other.RuleList); } if (other.RecordList.Count > 0) { RecordList.AddRange(other.RecordList); } if (other.ExpectedRecordList.Count > 0) { ExpectedRecordList.AddRange(other.ExpectedRecordList); } }
public async Task CalculatePoints_Daily_NumberOfCount(UserHabitRecordsControllerTestData_DailyNoOfCount testData) { var context = this.fixture.GetCurrentDataContext(); UserHabitRecordsController control = new(context); // Add Habit, Habit Rule UserHabit habit = new UserHabit(); habit.TargetUser = DataSetupUtility.UserA; habit.ValidFrom = new DateTime(2021, 1, 1); habit.ValidTo = new DateTime(2022, 12, 31); habit.Name = "Habit_Daily_1"; habit.Category = HabitCategory.Positive; habit.Comment = habit.Name; habit.Frequency = HabitFrequency.Daily; habit.CompleteCategory = HabitCompleteCategory.NumberOfCount; habit.CompleteCondition = testData.CompleteCondition; context.UserHabits.Add(habit); context.SaveChanges(); Int32 nNewHabitID = habit.ID; foreach (var rule in testData.RuleList) { rule.HabitID = habit.ID; context.UserHabitRules.Add(rule); } context.SaveChanges(); // Add user record. foreach (var nrecord in testData.RecordList) { nrecord.HabitID = habit.ID; nrecord.Comment = "Test1"; var rst = control.Post(nrecord); Assert.NotNull(rst); if (rst != null) { CreatedODataResult <UserHabitRecord> rstrecord = (CreatedODataResult <UserHabitRecord>)rst.Result; Assert.NotNull(rstrecord); } } // Check on DB directly var dbrecords = (from dbrecord in context.UserHabitRecords where dbrecord.HabitID == habit.ID orderby dbrecord.RecordDate ascending select dbrecord).ToList(); Assert.Equal(testData.ExpectedRecordList.Count, dbrecords.Count); // Ensure rule is assigned correctly if (testData.ExpectedRecordList.Count > 0) { foreach (var dbrecord in dbrecords) { var ridx = testData.ExpectedRecordList.FindIndex(rd => rd.RecordDate == dbrecord.RecordDate && rd.SubID == dbrecord.SubID); Assert.NotEqual(-1, ridx); Assert.Equal(testData.ExpectedRecordList[ridx].RuleID, dbrecord.RuleID); Assert.Equal(testData.ExpectedRecordList[ridx].ContinuousCount, dbrecord.ContinuousCount); } } DataSetupUtility.ClearUserHabitData(context, nNewHabitID); context.SaveChanges(); await context.DisposeAsync(); }