public void Then_request_is_passed_on_to_mediator()
        {
            _mediator.Send(Arg.Any <CreateInvitationRequest>()).Returns(new CreateInvitationResponse()
            {
                Invited = true
            });

            var invitationRequest = new InvitationRequestViewModel()
            {
                Email              = "*****@*****.**",
                GivenName          = "Dave",
                FamilyName         = "Smith",
                OrganisationName   = "WWF",
                ApprenticeshipName = "Apprenticeship",
                SourceId           = _sourceId.ToString(),
                Callback           = new Uri("https://callback"),
                UserRedirect       = new Uri("https://userRedirect")
            };

            var clientId = Guid.NewGuid();

            _controller.Invite(clientId, invitationRequest).Wait();

            _mediator.Received().Send(Arg.Is <CreateInvitationRequest>(r => r.Email == "*****@*****.**" &&
                                                                       r.GivenName == "Dave" &&
                                                                       r.FamilyName == "Smith" &&
                                                                       r.OrganisationName == "WWF" &&
                                                                       r.ApprenticeshipName == "Apprenticeship" &&
                                                                       r.SourceId == _sourceId.ToString() &&
                                                                       r.Callback == new Uri("https://callback") &&
                                                                       r.UserRedirect == new Uri("https://userRedirect") &&
                                                                       r.ClientId == clientId));
        }
        public void And_request_arguments_are_invalid_Then_BadRequest_should_be_returned()
        {
            _mediator.Send(Arg.Any <CreateInvitationRequest>()).Throws(new ArgumentException("Email, FamilyName"));

            var invitationRequest = new InvitationRequestViewModel()
            {
                Email        = "*****@*****.**",
                GivenName    = "Dave",
                FamilyName   = "Smith",
                SourceId     = _sourceId.ToString(),
                Callback     = new Uri("https://callback"),
                UserRedirect = new Uri("https://userRedirect")
            };

            var clientId = Guid.NewGuid();
            var result   = _controller.Invite(clientId, invitationRequest).Result;

            result.Result.Should().BeOfType <BadRequestObjectResult>();
        }
        public void And_Invitation_is_valid_Then_CreateInvitationResponse_Is_Returned()
        {
            _mediator.Send(Arg.Any <CreateInvitationRequest>()).Returns(new CreateInvitationResponse()
            {
                Invited = true
            });

            var invitationRequest = new InvitationRequestViewModel()
            {
                Email        = "*****@*****.**",
                GivenName    = "Dave",
                FamilyName   = "Smith",
                SourceId     = _sourceId.ToString(),
                Callback     = new Uri("https://callback"),
                UserRedirect = new Uri("https://userRedirect")
            };
            var clientId = Guid.NewGuid();
            var response = _controller.Invite(clientId, invitationRequest).Result;

            response.Value.Should().BeOfType <CreateInvitationResponse>();
            response.Value.Invited.Should().BeTrue();
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Index(InvitationRequestViewModel model)
        {
            ViewBag.TeamName = _configuration.SlackTeamName;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                using (var client = new HttpClient())
                {
                    var endpointUri = $"https://{_configuration.SlackTeamName}.slack.com/api/users.admin.invite";
                    var content     = new FormUrlEncodedContent(new Dictionary <string, string>
                    {
                        { "email", model.Email },
                        { "token", _configuration.SlackToken },
                        { "set_active", "true" }
                    });
                    var result = await client.PostAsync(endpointUri, content);

                    if (!result.IsSuccessStatusCode)
                    {
                        throw new Exception();
                    }
                }
                ViewBag.MessageTitle = "Done.";
                ViewBag.Message      = $"We sent invitation for {_configuration.SlackTeamName} slack team to {model.Email}.";
                ViewBag.IsSuccess    = true;
            }
            catch (Exception e)
            {
                ViewBag.MessageTitle = "Oops.";
                ViewBag.Message      = "Invalid e-mail address or something went wrong :(";
                ViewBag.IsSuccess    = false;
            }
            return(View(new InvitationRequestViewModel()));
        }
Exemplo n.º 5
0
        public async Task <ActionResult <CreateInvitationResponse> > InviteToOrganisation(Guid clientId, [FromBody] InvitationRequestViewModel createInvitationRequest)
        {
            try
            {
                var response = await _mediator.Send(new CreateInvitationRequest()
                {
                    Email        = createInvitationRequest.Email,
                    GivenName    = createInvitationRequest.GivenName,
                    FamilyName   = createInvitationRequest.FamilyName,
                    SourceId     = createInvitationRequest.SourceId,
                    Callback     = createInvitationRequest.Callback,
                    UserRedirect = createInvitationRequest.UserRedirect,
                    ClientId     = clientId,
                    IsInvitationToOrganisation = true,
                    Inviter          = createInvitationRequest.Inviter,
                    OrganisationName = createInvitationRequest.OrganisationName
                });

                _logger.LogDebug($"Received Response from CreateInvitationHandler: Invited: {response.Invited} Message: {response.Message}");
                return(response);
            }
            catch (ArgumentException e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 6
0
 public ActionResult <BaseResponse <string> > GenerateInvitation([FromBody] InvitationRequestViewModel model)
 {
     return(GetResult(GetCommand <GenerateInvitationCommand>().Execute(model)));
 }