示例#1
0
        public async Task RoleClaimsActorAdd_ExpectGetStateAsync()
        {
            var stateManager = new Mock <IActorStateManager>();
            var state        = new RoleClaimsEntity("testrole", new Dictionary <string, HashSet <string> >
            {
                { "type 1", new HashSet <string> {
                      "type 1 value"
                  } }
            });

            stateManager.Setup(manager => manager.GetStateAsync <RoleClaimsEntity>(_stateName, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(state))
            .Verifiable();
            RoleClaimsActor testDemoActor = await CreateActor(stateManager.Object, Guid.NewGuid().ToString());

            object result = await testDemoActor.GetStateValue();

            result.Should().NotBeNull();
            result.Should().BeOfType <RoleState>();
            var value = (RoleState)result;

            value.Should().NotBeNull();
            value.Name.Should().Be(state.Name);
            value.NormalizedName.Should().Be(state.NormalizedName);
            value.ConcurrencyStamp.Should().Be(state.ConcurrencyStamp);
            stateManager.VerifyAll();
        }
示例#2
0
        public async Task RoleClaimsActorRename_ExpectsNewValue()
        {
            var stateManager = new Mock <IActorStateManager>();
            var oldState     = new RoleState("old role", "OLDROLE", Guid.NewGuid().ToString());
            var newState     = new RoleState("new role", "NEWROLE", null);

            stateManager.Setup(manager => manager.GetStateAsync <RoleState>(_stateName, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(oldState))
            .Verifiable();
            stateManager.Setup(manager => manager
                               .SetStateAsync(
                                   _stateName,
                                   It.Is <RoleState>(o =>
                                                     o.Name == newState.Name &&
                                                     o.NormalizedName == newState.NormalizedName &&
                                                     string.IsNullOrWhiteSpace(o.ConcurrencyStamp) &&
                                                     o.ConcurrencyStamp != oldState.ConcurrencyStamp),
                                   It.IsAny <CancellationToken>()))
            .Verifiable();
            string          id            = Guid.NewGuid().ToString();
            RoleClaimsActor testDemoActor = await CreateActor(stateManager.Object, id);

            await testDemoActor.Tell(new RenameRole(id, newState.Name, newState.NormalizedName, oldState.ConcurrencyStamp, "user"));

            stateManager.VerifyAll();
        }
示例#3
0
        private async Task <RoleClaimsActor> CreateActor(IActorStateManager actorStateManager, string id)
        {
            var uniqueIndexActor     = new Mock <IUniqueIndexActor>();
            var eventBus             = new Mock <IEventBus>();
            var eventStore           = new Mock <IEventStore>();
            var actorTypeInformation = ActorTypeInformation.Get(typeof(RoleClaimsActor));

            RoleClaimsActor actorFactory(ActorService service, ActorId id) =>
            new RoleClaimsActor(service, id, eventBus.Object, eventStore.Object, actorStateManager);

            var             actorService = new ActorService(actorTypeInformation, actorFactory);
            RoleClaimsActor actor        = actorFactory(actorService, new ActorId(id));
            MethodInfo      OnActivate   = actor.GetType().GetMethod("OnActivateAsync", BindingFlags.NonPublic | BindingFlags.Instance);

            await(Task) OnActivate.Invoke(actor, Array.Empty <object>());
            return(actor);
        }
示例#4
0
        public async Task RoleClaimsActorRemove_ExpectsRemoveState()
        {
            var stateManager = new Mock <IActorStateManager>();
            var oldState     = new RoleState("old role", "OLDROLE", Guid.NewGuid().ToString());

            stateManager.Setup(manager => manager
                               .GetStateAsync <RoleState>(_stateName, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(oldState))
            .Verifiable();
            stateManager.Setup(manager => manager
                               .RemoveStateAsync(_stateName, It.IsAny <CancellationToken>()))
            .Verifiable();
            string          id            = Guid.NewGuid().ToString();
            RoleClaimsActor testDemoActor = await CreateActor(stateManager.Object, id);

            await testDemoActor.Tell(new RemoveRole(id, oldState.ConcurrencyStamp, "user"));

            stateManager.VerifyAll();
        }
示例#5
0
        public async Task RoleClaimsActorAdd_ExpectsValue()
        {
            var stateManager = new Mock <IActorStateManager>();
            var state1       = new RoleState("new role", "NEWROLE", null);

            stateManager.Setup(manager => manager
                               .SetStateAsync(
                                   _stateName,
                                   It.Is <RoleState>(o =>
                                                     o.Name == state1.Name &&
                                                     o.NormalizedName == state1.NormalizedName &&
                                                     !string.IsNullOrWhiteSpace(o.ConcurrencyStamp)),
                                   It.IsAny <CancellationToken>()))
            .Verifiable();
            string          id            = Guid.NewGuid().ToString();
            RoleClaimsActor testDemoActor = await CreateActor(stateManager.Object, id);

            await testDemoActor.Tell(new AddNewRole(id, state1.Name, state1.NormalizedName, "user"));

            stateManager.VerifyAll();
        }