public void TestThatConstructorInitializeUserNameAsMailAddressAuthorizationPolicy()
        {
            var primaryIdentityMock = MockRepository.GenerateMock <IIdentity>();

            var userNameAsMailAddressAuthorizationPolicy = new UserNameAsMailAddressAuthorizationPolicy(primaryIdentityMock);

            Assert.That(userNameAsMailAddressAuthorizationPolicy, Is.Not.Null);
            Assert.That(userNameAsMailAddressAuthorizationPolicy.Id, Is.Not.Null);
            Assert.That(userNameAsMailAddressAuthorizationPolicy.Id, Is.Not.Empty);
            Assert.That(userNameAsMailAddressAuthorizationPolicy.Issuer, Is.Not.Null);
            Assert.That(userNameAsMailAddressAuthorizationPolicy.Issuer, Is.EqualTo(ClaimSet.System));
            Assert.That(userNameAsMailAddressAuthorizationPolicy.PrimaryIdentity, Is.Not.Null);
            Assert.That(userNameAsMailAddressAuthorizationPolicy.PrimaryIdentity, Is.EqualTo(primaryIdentityMock));
        }
        public void TestThatIdGetterReturnsGuid()
        {
            var fixture = new Fixture();

            fixture.Customize <IIdentity>(e => e.FromFactory(() => MockRepository.GenerateMock <IIdentity>()));

            var userNameAsMailAddressAuthorizationPolicy = new UserNameAsMailAddressAuthorizationPolicy(fixture.Create <IIdentity>());

            Assert.That(userNameAsMailAddressAuthorizationPolicy, Is.Not.Null);

            var guid = Guid.Parse(userNameAsMailAddressAuthorizationPolicy.Id);

            Assert.That(guid, Is.Not.Null);
            Assert.That(guid, Is.Not.EqualTo(Guid.Empty));
        }
        public void TestThatEvaluateThrowsNotSupportedExceptionWhenEvaluationContextIsNotNull()
        {
            var fixture = new Fixture();

            fixture.Customize <IIdentity>(e => e.FromFactory(() => MockRepository.GenerateMock <IIdentity>()));

            var userNameAsMailAddressAuthorizationPolicy = new UserNameAsMailAddressAuthorizationPolicy(fixture.Create <IIdentity>());

            Assert.That(userNameAsMailAddressAuthorizationPolicy, Is.Not.Null);

            var evaluationContext = MockRepository.GenerateMock <EvaluationContext>();
            var state             = CreateLegalState();

            var exception = Assert.Throws <NotSupportedException>(() => userNameAsMailAddressAuthorizationPolicy.Evaluate(evaluationContext, ref state));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.InnerException, Is.Null);
        }
        public void TestThatEvaluateThrowsArgumentNullExceptionWhenEvaluationContextIsNull()
        {
            var fixture = new Fixture();

            fixture.Customize <IIdentity>(e => e.FromFactory(() => MockRepository.GenerateMock <IIdentity>()));

            var userNameAsMailAddressAuthorizationPolicy = new UserNameAsMailAddressAuthorizationPolicy(fixture.Create <IIdentity>());

            Assert.That(userNameAsMailAddressAuthorizationPolicy, Is.Not.Null);

            var state = CreateLegalState();

            // ReSharper disable AssignNullToNotNullAttribute
            var exception = Assert.Throws <ArgumentNullException>(() => userNameAsMailAddressAuthorizationPolicy.Evaluate(null, ref state));

            // ReSharper restore AssignNullToNotNullAttribute
            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("evaluationContext"));
            Assert.That(exception.InnerException, Is.Null);
        }