public void ValidatesTitleUniqueTest() { Guid userId = Guid.NewGuid(); CreateData((context) => { User user = new User() { UserId = userId }; CardTemplate template1 = new CardTemplate() { UserId = userId, Title = "test1", CardTemplateId = 1 }; CardTemplate template2 = new CardTemplate() { UserId = Guid.NewGuid(), Title = "test2", CardTemplateId = 2 }; context.Add(user); context.Add(template1); context.Add(template2); }); //not successful using DbContext context = CreateContext(); CardTemplateCommitValidator validator = new CardTemplateCommitValidator(context); CardTemplate template = new CardTemplate() { UserId = userId, Title = "test1", CardTemplateId = 3 }; string error = validator.Validate(template); Assert.IsFalse(string.IsNullOrEmpty(error)); //successful template = new CardTemplate() { UserId = userId, Title = "test2", CardTemplateId = 3 }; error = validator.Validate(template); Assert.IsTrue(string.IsNullOrEmpty(error)); }
public void ValidatesTitleTest() { using DbContext context = CreateContext(); CardTemplateCommitValidator validator = new CardTemplateCommitValidator(context); CardTemplate template = new CardTemplate() { CardTemplateId = 1 }; //not successful string error = validator.Validate(template); Assert.IsFalse(string.IsNullOrEmpty(error)); //successful template.Title = "Test"; error = validator.Validate(template); Assert.IsTrue(string.IsNullOrEmpty(error)); }