public async Task RegisterAsync_WithFailedAddToRoleAsync_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "AdministratorService RegisterAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context     = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userManager = this.GetUserManagerMock();

            userManager
            .Setup(x => x.CreateAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success);
            userManager
            .Setup(x => x.AddToRoleAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Failed());
            var userRepository            = new EfDeletableEntityRepository <ApplicationUser>(context);
            var administratorService      = new AdministratorService(this.configuration, userManager.Object, userRepository);
            var administratorServiceModel = new AdministratorServiceModel();

            // Act
            var result = await administratorService.RegisterAsync(administratorServiceModel);

            // Assert
            Assert.False(result, errorMessagePrefix + " " + "Returns true.");
        }
        public async Task <bool> RegisterAsync(AdministratorServiceModel administratorServiceModel)
        {
            var user = administratorServiceModel.To <ApplicationUser>();

            var result = await this.userManager.CreateAsync(
                user,
                administratorServiceModel.Password);

            if (result.Succeeded)
            {
                result = await this.userManager.AddToRoleAsync(
                    user,
                    GlobalConstants.AdministratorRoleName);
            }

            return(result.Succeeded);
        }