public void Constructor()
        {
            var profileValidationResult = new ProfileValidationResult(true, "userid", "errors");

            Assert.True(profileValidationResult.IsValid);
            Assert.Equal("userid", profileValidationResult.UserId);
            Assert.Equal("errors", profileValidationResult.Errors);
        }
        public void Valid()
        {
            var profileValidationResult = ProfileValidationResult.CreateValid();

            Assert.True(profileValidationResult.IsValid);
            Assert.Equal("", profileValidationResult.UserId);
            Assert.Equal("", profileValidationResult.Errors);
        }
        public void Constructor_Default()
        {
            var profileValidationResult = new ProfileValidationResult();

            Assert.False(profileValidationResult.IsValid);
            Assert.Null(profileValidationResult.UserId);
            Assert.Null(profileValidationResult.Errors);
        }
Esempio n. 4
0
        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);
        }
        public void ProfileRequestValidator_ShouldReturnPatternWithValidRequestAAC1920()
        {
            // arrange
            FundingStreamPeriodProfilePattern pattern = new FundingStreamPeriodProfilePattern(
                "AY-1819",
                "PSG",
                "FL1",
                new DateTime(2019, 8, 1),
                new DateTime(2020, 7, 31),
                false,
                new[]
            {
                new ProfilePeriodPattern(
                    PeriodType.CalendarMonth,
                    "Aug",
                    new DateTime(2019, 8, 1),
                    new DateTime(2019, 8, 31),
                    2019,
                    1,
                    "FY1920",
                    12.56m),

                new ProfilePeriodPattern(
                    PeriodType.CalendarMonth,
                    "Apr",
                    new DateTime(2020, 4, 1),
                    new DateTime(2020, 4, 30),
                    2020,
                    1,
                    "FY2021",
                    12.56m)
            },
                "FSP-ProfilePattern1",
                "FSP-ProfilePatternDescription1",
                RoundingStrategy.RoundDown);

            ProfileRequest request = new ProfileRequest(
                "PSG",
                "AY-1819",
                "FL1",
                200);

            // act
            ProfileValidationResult validationResult = ProfileRequestValidator.ValidateRequestAgainstPattern(request, pattern);

            // assert
            validationResult
            .Code
            .Should().Be(HttpStatusCode.OK);
        }
Esempio n. 6
0
        public void Constructor()
        {
            var user = new SlackUser {
                Id = "id"
            };
            var url = new Uri("http://image.com");

            var profileValidationResult = new ProfileValidationResult(user, "errors", url);

            Assert.False(profileValidationResult.IsValid);
            Assert.Same(user, profileValidationResult.User);
            Assert.Equal("errors", profileValidationResult.Errors);
            Assert.Same(url, profileValidationResult.ImageURL);
        }
Esempio n. 7
0
        public async Task VerifyAllProfiles_NoProfileErrors()
        {
            var users = new List <SlackUser> {
                new SlackUser(), new SlackUser()
            };
            var creationResult = await CreateProfileBot(true);

            creationResult.SlackIntegration.Setup(s => s.GetAllUsers()).ReturnsAsync(users);
            creationResult.SlackProfileChecker.Setup(s => s.ValidateProfile(It.IsAny <SlackUser>()))
            .Returns(ProfileValidationResult.CreateValid());

            creationResult.SlackIntegration.Raise(s => s.MessageReceived += null,
                                                  MessageParserTests.CreateMessage(adminUser.Id, "validate all users"));

            creationResult.SlackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id, "No profiles contain errors :)"));
        }
        public void ProfileRequestValidator_ShouldReturnBadRequestWithNotFoundFsp()
        {
            // arrange
            ProfileRequest request = new ProfileRequest(
                null,
                "ABC-123",
                null,
                0);

            // act
            ProfileValidationResult validationResult = ProfileRequestValidator.ValidateRequestAgainstPattern(request, null);

            // assert
            validationResult
            .Code
            .Should().Be(HttpStatusCode.NotFound);
        }
        public async Task <IActionResult> ProcessProfileAllocationRequest(ProfileRequest profileRequest)
        {
            Guard.ArgumentNotNull(profileRequest, nameof(profileRequest));

            _logger.Information($"Retrieved a request {profileRequest}");

            try
            {
                FundingStreamPeriodProfilePattern profilePattern = await GetProfilePattern(profileRequest);

                if (profilePattern == null)
                {
                    _logger.Error("Unable to find profile pattern for FundingStream = {fundingStreamId}, FundingPeriodId={FundingPeriodId}, FundingLineCode={FundingLineCode}, ProfilePatternKey={ProfilePatternKey}, ProviderType={ProviderType}, ProviderSubType={ProviderSubType}",
                                  profileRequest.FundingStreamId,
                                  profileRequest.FundingPeriodId,
                                  profileRequest.FundingLineCode,
                                  profileRequest.ProfilePatternKey,
                                  profileRequest.ProviderType,
                                  profileRequest.ProviderSubType);
                }

                ProfileValidationResult validationResult =
                    ProfileRequestValidator.ValidateRequestAgainstPattern(profileRequest, profilePattern);

                if (validationResult.Code != HttpStatusCode.OK)
                {
                    _logger.Information($"Returned status code of {validationResult.Code} for {profileRequest}");

                    return(new StatusCodeResult((int)validationResult.Code));
                }

                AllocationProfileResponse profilingResult = ProfileAllocation(profileRequest, profilePattern, profileRequest.FundingValue);
                profilingResult.ProfilePatternKey         = profilePattern.ProfilePatternKey;
                profilingResult.ProfilePatternDisplayName = profilePattern.ProfilePatternDisplayName;

                _logger.Information($"Returned Ok for {profileRequest}");

                return(new OkObjectResult(profilingResult));
            }
            catch (Exception ex)
            {
                LogError(ex, profileRequest);

                throw;
            }
        }
        /// <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));
        }
