public void GetById_Should_Return_ListItem() { using (var mock = AutoMock.GetLoose()) { // Arrange var dummy = new ListItemDto() { Id = 1, Name = "Henk", Description = "ABC", CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow, Status = "Available" }; mock.Mock <IListItemRepository>() .Setup(srv => srv.GetById(It.IsAny <int>())) .Returns <int>(id => dummy); // Sut var sut = mock.Create <ListItemService>(); // Act var actual = sut.GetById("1"); // Assert mock.Mock <IListItemRepository>().Verify(x => x.GetById(It.IsAny <int>())); // ToDo SR write cool equal //actual.Result.Should().Be(dummy) actual.Result.Id.Should().Be(dummy.Id); } }
public void TryJoinTianXuan(ListItemDto target) { _logger.LogInformation("开始检查直播间:{name}({id})", target.Title, target.Roomid); try { CheckTianXuanDto check = _liveApi.CheckTianXuan(target.Roomid) .GetAwaiter().GetResult() .Data; if (check == null) { _logger.LogInformation("数据异常,跳过"); return; } _logger.LogInformation("奖励:{name},条件:{text}", check.Award_name, check.Require_text); if (check.Status != 1) { _logger.LogInformation("已开奖,跳过\r\n"); return; } if (check.Gift_price != 0) { _logger.LogInformation("需要赠送礼物才能参与,跳过\r\n"); return; } var request = new JoinTianXuanRequest { Id = check.Id, Gift_id = check.Gift_id, Gift_num = check.Gift_num, Csrf = _biliCookie.BiliJct }; var re = _liveApi.Join(request) .GetAwaiter().GetResult(); if (re.Code == 0) { _logger.LogInformation("参与抽奖成功!\r\n"); return; } _logger.LogInformation("参与抽奖失败,原因:{msg}\r\n", re.Message); } catch (Exception ex) { _logger.LogWarning("发生异常:{msg},{detail}\r\n", ex.Message, ex); //ignore } }
public void TryJoinTianXuan(ListItemDto target) { _logger.LogInformation("【直播间】{name}({id})", target.Title, target.Roomid); try { CheckTianXuanDto check = _liveApi.CheckTianXuan(target.Roomid) .GetAwaiter().GetResult() .Data; if (check == null) { _logger.LogInformation("数据异常,跳过"); return; } if (check.Status != 1) { _logger.LogInformation("已开奖,跳过" + Environment.NewLine); return; } _logger.LogInformation("【奖励】{name}", check.Award_name); _logger.LogInformation("【条件】{text}", check.Require_text); _logger.LogInformation("【赠礼】{gift}", check.Gift_price > 0 ? check.GiftDesc : "无"); if (check.Gift_price != 0) { _logger.LogInformation("需赠送礼物,跳过" + Environment.NewLine); return; } //根据配置过滤 if (!check.AwardNameIsSatisfied(_liveLotteryTaskOptions.IncludeAwardNameList, _liveLotteryTaskOptions.ExcludeAwardNameList)) { _logger.LogInformation("不满足配置的筛选条件,跳过" + Environment.NewLine); return; } var request = new JoinTianXuanRequest { Id = check.Id, Gift_id = check.Gift_id, Gift_num = check.Gift_num, Csrf = _biliCookie.BiliJct }; var re = _liveApi.Join(request) .GetAwaiter().GetResult(); if (re.Code == 0) { _logger.LogInformation("【参与抽奖】成功 √" + Environment.NewLine); return; } _logger.LogInformation("【参与抽奖】失败"); _logger.LogInformation("【原因】{msg}" + Environment.NewLine, re.Message); } catch (Exception ex) { _logger.LogWarning("【异常】{msg},{detail}" + Environment.NewLine, ex.Message, ex); //ignore } }
public void TryJoinTianXuan(ListItemDto target) { _logger.LogDebug("【房间】{name}", target.Title); try { CheckTianXuanDto check = _liveApi.CheckTianXuan(target.Roomid) .GetAwaiter().GetResult() .Data; if (check == null) { _logger.LogDebug("数据异常,跳过"); return; } if (check.Status != TianXuanStatus.Enable) { _logger.LogDebug("已开奖,跳过" + Environment.NewLine); return; } //根据配置过滤 if (!check.AwardNameIsSatisfied(_liveLotteryTaskOptions.IncludeAwardNameList, _liveLotteryTaskOptions.ExcludeAwardNameList)) { _logger.LogDebug("不满足配置的筛选条件,跳过" + Environment.NewLine); return; } //是否需要赠礼 if (check.Gift_price > 0) { _logger.LogDebug("【赠礼】{gift}", check.GiftDesc); _logger.LogDebug("需赠送礼物,跳过" + Environment.NewLine); return; } //条件 if (check.Require_type != RequireType.None && check.Require_type != RequireType.Follow) { _logger.LogDebug("【条件】{text}", check.Require_text); _logger.LogDebug("要求粉丝勋章,跳过"); return; } _logger.LogInformation("【房间】{name}", target.ShortTitle); _logger.LogInformation("【主播】{name}({id})", target.Uname, target.Uid); _logger.LogInformation("【奖品】{name}【条件】{text}", check.Award_name, check.Require_text); var request = new JoinTianXuanRequest { Id = check.Id, Gift_id = check.Gift_id, Gift_num = check.Gift_num, Csrf = _biliCookie.BiliJct }; var re = _liveApi.Join(request) .GetAwaiter().GetResult(); if (re.Code == 0) { _logger.LogInformation("【抽奖】成功 √" + Environment.NewLine); if (check.Require_type == RequireType.Follow) { _tianXuanFollowed.AddIfNotExist(target, x => x.Uid == target.Uid); } return; } _logger.LogInformation("【抽奖】失败"); _logger.LogInformation("【原因】{msg}" + Environment.NewLine, re.Message); } catch (Exception ex) { _logger.LogWarning("【异常】{msg},{detail}" + Environment.NewLine, ex.Message, ex); //ignore } }