コード例 #1
0
        public UserInvitesControllerTests()
        {
            var mapper = new MapperConfiguration(cfg => { cfg.AddProfile <UserInviteProfile>(); }).CreateMapper();

            // repository mock
            _repositoryFactoryMock.Setup(m => m.CreateRepositoryAsync <UserInvite>(It.IsAny <CancellationToken>()))
            .ReturnsAsync(_userInviteRepositoryMock.Object);
            _repositoryFactoryMock.Setup(m => m.CreateRepositoryAsync <User>(It.IsAny <CancellationToken>()))
            .ReturnsAsync(_userRepositoryMock.Object);

            _validatorMock.Setup(m => m.Validate(It.IsAny <object>()))
            .Returns(new ValidationResult());

            _validatorMock.Setup(m => m.ValidateAsync(It.IsAny <object>(), CancellationToken.None))
            .ReturnsAsync(new ValidationResult());

            _validatorLocatorMock.Setup(m => m.GetValidator(It.IsAny <Type>()))
            .Returns(_validatorMock.Object);

            _validatorFailsMock.Setup(m => m.Validate(It.IsAny <object>()))
            .Returns(new ValidationResult {
                Errors = { new ValidationFailure(string.Empty, string.Empty) }
            });

            // event service mock
            _eventServiceMock.Setup(m => m.PublishAsync(It.IsAny <ServiceBusEvent <UserInvite> >()));

            // logger factory mock
            var loggerFactoryMock = new Mock <ILoggerFactory>();

            loggerFactoryMock.Setup(m => m.Get(It.IsAny <LogTopic>()))
            .Returns(_loggerMock.Object);

            _controller = new UserInvitesController(_repositoryFactoryMock.Object,
                                                    loggerFactoryMock.Object,
                                                    mapper,
                                                    _validatorLocatorMock.Object,
                                                    _tenantApiMock.Object,
                                                    _emailApiMock.Object);
        }
        public UserInviteModule(
            IUserInvitesController userInvitesController,
            IMetadataRegistry metadataRegistry,
            IPolicyEvaluator policyEvaluator,
            ILoggerFactory loggerFactory)
            : base(ServiceInformation.ServiceNameShort, metadataRegistry, policyEvaluator, loggerFactory)
        {
            _userInviteController = userInvitesController;

            this.RequiresAuthentication();

            CreateRoute("CreateUserInviteListForTenant", HttpMethod.Post, Routing.UserInvites, _ => CreateUserInviteListForTenantAsync())
            .Description("Email invites for passed user list")
            .StatusCodes(HttpStatusCode.Created, HttpStatusCode.Unauthorized, HttpStatusCode.Forbidden, HttpStatusCode.BadRequest, HttpStatusCode.InternalServerError)
            .RequestFormat(new List <UserInvite> {
                UserInvite.Example()
            })
            .ResponseFormat(new List <UserInvite> {
                UserInvite.Example()
            });

            CreateRoute("ResendEmailInvitation", HttpMethod.Post, Routing.ResendUserInvites, _ => ResendEmailInvitationAsync())
            .Description("Resend Email invites for passed user list")
            .StatusCodes(HttpStatusCode.Created, HttpStatusCode.Unauthorized, HttpStatusCode.Forbidden, HttpStatusCode.BadRequest, HttpStatusCode.InternalServerError)
            .RequestFormat(new List <UserInvite> {
                UserInvite.Example()
            })
            .ResponseFormat(new List <UserInvite> {
                UserInvite.Example()
            });

            CreateRoute("GetUserInvitesForTenantAsync", HttpMethod.Get, Routing.UserInvites, GetUsersInvitedForTenantAsync)
            .Description("Gets all invited users for Tenant")
            .StatusCodes(HttpStatusCode.OK, HttpStatusCode.BadRequest, HttpStatusCode.Unauthorized, HttpStatusCode.Forbidden, HttpStatusCode.InternalServerError, HttpStatusCode.NotFound)
            .ResponseFormat(new PagingMetadata <UserInvite> {
                List = new List <UserInvite> {
                    UserInvite.Example()
                }
            });
        }