public static string GetDescription(this TimeEntryTypeEnum type) { var memberInfos = type.GetType().GetMember(type.ToString()); var attribute = memberInfos[0].GetCustomAttributes(typeof(DescriptionAttribute), false); var description = ((DescriptionAttribute)attribute.ElementAt(0)).Description; return(description); }
public void InterpretDeleteMessage_canInterpretDifferentTimeTypeDeletion(TimeEntryTypeEnum timeEntryType) { var sut = new DeleteInterpreter().InterpretMessage(ToPayload("delete " + timeEntryType.GetDescription())); var now = DateTime.UtcNow; sut.Date.Year.Should().Be(now.Year); sut.Date.Month.Should().Be(now.Month); sut.Date.Day.Should().Be(now.Day); sut.TimeEntryType.Should().Be(timeEntryType); }
private async Task StoreTimeEntryOnFirstDayOfMonth(TimeEntryTypeEnum entryType, User user, int hours, int month) { var timeEntry = new TimeEntry { Hours = hours, Date = new DateTime(DateTime.UtcNow.Year, month, 1), TimeEntryType = entryType, User = user }; database.TimeEntries.Add(timeEntry); await database.SaveChangesAsync(); }
HandleCommand_deleteHoursTypeDefaultDay_returnsDeletedMessage_andOnlyDeletesHoursForThatTypeToday( TimeEntryTypeEnum entryType, int hours, int numEntriesToDelete) { var user = database.Users.First(); var date = DateTime.UtcNow.Date; var timeEntryService = new TimeEntryService(user.UserId, database); await SetUpHourEntriesAndDays(timeEntryService, date); var numEntries = database.TimeEntries.Count(); var slackMessage = await orchestrator.HandleCommand(new SlashCommandPayload() { text = "delete " + entryType.GetDescription(), user_id = user.SlackUserId, user_name = user.UserName }); slackMessage.Text.Should().Be($"Deleted {hours:F1} {entryType} hours for date: {date:D}"); database.TimeEntries.Count().Should().Be(numEntries - numEntriesToDelete); database.TimeEntries.Where(x => x.UserId == user.UserId).Sum(x => x.Hours).Should().Be(33 - hours); database.TimeEntries.Where(x => x.UserId == user.UserId && x.TimeEntryType == entryType && x.Date == date) .ToList().Count.Should().Be(0); }
public async Task WhenDeletingNonBillableHoursOnADay_AllNonBillableHoursOnThatDayAreDeleted(TimeEntryTypeEnum entryType, double hours) { var date = DateTime.UtcNow.AddDays(-2); await timeEntryService.CreateBillableTimeEntry(DateTime.UtcNow, 4, 1); await timeEntryService.CreateBillableTimeEntry(date, 1, 1); await timeEntryService.CreateNonBillableTimeEntry(date, 4, "beach", TimeEntryTypeEnum.NonBillable); await timeEntryService.CreateNonBillableTimeEntry(date, 3, "flu", TimeEntryTypeEnum.Sick); await timeEntryService.CreateNonBillableTimeEntry(date, 2, null, TimeEntryTypeEnum.Vacation); var hoursDeleted = await timeEntryService.DeleteHoursForTimeEntryType(date.Date, entryType); var timeEntries = await database.TimeEntries.Where(x => x.UserId == userId).ToListAsync(); var hoursLeft = timeEntries.Sum(x => x.Hours); hoursLeft.Should().Be(14 - hours); hoursDeleted.Should().Be(hours); }
public async Task WhenTimeEntryStoredOnFirstDayOfYear_ThenItGetsDisplayedInReportYtd(TimeEntryTypeEnum entryType, string reportText) { var user = database.Users.First(); await StoreTimeEntryOnFirstDayOfMonth(entryType, user, 8, 1); var response = await RequestReport(user); response.Text.Should().Contain($"{DateTime.UtcNow.Year} Total {reportText} Hours: 8.0"); }
public async Task WhenTimeEntryStoredOnFirstOfMonth_ThenItGetsDisplayedInReportCurrentMonth(TimeEntryTypeEnum entryType, string reportText) { var user = database.Users.First(); var now = DateTime.UtcNow; await StoreTimeEntryOnFirstDayOfMonth(entryType, user, 8, now.Month); var response = await RequestReport(user); response.Text.Should().Contain($"{now:MMMM yyyy} {reportText} Hours: 8.0"); }
public void GetDescription_ReturnsMatchingStringToEnum(TimeEntryTypeEnum type, string name) { type.GetDescription().Should().Be(name); }