Ejemplo n.º 1
0
        public async Task GetIdentitiesAsync_RequirePermissionsAsyncSucceeds_ReturnsGetCurrentIdentitiesAsync()
        {
            using var testContext = new TestContext();

            var identities = TestArray.Unique <CharacterGuildIdentityViewModel>();

            testContext.MockCharacterGuildsService
            .Setup(x => x.GetCurrentIdentitiesAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(identities);

            var uut = testContext.BuildUut();

            var result = await uut.GetIdentitiesAsync(
                testContext.CancellationToken);

            result.IsSuccess.ShouldBeTrue();
            result.Value.ShouldBeSameAs(identities);

            testContext.MockAuthorizationService.ShouldHaveReceived(x => x
                                                                    .RequirePermissionsAsync(
                                                                        It.Is <int[]>(y => (y != null) && (y.Length != 0)),
                                                                        testContext.CancellationToken));

            testContext.MockCharacterGuildsService
            .ShouldHaveReceived(x => x.GetCurrentIdentitiesAsync(testContext.CancellationToken));
        }
        public async Task UpdateExperienceDiffsAsync_RequirePermissionsAsyncFails_ReturnsImmediately()
        {
            using var testContext = new TestContext();

            var mockError = new Mock <OperationError>("Mock Message");

            testContext.RequirePermissionsResult = OperationResult.FromError(mockError.Object);

            var uut = testContext.BuildUut();

            var experienceThresholds = TestArray.Unique <int>();

            var result = await uut.UpdateExperienceDiffsAsync(
                experienceThresholds,
                testContext.CancellationToken);

            result.IsFailure.ShouldBeTrue();
            result.Error.ShouldBeSameAs(mockError.Object);

            testContext.MockAuthorizationService.ShouldHaveReceived(x => x
                                                                    .RequirePermissionsAsync(
                                                                        It.Is <int[]>(y => (y != null) && (y.Length != 0)),
                                                                        testContext.CancellationToken));

            testContext.MockCharacterLevelsService.Invocations.ShouldBeEmpty();
        }
        public async Task GetDescriptionsAsync_RequirePermissionsAsyncSucceeds_ReturnsGetDescriptionsAsync()
        {
            using var testContext = new TestContext();

            testContext.MockAuthorizationService
            .Setup(x => x.RequirePermissionsAsync(It.IsAny <int[]>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(OperationResult.Success);

            var descriptions = TestArray.Unique <PermissionCategoryDescriptionViewModel>();

            testContext.MockPermissionsService
            .Setup(x => x.GetDescriptionsAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(descriptions);

            var uut = testContext.BuildUut();

            var result = await uut.GetDescriptionsAsync(
                testContext.CancellationToken);

            result.IsSuccess.ShouldBeTrue();
            result.Value.ShouldBeSameAs(descriptions);

            testContext.MockAuthorizationService.ShouldHaveReceived(x => x
                                                                    .RequirePermissionsAsync(
                                                                        It.Is <int[]>(y => (y != null) && (y.Length != 0)),
                                                                        testContext.CancellationToken));

            testContext.MockPermissionsService.ShouldHaveReceived(x => x
                                                                  .GetDescriptionsAsync(testContext.CancellationToken));
        }
        public async Task UpdateExperienceDiffsAsync_RequirePermissionsAsyncSucceeds_ReturnsUpdateExperienceDiffsAsync(
            ulong currentUserId)
        {
            using var testContext = new TestContext();

            testContext.SetCurrentUserId(currentUserId);

            var mockError = new Mock <OperationError>("Mock Message");

            testContext.MockCharacterLevelsService
            .Setup(x => x.UpdateExperienceDiffsAsync(
                       It.IsAny <IReadOnlyList <int> >(),
                       It.IsAny <ulong>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(OperationResult.FromError(mockError.Object));

            var uut = testContext.BuildUut();

            var experienceThresholds = TestArray.Unique <int>();

            var result = await uut.UpdateExperienceDiffsAsync(
                experienceThresholds,
                testContext.CancellationToken);

            result.IsFailure.ShouldBeTrue();
            result.Error.ShouldBeSameAs(mockError.Object);

            testContext.MockAuthorizationService.ShouldHaveReceived(x => x
                                                                    .RequirePermissionsAsync(
                                                                        It.Is <int[]>(y => (y != null) && (y.Length != 0)),
                                                                        testContext.CancellationToken));

            testContext.MockCharacterLevelsService.ShouldHaveReceived(x => x
                                                                      .UpdateExperienceDiffsAsync(
                                                                          experienceThresholds,
                                                                          currentUserId,
                                                                          testContext.CancellationToken));
        }