public async Task Validate_TwoAccounts(bool valid, string email1, string email2) { using (var provider = await CreateProvider()) { var access = provider.GetRequiredService <IContextLock>(); var context = provider.GetRequiredService <IContext>(); var accounts = provider.GetRequiredService <IAccountRepository>(); IValidator <Account> validator = new AccountValidator(accounts); using (var handle = await access.Write()) { var one = new Account { Email = new EmailAddress(email1) }; context.Add(one); await handle.Finish(); } using (await access.Read()) { var two = new Account { Email = new EmailAddress(email2) }; var target = new ValidationTarget <Account>(two); validator.Validate(target); Assert.Equal(valid, !target.GetResult().HasErrors); } } }
public void Invalid(string value) { IValidator <Name> validator = new NameValidator(); var target = new ValidationTarget <Name>(new Name(value)); validator.Validate(target); Assert.True(target.GetResult().HasErrors); }
public void Invalid(string value) { IValidator <Identifier> validator = new IdentifierValidator(); var target = new ValidationTarget <Identifier>(new Identifier(value)); validator.Validate(target); Assert.True(target.GetResult().HasErrors); }
public void Invalid(string value) { IValidator <EmailAddress> validator = new EmailAddressValidator(); var target = new ValidationTarget <EmailAddress>(new EmailAddress(value)); validator.Validate(target); Assert.True(target.GetResult().HasErrors); }
private void Validate <T>(bool success, T value) { IValidator <T> validator = new RequiredValidator <T>(); var target = new ValidationTarget <T>(value); validator.Validate(target); var result = target.GetResult(); Assert.Equal(success, !result.HasErrors); }
public void Validate_Recipients(bool valid, EmailRecipient[] recipients) { IValidator <Email> validator = new EmailValidator(); var email = new Email { IsSent = false, Sent = null, Recipients = new HashSet <EmailRecipient>(recipients) }; var target = new ValidationTarget <Email>(email); validator.Validate(target); Assert.Equal(valid, !target.GetResult().HasErrors); }
public void Validate_Sent_IsSent(bool valid, bool isSent, DateTime?sent) { IValidator <Email> validator = new EmailValidator(); var email = new Email { IsSent = isSent, Sent = sent, Recipients = new HashSet <EmailRecipient> { new EmailRecipient() }, }; var target = new ValidationTarget <Email>(email); validator.Validate(target); Assert.Equal(valid, !target.GetResult().HasErrors); }
public async Task Validate_OneAccount() { using (var provider = await CreateProvider()) { var access = provider.GetRequiredService <IContextLock>(); var accounts = provider.GetRequiredService <IAccountRepository>(); IValidator <Account> validator = new AccountValidator(accounts); var account = new Account(); using (await access.Read()) { var target = new ValidationTarget <Account>(account); validator.Validate(target); Assert.False(target.GetResult().HasErrors); } } }
public async Task Validate_Type_Privacy(bool valid, AccountType type, WorldPrivacy privacy) { using (var provider = await CreateProvider()) { var worlds = provider.GetRequiredService <IWorldRepository>(); IValidator <World> validator = new WorldValidator(worlds); var world = new World { Account = new Account { Type = type, }, Privacy = privacy }; var target = new ValidationTarget <World>(world); validator.Validate(target); Assert.Equal(valid, !target.GetResult().HasErrors); } }
public async Task Validate_TwoMembers(bool valid, string email1, string email2) { using (var provider = await CreateProvider()) { var context = provider.GetRequiredService <IContext>(); var access = provider.GetRequiredService <IContextLock>(); var worlds = provider.GetRequiredService <IWorldRepository>(); var entries = provider.GetRequiredService <IEntryRepository>(); IValidator <Member> validator = new MemberValidator(entries, worlds); var world = new World(); using (var handle = await access.Write()) { var one = new Member { World = world, Email = new EmailAddress(email1) }; world.Members = new HashSet <Member> { one }; context.Add(one); await handle.Finish(); } using (await access.Read()) { var two = new Member { World = world, Email = new EmailAddress(email2) }; var target = new ValidationTarget <Member>(two); validator.Validate(target); Assert.Equal(valid, !target.GetResult().HasErrors); } } }
public async Task Validate_OneMember() { using (var provider = await CreateProvider()) { var access = provider.GetRequiredService <IContextLock>(); var worlds = provider.GetRequiredService <IWorldRepository>(); var entries = provider.GetRequiredService <IEntryRepository>(); IValidator <Member> validator = new MemberValidator(entries, worlds); var member = new Member { World = new World() }; using (await access.Read()) { var target = new ValidationTarget <Member>(member); validator.Validate(target); Assert.False(target.GetResult().HasErrors); } } }