public void Valid() { var user = new SlackUser { Id = "id" }; var profileValidationResult = ProfileValidationResult.Valid(user); Assert.True(profileValidationResult.IsValid); Assert.Same(user, profileValidationResult.User); Assert.Equal("", profileValidationResult.Errors); Assert.Null(profileValidationResult.ImageURL); }
/// <summary> /// Validates that a user profile is complete. /// </summary> /// <param name="user">The user to be validated.</param> /// <returns>The result of the validation.</returns> public async Task <ProfileValidationResult> ValidateProfile(SlackUser user) { user.Guard(); if (string.IsNullOrEmpty(user.Name)) { throw new ArgumentException("Name cannot be empty.", nameof(user)); } var errors = new StringBuilder(); ValidateEmail(user, errors); if (string.IsNullOrEmpty(user.FirstName)) { errors.AppendLine("Fornavn må registreres slik at folk vet hvem du er."); } if (string.IsNullOrEmpty(user.LastName)) { errors.AppendLine("Etternavn må registreres slik at folk vet hvem du er."); } if (string.IsNullOrEmpty(user.WhatIDo)) { errors.AppendLine("Feltet \"What I do\" må inneholde team og hva du kan i DIPS."); } var imageWasSuspect = await ValidateProfileImage(user, errors); var actualErrors = errors.ToString(); return(actualErrors.Length == 0 || user.IsBot || user.Deleted || user.Name == "slackbot" ? ProfileValidationResult.Valid(user) : new ProfileValidationResult(user, $"Hei <@{user.Id}>, jeg har sett gjennom profilen din og den har følgende mangler:" + $"{Environment.NewLine}{Environment.NewLine}{actualErrors}{Environment.NewLine}" + "Se https://github.com/DIPSAS/community/blob/master/communication/slack-guidelines.md for hva som kreves av en fullt utfylt profil." + $"{Environment.NewLine}Ta kontakt med #admins dersom du har spørsmål.", imageWasSuspect ? new Uri(user.Image) : null)); }
static ProfileValidationResult ValidResult() => ProfileValidationResult.Valid(new SlackUser { Id = "userId" });