Beispiel #1
0
        public async Task GetGroupsForTenantReturnsOk()
        {
            _controllerMock.Setup(m => m.GetGroupsForTenantAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(Enumerable.Empty <Group>()));

            var response = await UserTokenBrowser.Get(Routing.Groups, BuildRequest);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        public async Task GetTenantMachinesReturnsInternalServerError()
        {
            _controllerMock.Setup(m => m.GetTenantMachinesAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .Throws(new Exception());

            var response = await UserTokenBrowser.Get(Routing.Machines, BuildRequest);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
        public async Task GetTenantMachinesReturnsNotFoundException()
        {
            _controllerMock.Setup(m => m.GetTenantMachinesAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .Throws(new NotFoundException(string.Empty));

            var response = await UserTokenBrowser.Get("/v1/tenantmachines", BuildRequest);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
Beispiel #4
0
        public async Task GetGroupsForTenantReturnsNotFoundIfItemDoesNotExist()
        {
            _controllerMock.Setup(m => m.GetGroupsForTenantAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .Throws(new NotFoundException(string.Empty));

            var response = await UserTokenBrowser.Get(Routing.Groups, BuildRequest);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
Beispiel #5
0
        public async Task GetInvitedUsersForTenantReturnsInternalServerErrorIfUnhandledExceptionIsThrown()
        {
            _controllerMock.Setup(m => m.GetUsersInvitedForTenantAsync(It.IsAny <Guid>(), It.IsAny <bool>()))
            .Throws(new Exception());

            var response = await UserTokenBrowser.Get(Routing.UserInvites, BuildRequest);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
        public async Task GetTenantMachinesReturnsValidationException()
        {
            _controllerMock.Setup(m => m.GetTenantMachinesAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .Throws(new ValidationFailedException(Enumerable.Empty <ValidationFailure>()));

            var response = await UserTokenBrowser.Get(Routing.Machines, BuildRequest);

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Beispiel #7
0
        public async void GetInvitedUsersForTenantReturnsOk()
        {
            _controllerMock.Setup(m => m.GetUsersInvitedForTenantAsync(It.IsAny <Guid>(), It.IsAny <bool>()))
            .Returns(Task.FromResult(new PagingMetadata <UserInvite>()));

            var response = await UserTokenBrowser.Get(Routing.UserInvites, BuildRequest);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        public async Task GetTenantMachinesReturnsFound()
        {
            _controllerMock.Setup(m => m.GetTenantMachinesAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new List <Machine>()));

            var response = await UserTokenBrowser.Get(Routing.Machines, BuildRequest);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Beispiel #9
0
        public async Task GetGuestSessionsByProjectIdForUser_OnUnexpectedExpection_ReturnsInternalServerError()
        {
            _guestSessionControllerMock
            .Setup(x => x.GetGuestSessionsByProjectIdForUserAsync(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .Throws <Exception>();

            var response = await UserTokenBrowser.Get($"{Routing.ProjectsRoute}/{Guid.NewGuid()}/{Routing.UsersPath}/{Guid.NewGuid()}/{Routing.GuestSessionsPath}", BuildRequest);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
Beispiel #10
0
        public async Task GetGuestSession_ReturnsOk()
        {
            _guestSessionControllerMock
            .Setup(x => x.GetGuestSessionAsync(It.IsAny <Guid>()))
            .ReturnsAsync(new GuestSession());

            var response = await UserTokenBrowser.Get($"{Routing.GuestSessionsRoute}/{Guid.NewGuid()}", BuildRequest);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        public async Task GetGuestInviteByIdReturnsInternalServerErrorOnUnexpectedException()
        {
            _guestInviteControllerMock
            .Setup(x => x.GetGuestInviteAsync(It.IsAny <Guid>()))
            .Throws <Exception>();

            var response = await UserTokenBrowser.Get($"{Routing.GuestInvitesRoute}/{Guid.NewGuid()}", ctx => BuildRequest(ctx, _guestInvite));

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
        public async Task GetGuestInviteByProjectIdReturnsBadRequestOnValidationFailedException()
        {
            _guestInviteControllerMock
            .Setup(x => x.GetValidGuestInvitesByProjectIdAsync(It.IsAny <Guid>()))
            .Throws(new ValidationFailedException(new List <ValidationFailure>()));

            var response = await UserTokenBrowser.Get($"{Routing.ProjectsRoute}/{Guid.NewGuid()}/{Routing.GuestInvitesPath}", BuildRequest);

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task GetProjectLobbyStateAsync_IfUnhandledExceptionIsThrown_ReturnsInternalServerError()
        {
            _projectLobbyStateControllerMock
            .Setup(m => m.GetProjectLobbyStateAsync(It.IsAny <Guid>()))
            .Throws(new Exception());

            var response = await UserTokenBrowser.Get($"{Routing.ProjectsRoute}/{Guid.NewGuid()}/{Routing.ProjectLobbyStatePath}", BuildRequest);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
        public async Task GetGuestInviteByIdReturnsNotFoundException()
        {
            _guestInviteControllerMock
            .Setup(x => x.GetGuestInviteAsync(It.IsAny <Guid>()))
            .Throws(new NotFoundException("GuestInvite not found"));

            var response = await UserTokenBrowser.Get($"{Routing.GuestInvitesRoute}/{Guid.NewGuid()}", ctx => BuildRequest(ctx, _guestInvite));

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
        public async Task GetProjectLobbyStateAsync_IfValidationFailedExceptionIsThrown_ReturnsBadRequest()
        {
            _projectLobbyStateControllerMock
            .Setup(m => m.GetProjectLobbyStateAsync(It.IsAny <Guid>()))
            .Throws(new ValidationFailedException(new List <ValidationFailure>()));

            var response = await UserTokenBrowser.Get($"{Routing.ProjectsRoute}/{Guid.NewGuid()}/{Routing.ProjectLobbyStatePath}", BuildRequest);

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task GetProjectLobbyStateAsync_IfNotFoundExceptionIsThrown_ReturnsNotFound()
        {
            _projectLobbyStateControllerMock
            .Setup(m => m.GetProjectLobbyStateAsync(It.IsAny <Guid>()))
            .Throws(new NotFoundException(string.Empty));

            var response = await UserTokenBrowser.Get($"{Routing.ProjectsRoute}/{Guid.NewGuid()}/{Routing.ProjectLobbyStatePath}", BuildRequest);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
Beispiel #17
0
        public async void GetInProductTrainingViewsReturnsForbiddenWhenPermissionIsDenied()
        {
            PolicyEvaluatorMock
            .Setup(x => x.EvaluateAsync(It.IsAny <PolicyEvaluationContext>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(PermissionScope.Deny);

            var actual = await UserTokenBrowser.Get($"/v1/inproducttraining/viewed/{_defaultClientApplicationId}", BuildRequest);

            Assert.Equal(HttpStatusCode.Forbidden, actual.StatusCode);
        }
Beispiel #18
0
        public async void GetInProductTrainingViewsReturnsInternalServerErrorWhenControllerThrowsException()
        {
            _inProductTrainingControllerMock
            .Setup(x => x.GetViewedInProductTrainingAsync(It.IsAny <int>(), It.IsAny <Guid>()))
            .ThrowsAsync(new Exception());

            var actual = await UserTokenBrowser.Get($"/v1/inproducttraining/viewed/{_defaultClientApplicationId}", BuildRequest);

            Assert.Equal(HttpStatusCode.InternalServerError, actual.StatusCode);
            Assert.Equal(ResponseReasons.InternalServerErrorGetInProductTrainingViews, actual.ReasonPhrase);
        }
Beispiel #19
0
        public async Task GetGroupByIdReturnsBadRequest()
        {
            _controllerMock.Setup(m => m.GetGroupByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .Throws(new ValidationFailedException(new List <ValidationFailure>()));

            var validGroupId = Guid.NewGuid();

            var response = await UserTokenBrowser.Get(string.Format(Routing.GroupsWithIdBase, validGroupId), BuildRequest);

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Beispiel #20
0
        public async void GetInProductTrainingViewsReturnsBadRequestWhenControllerThrowsValidationException()
        {
            _inProductTrainingControllerMock
            .Setup(x => x.GetViewedInProductTrainingAsync(It.IsAny <int>(), It.IsAny <Guid>()))
            .ThrowsAsync(new ValidationFailedException(new[] { new ValidationFailure("property name", "error") }));

            var actual = await UserTokenBrowser.Get($"/v1/inproducttraining/viewed/{_defaultClientApplicationId}", BuildRequest);

            Assert.Equal(HttpStatusCode.BadRequest, actual.StatusCode);
            Assert.Equal(ResponseText.BadRequestValidationFailed, actual.ReasonPhrase);
        }
        public async void GetReturnsNotFoundWhenControllerThrowsNotFound()
        {
            _inProductTrainingControllerMock
            .Setup(x => x.GetInProductTrainingAsync(It.IsAny <Guid>()))
            .ThrowsAsync(new NotFoundException(""));

            var actual = await UserTokenBrowser.Get($"/v1/inProductTraining/{Guid.NewGuid()}", BuildRequest);

            Assert.Equal(HttpStatusCode.NotFound, actual.StatusCode);
            Assert.Equal(ResponseReasons.NotFoundInProductTraining, actual.ReasonPhrase);
        }
        public async Task GetMachineByIdReturnsInternalServerError()
        {
            _controllerMock.Setup(m => m.GetMachineByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid?>(), It.IsAny <CancellationToken>()))
            .Throws(new Exception());

            var validMachineId = Guid.NewGuid();

            var response = await UserTokenBrowser.Get(string.Format(Routing.MachinesWithIdBase, validMachineId), BuildRequest);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
        public async Task GetMachineByIdReturnsNotFoundIfItemDoesNotExist()
        {
            _controllerMock.Setup(m => m.GetMachineByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid?>(), It.IsAny <CancellationToken>()))
            .Throws(new NotFoundException(string.Empty));

            var validMachineId = Guid.NewGuid();

            var response = await UserTokenBrowser.Get(string.Format(Routing.MachinesWithIdBase, validMachineId), BuildRequest);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
        public async Task GetMachineByIdReturnsOk()
        {
            _controllerMock.Setup(m => m.GetMachineByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid?>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new Machine()));

            var validMachineId = Guid.NewGuid();

            var response = await UserTokenBrowser.Get(string.Format(Routing.MachinesWithIdBase, validMachineId), BuildRequest);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        public async Task GetGuestInviteByProjectIdReturnsOk()
        {
            _guestInviteControllerMock
            .Setup(x => x.GetValidGuestInvitesByProjectIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(new List <GuestInvite> {
                GuestInvite.Example()
            });

            var response = await UserTokenBrowser.Get($"{Routing.ProjectsRoute}/{Guid.NewGuid()}/{Routing.GuestInvitesPath}", BuildRequest);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        public async Task GetMachineByIdReturnsValidationFailedException()
        {
            var errors = Enumerable.Empty <ValidationFailure>();

            _controllerMock.Setup(m => m.GetMachineByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid?>(), It.IsAny <CancellationToken>()))
            .Throws(new ValidationFailedException(errors));

            var validMachineId = Guid.NewGuid();

            var response = await UserTokenBrowser.Get(string.Format(Routing.MachinesWithIdBase, validMachineId), BuildRequest);

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Beispiel #27
0
        public async Task GetGuestSessionsByProjectIdForUser_ReturnsOk()
        {
            _guestSessionControllerMock
            .Setup(x => x.GetGuestSessionsByProjectIdForUserAsync(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .ReturnsAsync(new List <GuestSession>()
            {
                new GuestSession()
            });

            var response = await UserTokenBrowser.Get($"{Routing.ProjectsRoute}/{Guid.NewGuid()}/{Routing.UsersPath}/{Guid.NewGuid()}/{Routing.GuestSessionsPath}", BuildRequest);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Beispiel #28
0
        public async void GetTenantIdListReturns500UponControllerRaisesException()
        {
            var tenantId = Guid.NewGuid();

            _tenantIds.Add(tenantId);

            _guestTenantControllerMock
            .Setup(x => x.GetTenantIdsForUserAsync(It.IsAny <Guid>()))
            .Throws <Exception>();

            var response = await UserTokenBrowser.Get(Routing.GuestTenantIdsRoute, BuildRequest);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
        public async Task GetMachineByKeyReturnsNotFoundIfItemDoesNotExist()
        {
            _controllerMock.Setup(m => m.GetMachineByKeyAsync(It.IsAny <string>(), It.IsAny <Guid?>(), It.IsAny <CancellationToken>()))
            .Throws(new NotFoundException(string.Empty));

            var response = await UserTokenBrowser.Get(Routing.Machines,
                                                      with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.Header("Content-Type", "application/json");
                with.Query("machinekey", "0123456789");
            });

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
        public async Task GetMachineByKeyReturnsInternalServerError()
        {
            _controllerMock.Setup(m => m.GetMachineByKeyAsync(It.IsAny <string>(), It.IsAny <Guid?>(), It.IsAny <CancellationToken>()))
            .Throws(new Exception());

            const string validMachineKey = "0123456789";
            var          response        = await UserTokenBrowser.Get(Routing.Machines,
                                                                      with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.Header("Content-Type", "application/json");
                with.Query("machinekey", validMachineKey);
            });

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }