public async Task CompleteOrders(CoffeeService coffee, User user, string text, SlackResponse response) { var orders = await coffee.CompleteOrderAsync(); var sb = new StringBuilder(); foreach (var o in orders) { sb.Append(SlackBot.Utils.UserIdToString(o.UserId)).Append(' '); } sb.Append("님 커피 가져가세요~"); // TODO: 왓카페 채널에 완성 명단을 알리기 response .Ephemeral("공지하였습니다.") .InChannel(sb.ToString(), "user"); }
public async void CoffeeService() { using var context = TestCoffeeContext.CreateContext(); context.SetUsers(); context.SetMenus(); await context.SaveChangesAsync(); var at = DateTime.Now; var service = new CoffeeService(context); // 이전 주문이 없어서 실패 await Assert.ThrowsAsync <BadRequestException>(() => service.MakeOrderAsync("id1", "", at)); // 없는 메뉴이기 때문에 실패 await Assert.ThrowsAsync <MenuNotFoundException>(() => service.MakeOrderAsync("id1", "없는메뉴", at)); var order = await service.MakeOrderAsync("id1", "메뉴1", at); await context.SaveChangesAsync(); at = at.AddSeconds(10); // 아직 추첨을 안했기 때문에 완성 실패 await Assert.ThrowsAsync <BadRequestException>(service.CompleteOrderAsync); var pickedOrders = await service.PickOrderAsync(10, at.AddSeconds(10)); await context.SaveChangesAsync(); at = at.AddSeconds(10); // 이미 추첨을 했기 때문에 추첨 불가 await Assert.ThrowsAsync <BadRequestException>(() => service.PickOrderAsync(10, at)); Assert.Single(pickedOrders); Assert.Equal("id1", pickedOrders[0].UserId); Assert.Equal("메뉴1", pickedOrders[0].MenuId); // 추가 신청 await service.MakeOrderAsync("id2", "메뉴2", at); await context.SaveChangesAsync(); at = at.AddSeconds(10); // 추가 추첨 var pickedMore = await service.PickMoreOrderAsync(2, at); await context.SaveChangesAsync(); Assert.Single(pickedMore); Assert.Equal("id2", pickedMore[0].UserId); var completedOrders = await service.CompleteOrderAsync(); await context.SaveChangesAsync(); Assert.Equal(2, completedOrders.Count); Assert.Equal("id1", completedOrders[0].UserId); Assert.Equal("메뉴1", completedOrders[0].MenuId); var orders = await context.Orders.ToListAsync(); Assert.Empty(orders); var completeds = await context.CompletedOrders.ToListAsync(); Assert.Equal(2, completeds.Count); var user = await context.Users.FindAsync("id1"); Assert.Equal(500, (int)user.Deposit); user = await context.Users.FindAsync("id2"); Assert.Equal(-500, (int)user.Deposit); }