Beispiel #1
0
        public void SearchFindsMatchingUsers(string query, int foundCount, int notFoundCount)
        {
            // Arrange.
            var policyService = new TestSecurityPolicyService();
            var entitiesMock  = policyService.MockEntitiesContext;

            entitiesMock.Setup(c => c.Users).Returns(TestUsers.MockDbSet().Object);
            var controller = new SecurityPolicyController(entitiesMock.Object, policyService);

            // Act.
            JsonResult result = controller.Search(query);

            // Assert
            dynamic data          = result.Data;
            var     users         = data.Users as IEnumerable <UserSecurityPolicySubscriptions>;
            var     usersNotFound = data.UsersNotFound as IEnumerable <string>;

            Assert.NotNull(users);
            Assert.Equal(foundCount, users.Count());
            Assert.Equal(notFoundCount, usersNotFound.Count());
        }
Beispiel #2
0
        public async Task SearchReturnsUserSubscriptions()
        {
            // Arrange.
            var policyService    = new TestSecurityPolicyService();
            var dbUsers          = TestUsers.ToArray();
            var subscription     = policyService.Mocks.Subscription.Object;
            var subscriptionName = subscription.SubscriptionName;
            await policyService.SubscribeAsync(dbUsers[1], subscription);

            var entitiesMock = policyService.MockEntitiesContext;

            entitiesMock.Setup(c => c.Users).Returns(dbUsers.MockDbSet().Object);
            var controller = new SecurityPolicyController(entitiesMock.Object, policyService);

            // Act.
            JsonResult result = controller.Search("A,B,C");

            // Assert.
            dynamic data  = result.Data;
            var     users = (data.Users as IEnumerable <UserSecurityPolicySubscriptions>)?.ToList();

            Assert.NotNull(users);
            Assert.Equal(3, users.Count());

            Assert.Equal(1, users[0].Subscriptions.Count);
            Assert.True(users[0].Subscriptions.ContainsKey(subscriptionName));
            Assert.False(users[0].Subscriptions[subscriptionName]);

            Assert.Equal(1, users[1].Subscriptions.Count);
            Assert.True(users[1].Subscriptions.ContainsKey(subscriptionName));
            Assert.True(users[1].Subscriptions[subscriptionName]);

            Assert.Equal(1, users[2].Subscriptions.Count);
            Assert.True(users[2].Subscriptions.ContainsKey(subscriptionName));
            Assert.False(users[2].Subscriptions[subscriptionName]);
        }