Esempio n. 11
0
 // ReSharper disable once UnusedParameter.Local
 static void VerifyOtherThanDIPSMail(ProfileValidationResult validationResult)
 {
     Assert.Contains("Kun DIPS-epost skal benyttes.", validationResult.Errors);
 }
Esempio n. 12
0
        public async Task AnswerRegularUser_ValidProfile()
        {
            var user = new SlackUser {
                Id = "U1TBU8337"
            };
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            slackIntegration.Setup(s => s.GetUser("U1TBU8337")).ReturnsAsync(user);
            creationResult.SlackProfileChecker.Setup(s => s.ValidateProfile(It.IsAny <SlackUser>())).Returns(ProfileValidationResult.CreateValid());

            slackIntegration.Raise(s => s.MessageReceived += null,
                                   MessageParserTests.CreateMessage("U1TBU8337", "Any message"));

            slackIntegration.Verify(s => s.SendDirectMessage("U1TBU8337", "Checking your profile"));
            slackIntegration.Verify(s => s.SendDirectMessage("U1TBU8337", "Well done <@U1TBU8337>, your profile is complete"));
        }
Esempio n. 13
0
        public async Task NotifySingleProfile_ValidProfile()
        {
            var user = new SlackUser {
                Id = adminUser.Id
            };
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            slackIntegration.Setup(s => s.GetUser(adminUser.Id)).ReturnsAsync(user);
            creationResult.SlackProfileChecker.Setup(s => s.ValidateProfile(It.IsAny <SlackUser>())).Returns(ProfileValidationResult.CreateValid());

            slackIntegration.Raise(s => s.MessageReceived += null,
                                   MessageParserTests.CreateMessage(adminUser.Id, "Notify <@U1TBU8336>"));

            slackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id, "Notifying <@U1TBU8336>"));
            slackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id, "<@U1TBU8336> has a complete profile"));
        }
Esempio n. 14
0
 static ProfileValidationResult ValidResult() =>
 ProfileValidationResult.Valid(new SlackUser {
     Id = "userId"
 });
Esempio n. 15
0
 // ReSharper disable once UnusedParameter.Local
 static void VerifyMissingImage(ProfileValidationResult validationResult)
 {
     Assert.Contains("Legg inn et profilbilde slik at folk kjenner deg igjen.", validationResult.Errors);
 }
Esempio n. 16
0
 // ReSharper disable once UnusedParameter.Local
 static void VerifyBadImage(ProfileValidationResult validationResult)
 {
     Assert.Contains("Bad image", validationResult.Errors);
 }
Esempio n. 17
0
 // ReSharper disable once UnusedParameter.Local
 static void VerifyMissingWhatIDo(ProfileValidationResult validationResult)
 {
     Assert.Contains("Feltet \"What I do\" må inneholde team og hva du kan i DIPS.", validationResult.Errors);
 }
Esempio n. 18
0
 // ReSharper disable once UnusedParameter.Local
 static void VerifyMissingLastName(ProfileValidationResult validationResult)
 {
     Assert.Contains("Etternavn må registreres slik at folk vet hvem du er.", validationResult.Errors);
 }
Esempio n. 19
0
 // ReSharper disable once UnusedParameter.Local
 static void VerifyWrongDIPSMail(ProfileValidationResult validationResult)
 {
     Assert.Contains("Brukernavnet ditt skal kun være dine tre DIPS-bokstaver. Dette kan endres via https://dipsasa.slack.com/account/settings", validationResult.Errors);
 }
Esempio n. 20
0
 // ReSharper disable once UnusedParameter.Local
 static void VerifyValidationResult(ProfileValidationResult validationResult)
 {
     Assert.Equal(false, validationResult.IsValid);
     Assert.Equal(UserId, validationResult.User.Id);
 }
Esempio n. 21
0
 // ReSharper disable once UnusedParameter.Local
 static void VerifyEmailExist(ProfileValidationResult validationResult)
 {
     Assert.Contains("Din DIPS-epost må være registrert på brukeren din.", validationResult.Errors);
 }