public void ProducesMetricHealthBadge(BadgeStatus status) { // Arrange var badgeService = new BadgeService(); var label = status == BadgeStatus.Success ? AutoLabels.Normal : ( status == BadgeStatus.Neutural ? AutoLabels.Warning : AutoLabels.Critical ); // Act var badge = badgeService .GetMetricHealthBadge( "the-source", Metrics.CpuLoad, label ); // Assert Assert.Equal(status, badge.Status); Assert.NotEqual(0, badge.TitleWidth); Assert.NotEqual(0, badge.MessageWidth); Assert.Contains("the-source", badge.Title.ToLower()); Assert.Contains(Metrics.CpuLoad.ToString().ToLower(), badge.Title.ToLower()); Assert.Contains(label.ToString().ToLower(), badge.Message.ToLower()); }
public void ProducesSystemHealthBadge(BadgeStatus status) { // Arrange var badgeService = new BadgeService(); var report = new Mock <HealthReport>(); report .SetupGet(rep => rep.Health) .Returns(status == BadgeStatus.Success ? 94 : (status == BadgeStatus.Neutural ? 81 : 56)); // Act var badge = badgeService.GetSystemHealthBadge(report.Object); // Assert Assert.Equal(status, badge.Status); Assert.NotEqual(0, badge.TitleWidth); Assert.NotEqual(0, badge.MessageWidth); switch (status) { case BadgeStatus.Success: Assert.Contains(94.ToString(), badge.Message); break; case BadgeStatus.Neutural: Assert.Contains(81.ToString(), badge.Message); break; case BadgeStatus.Failure: Assert.Contains(56.ToString(), badge.Message); break; } Assert.Equal("System health".ToLower(), badge.Title.ToLower()); }
public void ProducesUptimeBadge(BadgeStatus status) { // Act var badge = new BadgeService().GetUptimeBadge( "the-url.com", status == BadgeStatus.Success ? 98 : (status == BadgeStatus.Neutural ? 90 : 80) ); // Assert Assert.Equal(status, badge.Status); Assert.NotEqual(0, badge.TitleWidth); Assert.NotEqual(0, badge.MessageWidth); switch (status) { case BadgeStatus.Success: Assert.Contains(98.ToString(), badge.Message); break; case BadgeStatus.Neutural: Assert.Contains(90.ToString(), badge.Message); break; case BadgeStatus.Failure: Assert.Contains(80.ToString(), badge.Message); break; } Assert.Contains("uptime", badge.Title.ToLower()); Assert.Contains("the-url.com", badge.Title.ToLower()); }
public void ProducesIndividualHealthBadge(BadgeStatus status) { // Act var badge = new BadgeService().GetMetricHealthBadge( "the-source", Metrics.CpuLoad, status == BadgeStatus.Success ? AutoLabels.Normal : (status == BadgeStatus.Neutural ? AutoLabels.Warning : AutoLabels.Critical) ); // Assert Assert.Equal(status, badge.Status); Assert.NotEqual(0, badge.TitleWidth); Assert.NotEqual(0, badge.MessageWidth); switch (status) { case BadgeStatus.Success: Assert.Contains(AutoLabels.Normal.ToString().ToLower(), badge.Message.ToLower()); break; case BadgeStatus.Neutural: Assert.Contains(AutoLabels.Warning.ToString().ToLower(), badge.Message.ToLower()); break; case BadgeStatus.Failure: Assert.Contains(AutoLabels.Critical.ToString().ToLower(), badge.Message.ToLower()); break; } Assert.Contains(Metrics.CpuLoad.ToString().ToLower(), badge.Title.ToLower()); Assert.Contains("the-source", badge.Title.ToLower()); }
public void DenyBadge() { if (CanExecuteMethod(DenyBadgeMethod)) { this.BadgeStatus = BadgeStatus.Denied; this.ApprovedById = 0; this.ApprovedDate = null; } }
public void ApproveBadge(int approverUserId) { if (CanExecuteMethod(ApproveBadgeMethod)) { this.BadgeStatus = BadgeStatus.Approved; this.ApprovedById = approverUserId; this.ApprovedDate = DateTime.UtcNow; } }
public bool GetIsNew(string badgeID) { bool retVal = false; if (BadgeStatus.ContainsKey(badgeID)) { retVal = BadgeStatus[badgeID].IsNew; } return(retVal); }
/// <summary> /// Gets the status style. /// </summary> /// <param name="status">The status.</param> /// <returns>The status style.</returns> public BadgeStatusStyle GetStatusStyle(BadgeStatus status) { switch (status) { case BadgeStatus.Success: return Success; case BadgeStatus.Warning: return Warning; default: return Failed; } }
} //Key: Badge type, Value: data to check with badges' unlock condition //series Badge are accumulative. For example, the level badges are awarded //at level 1, 5, 10, 15, 20. Even though all the level badges have their own //badge id they are considered as the same type //Change badge status. locked or unlocked public void UpdateBadgeStatus(string badgeID, bool isUnlocked, bool isNew) { if (BadgeStatus.ContainsKey(badgeID)) { Status status = BadgeStatus[badgeID]; status.IsUnlocked = isUnlocked; status.IsNew = isNew; BadgeStatus[badgeID] = status; } else { Status status = new Status(isUnlocked, isNew); BadgeStatus.Add(badgeID, status); } }
// add a badge status public int addBadgeStatus(BadgeStatus bs) { if (bs == null) { throw new Exception("Failed to add the badge status. Passed wrong badge status."); } string name = bs.BS_Name , descript = bs.BS_Descript; using (var conn = new SqlConnection(connectionString)) { string sql = @"INSERT INTO BadgeStatus (BS_Name, BS_Descript) VALUES ( @name , @descript )"; return(conn.Execute(sql, new { name, descript })); } }
// Update badge status public int updateBadgeStatus(BadgeStatus bs, string oldBSName) { if (bs == null || String.IsNullOrEmpty(oldBSName)) { throw new Exception("Failed to update the badge status. Passed in wrong badge status"); } string name = bs.BS_Name , descript = bs.BS_Descript; using (var conn = new SqlConnection(connectionString)) { string sql = @"UPDATE BadgeStatus SET BS_Name = @name, BS_Descript = @descript WHERE BS_Id = (select BadgeStatus.BS_Id from BadgeStatus where BS_Name = @oldBSName)"; return(conn.Execute(sql, new { name, descript, oldBSName })); } }
internal void Load(ApproveBadgeItemDTO data, bool inCollection) { using (this.BypassPropertyChecks) { this.BadgeId = data.BadgeId; this.Name = data.Name; this.Description = data.Description; this.Tagline = data.Tagline; this.Type = data.Type; this.AwardValueAmount = data.AwardValueAmount; this.Created = data.Created; this.ImagePath = data.ImagePath; this.BadgeStatus = data.BadgeStatus; this.ApprovedById = data.ApprovedById; this.ApprovedDate = data.ApprovedDate; } this.MarkClean(); this.MarkOld(); if (inCollection) { this.MarkAsChild(); } }
private async Task <Stream> CreateBadge(string service, BadgeStatus status, string label) { var color = "lightgrey"; switch (status) { case BadgeStatus.Success: color = "brightgreen"; break; case BadgeStatus.Pending: color = "yellow"; break; case BadgeStatus.Error: color = "red"; break; } var response = await _ShieldsClient.GetAsync(GetBadgeUrl(ENDPOINT_URL, service, label, color)); response.EnsureSuccessStatusCode(); return(await response.Content.ReadAsStreamAsync()); }
async Task IBadgeService.CreateAsync(string service, string id, BadgeStatus status, string label) { var badgeContent = await CreateBadge(service, status, label); await GetBlob(GetBlobName(_Shard, service, id)).UploadAsync(badgeContent, overwrite: true); }