Beispiel #1
0
        public async Task UpsertUser_InvalidData_ThrowException(string id, string email, string name, string[] roles)
        {
            // Arrange
            var userRepoMock = new Mock <IUserRepository>();

            userRepoMock
            .Setup(r => r.IsEmailUnique(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(true);
            var upsertUserCommandValidator = new UpsertUserCommandValidator(userRepoMock.Object);

            var validationService = new ValidationService(upsertUserCommandValidator);

            var userService = InstantiateUserService(
                new Tuple <Type, object>(typeof(IValidationService), validationService)
                );

            var command = new UpsertUserCommand()
            {
                Id    = id,
                Email = email,
                Name  = name,
                Roles = roles
            };

            // Act
            // Assert
            await Assert.ThrowsAsync <ValidationException>(
                () => userService.UpsertUser(command)
                );
        }
Beispiel #2
0
        public async Task UpsertUser_ValidData_CheckUniqueEmail()
        {
            // Arrange
            var userRepoMock = new Mock <IUserRepository>();

            userRepoMock
            .Setup(r => r.IsEmailUnique(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(false);
            var upsertUserCommandValidator = new UpsertUserCommandValidator(userRepoMock.Object);

            var validationService = new ValidationService(upsertUserCommandValidator);

            var userService = InstantiateUserService(
                new Tuple <Type, object>(typeof(IValidationService), validationService)
                );
            var command = new UpsertUserCommand()
            {
                Id    = "160db952-ce02-44b4-adb9-224d635cc11c",
                Email = "*****@*****.**",
                Name  = "New User",
                Roles = new[] { "User", "Admin" }
            };

            // Act
            // Assert
            await Assert.ThrowsAsync <ValidationException>(
                () => userService.UpsertUser(command)
                );
        }