public void Should_Have_Error_When_Name_Is_Not_Unique()
        {
            //Arrange
            _serviceProvider.RunScoped <IDbContext>(context =>
            {
                context.Set <Role>()
                .Add(new Role {
                    Name = "ExistingName", NormalizedName = "ExistingName".ToUpperInvariant()
                });
                context.SaveChanges();
            });

            var dbContext = _serviceProvider.GetService <IDbContext>();
            var validator = new RoleValidator(dbContext, _translation);

            var model = new RoleModel
            {
                Name = "ExistingName"
            };

            //Act & Assert
            validator.ShouldHaveValidationErrorFor(x => x.Name, model)
            .WithErrorMessage("Role.Fields.Name.Unique");
        }
Exemplo n.º 2
0
        public void Should_Have_Error_When_Name_Is_Not_Unique()
        {
            //Arrange
            _serviceProvider.RunScoped <IUnitOfWork>(uow =>
            {
                uow.Set <Role>()
                .Add(new Role {
                    Name = "ExistingName", NormalizedName = "ExistingName".ToUpperInvariant()
                });
                uow.SaveChanges();
            });

            var unitOfWork = _serviceProvider.GetService <IUnitOfWork>();
            var validator  = new RoleValidator(unitOfWork, _localizer);

            var model = new RoleModel
            {
                Name = "ExistingName"
            };

            //Act & Assert
            validator.ShouldHaveValidationErrorFor(x => x.Name, model)
            .WithErrorMessage("Role.Fields.Name.Unique");
        }
 public void Name_ShouldHaveError_When_Empty()
 {
     _sut.ShouldHaveValidationErrorFor(m => m.Name, string.Empty);
 }