public void IsInvalidWhen_PrincipalIdentityName_IsNull() { const string principalIdentityName = null; // ReSharper disable ExpressionIsAlwaysNull var principal = principalIdentityName.AsPrincipal(); // ReSharper restore ExpressionIsAlwaysNull var command = new UpdateMyAffiliationCommand { Principal = principal, }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <Establishment>()).Returns(new Establishment[] { }.AsQueryable); var validator = new UpdateMyAffiliationValidator(entities.Object); var results = validator.Validate(command); results.IsValid.ShouldBeFalse(); results.Errors.Count.ShouldBeInRange(1, int.MaxValue); var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Principal"); error.ShouldNotBeNull(); // ReSharper disable PossibleNullReferenceException error.ErrorMessage.ShouldEqual(ValidatePrincipal.FailedBecausePrincipalWasNull); // ReSharper restore PossibleNullReferenceException }
public void IsValidWhen_PrincipalIdentityName_MatchesUser() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var command = new UpdateMyAffiliationCommand { Principal = principal, }; var user = new User { Name = principal.Identity.Name }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <User>()).Returns(new[] { user }.AsQueryable); entities.Setup(m => m.Query <Establishment>()).Returns(new Establishment[] { }.AsQueryable); var validator = new UpdateMyAffiliationValidator(entities.Object); var results = validator.Validate(command); var error = results.Errors.SingleOrDefault(e => e.PropertyName == "Principal"); error.ShouldBeNull(); }