Esempio n. 1
0
 public CapabilityForParameterChecker(IGetsTypedCapabilityTester testerFactory,
                                      IGetsEntityTypeForCapability entityTypeProvider,
                                      IGetsCurrentCapabilityUser userProvider,
                                      IGetsTargetEntityIdentity targetEntityProvider,
                                      ILog logger)
 {
     this.testerFactory        = testerFactory ?? throw new ArgumentNullException(nameof(testerFactory));
     this.entityTypeProvider   = entityTypeProvider ?? throw new ArgumentNullException(nameof(entityTypeProvider));
     this.userProvider         = userProvider ?? throw new ArgumentNullException(nameof(userProvider));
     this.targetEntityProvider = targetEntityProvider ?? throw new ArgumentNullException(nameof(targetEntityProvider));
     this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        public void AssertCurrentUserHasCapability_does_not_invoke_tester_if_spec_param_value_does_not_return_entity([Frozen] IGetsTypedCapabilityTester testerFactory,
                                                                                                                     [Frozen] IGetsEntityTypeForCapability entityTypeProvider,
                                                                                                                     [Frozen] IGetsTargetEntityIdentity targetEntityProvider,
                                                                                                                     [CapabilitySpec] CapabilitiesAssertionSpec spec,
                                                                                                                     CapabilityForParameterChecker sut)
        {
            Mock.Get(entityTypeProvider)
            .Setup(x => x.GetEntityType(spec.CapabilityAttribute.RequiredCapability))
            .Returns(typeof(SampleEntity));
            Mock.Get(targetEntityProvider)
            .Setup(x => x.GetTargetEntityIdentity <SampleEntity>(spec.ParameterValue))
            .Returns(() => null);

            sut.AssertCurrentUserHasCapability(spec);

            Mock.Get(testerFactory)
            .Verify(x => x.GetCapabilityTester <SampleEntity, CapabilitySpecAttribute.SampleCapability>(), Times.Never);
        }
        public void AssertCurrentUserHasCapability_invokes_tester_with_correct_parameters([Frozen] IGetsTypedCapabilityTester testerFactory,
                                                                                          [Frozen] IGetsEntityTypeForCapability entityTypeProvider,
                                                                                          [Frozen] IGetsCurrentCapabilityUser userProvider,
                                                                                          [Frozen] IGetsTargetEntityIdentity targetEntityProvider,
                                                                                          IAssertsUserHasCapability <SampleEntity, CapabilitySpecAttribute.SampleCapability> tester,
                                                                                          [CapabilitySpec] CapabilitiesAssertionSpec spec,
                                                                                          IIdentity <SampleEntity> entity,
                                                                                          IIdentity <User> user,
                                                                                          CapabilityForParameterChecker sut)
        {
            Mock.Get(entityTypeProvider)
            .Setup(x => x.GetEntityType(spec.CapabilityAttribute.RequiredCapability))
            .Returns(typeof(SampleEntity));
            Mock.Get(targetEntityProvider)
            .Setup(x => x.GetTargetEntityIdentity <SampleEntity>(spec.ParameterValue))
            .Returns(entity);
            Mock.Get(testerFactory)
            .Setup(x => x.GetCapabilityTester <SampleEntity, CapabilitySpecAttribute.SampleCapability>())
            .Returns(tester);
            Mock.Get(userProvider)
            .Setup(x => x.GetCurrentCapabilityUser())
            .Returns(user);
            var expectedCapability = (CapabilitySpecAttribute.SampleCapability)spec.CapabilityAttribute.RequiredCapability;

            sut.AssertCurrentUserHasCapability(spec);

            Mock.Get(tester)
            .Verify(x => x.AssertUserHasCapability(user, entity, expectedCapability), Times.Once);
        }