public async Task UnsubscribeAsync_DoesNotRemoveOtherSubscriptionPolicies() { // Arrange. var service = new TestSecurityPolicyService(); var user = new User("testUser"); var subscriptionName2 = "MockSubscription2"; var subscription = service.Mocks.Subscription.Object; foreach (var policy in subscription.Policies) { user.SecurityPolicies.Add(new UserSecurityPolicy(policy)); user.SecurityPolicies.Add(new UserSecurityPolicy(policy.Name, subscriptionName2)); } Assert.Equal(4, user.SecurityPolicies.Count); // Act. await service.UnsubscribeAsync(user, service.UserSubscriptions.First()); // Act & Assert. var policies = user.SecurityPolicies.ToList(); Assert.Equal(2, policies.Count); Assert.Equal(subscriptionName2, policies[0].Subscription); Assert.Equal(subscriptionName2, policies[1].Subscription); service.Mocks.Subscription.Verify(s => s.OnUnsubscribeAsync(It.IsAny <UserSecurityPolicySubscriptionContext>()), Times.Once); service.MockEntitiesContext.Verify(c => c.SaveChangesAsync(), Times.Once); service.MockUserSecurityPolicies.Verify(p => p.Remove(It.IsAny <UserSecurityPolicy>()), Times.Exactly(2)); }
public async Task UnsubscribeAsync_DoesNotSaveAuditRecordIfWasNotSubscribed() { // Arrange. var service = new TestSecurityPolicyService(); var user = new User("testUser"); var subscription = service.UserSubscriptions.First(); // Act. await service.UnsubscribeAsync(user, subscription); // Act & Assert. service.MockAuditingService.Verify(s => s.SaveAuditRecordAsync(It.IsAny <AuditRecord>()), Times.Never); }
public async Task UnsubscribeAsync_RemovesAllSubscriptionPolicies() { // Arrange. var service = new TestSecurityPolicyService(); var user = new User("testUser"); var subscription = service.Mocks.UserPoliciesSubscription.Object; foreach (var policy in subscription.Policies) { user.SecurityPolicies.Add(new UserSecurityPolicy(policy)); } Assert.Equal(2, user.SecurityPolicies.Count); // Act. await service.UnsubscribeAsync(user, service.Subscriptions.First()); // Act & Assert. Assert.Equal(0, user.SecurityPolicies.Count); service.Mocks.UserPoliciesSubscription.Verify(s => s.OnUnsubscribeAsync(It.IsAny <UserSecurityPolicySubscriptionContext>()), Times.Once); service.MockEntitiesContext.Verify(c => c.SaveChangesAsync(), Times.Once); service.MockUserSecurityPolicies.Verify(p => p.Remove(It.IsAny <UserSecurityPolicy>()), Times.Exactly(2)); }