Ejemplo 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 CapabilitiesForCurrentUserProvider(IGetsCurrentCapabilityUser userReader,
                                           IGetsUserCapabilities capabilitiesProvider)
 {
     this.userReader           = userReader ?? throw new ArgumentNullException(nameof(userReader));
     this.capabilitiesProvider = capabilitiesProvider ?? throw new ArgumentNullException(nameof(capabilitiesProvider));
 }
        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);
        }