Пример #1
0
        public async Task DeleteUserWithManagerRole_Returns204NoContentOnSuccess()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Manager", "manageruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var userName    = Guid.NewGuid().ToString();
            var password    = Guid.NewGuid().ToString();
            var email       = $"{Guid.NewGuid()}@gmail.com";
            var requestBody = new UserCreateDto
            {
                FirstName = "someUser",
                LastName  = "someUserLastName",
                UserName  = userName,
                Password  = password,
                Email     = email,
                Roles     = new List <string>()
                {
                    "Jogger"
                }
            };
            var users = await _client.GetFromJsonAsync <IEnumerable <UserDto> >("/api/users");

            if (users.Count() > 4)
            {
                var newlyCreatedUser = users.LastOrDefault();
                var deleteResponse   = await _client.DeleteAsync($"/api/users/{newlyCreatedUser.Id}");

                Assert.Equal(204, (int)deleteResponse.StatusCode);
            }
        }
Пример #2
0
        public async Task GetWeeklyReportsWithAdminRole_Returns200Ok()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.GetAsync("/api/joggings/2002/reports");

            Assert.Equal(200, (int)response.StatusCode);
        }
Пример #3
0
        public async Task DeleteJogging_Returns403ForbiddenWhenUserIsNotOwnerOfJogging()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "userWithoutJoggings");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.DeleteAsync("/api/joggings/1000");

            Assert.Equal(403, (int)response.StatusCode);
        }
Пример #4
0
        public async Task DeleteJoggingWithAdminUser_Returns404NotFoundWithInvalidJoggingId()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.DeleteAsync("/api/joggings/651115");

            Assert.Equal(404, (int)response.StatusCode);
        }
Пример #5
0
        public async Task GetAllUsersWithManagerRole_ReturnsListOfUsers()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Manager", "manageruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var users = await _client.GetFromJsonAsync <IEnumerable <UserDto> >("/api/users");

            Assert.IsType <List <UserDto> >(users);
        }
Пример #6
0
        public async Task DeleteUserWithJoggerRole_Returns403Forbidden()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "joggeruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var deleteResponse = await _client.DeleteAsync($"/api/users/{int.MaxValue}");

            Assert.Equal(403, (int)deleteResponse.StatusCode);
        }
Пример #7
0
        public async Task GetSingleJoggingWithJoggerRole_Returns403ForbiddedForJoggingNotCreatedByThisJogger()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "userWithoutJoggings");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.GetAsync("/api/joggings/1000");

            Assert.Equal(403, (int)response.StatusCode);
        }
Пример #8
0
        public async Task GetAllUsersWithJoggerRole_Returns403Forbidden()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "joggeruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.GetAsync("/api/users");

            Assert.Equal(403, (int)response.StatusCode);
        }
Пример #9
0
        public async Task GetSingleJoggingWithJoggerRole_ReturnsJoggingOnlyJoggerUserCreated()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "joggeruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var jogging = await _client.GetFromJsonAsync <JoggingDto>("/api/joggings/1000");

            Assert.Equal(2002, jogging.UserId);
        }
Пример #10
0
        public async Task GetSingleJoggingWithAdminRole_WhenCalledReturnsSingleJogging()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var jogging = await _client.GetFromJsonAsync <JoggingDto>("/api/joggings/1000");

            Assert.IsType <JoggingDto>(jogging);
        }
Пример #11
0
        public async Task GetSingleJogginWithManagerRole_WhenCalledReturns403Forbidded()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Manager", "manageruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.GetAsync("/api/joggings/1000");

            Assert.Equal(403, (int)response.StatusCode);
        }
Пример #12
0
        public async Task GetWeeklyReportsWithJoggerRole_Returns403ForbiddenWhenJoggerIsNotOwner()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "userWithoutJoggings");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.GetAsync("/api/joggings/2002/reports");

            Assert.Equal(403, (int)response.StatusCode);
        }
Пример #13
0
        public async Task GetAllUsersWithManagerRole_Returns200OkAndListUserDtos()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Manager", "manager");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.GetAsync("/api/users");

            Assert.Equal(200, (int)response.StatusCode);
        }
Пример #14
0
        public async Task GetJoggingsWithJoggerRoleWhoHasNotAnyJoggings_WhenCalledReturnsEmptyList()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "userWithoutJoggings");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var joggerUserId2003Joggings = await _client.GetFromJsonAsync <IEnumerable <JoggingDto> >("/api/joggings");

            Assert.Empty(joggerUserId2003Joggings);
        }
Пример #15
0
        public async Task GetSingleJoggingById_WhenCalledReturns404()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "joggeruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.GetAsync("/api/joggings/565415");

            Assert.Equal(404, (int)response.StatusCode);
        }
Пример #16
0
        public async Task GetSingleUser_Returns404NotFound()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.GetAsync($"/api/users/{int.MaxValue}");

            Assert.Equal(404, (int)response.StatusCode);
        }
Пример #17
0
        public async Task UpdateJogging_ReturnsBadRequestWithoutRequestBody()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "joggeruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var requestBody = new JoggingUpdateDto();
            var response    = await _client.PutAsJsonAsync("/api/joggings/1000", requestBody);

            Assert.Equal(422, (int)response.StatusCode);
        }
Пример #18
0
        public async Task GetJoggingsWithJoggerRole_WhenCalledReturns200Ok()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "joggeruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.GetAsync("/api/joggings");

            response.EnsureSuccessStatusCode();
            Assert.Equal(200, (int)response.StatusCode);
        }
Пример #19
0
        public async Task GetJoggingsWithJoggerRole_WhenCalledReturnsJoggingsOnlyJoggerUserCreated()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "joggeruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var joggerUserId2002Joggings = await _client.GetFromJsonAsync <IEnumerable <JoggingDto> >("/api/joggings");

            foreach (var j in joggerUserId2002Joggings)
            {
                Assert.Equal(2002, j.UserId);
            }
        }
Пример #20
0
        public async Task GetSingleUserWithAdminRole_ReturnsSingleUser()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var user = await _client.GetFromJsonAsync <UserDto>("/api/users/2002");

            if (user != null)
            {
                Assert.IsType <UserDto>(user);
            }
        }
Пример #21
0
        public async Task GetAllUsers_ReturnsPagingInfoInResponseHeader()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var response = await _client.GetAsync("/api/users");

            var xPaginationResponseHeader = response.Headers.Where(h => h.Key == "X-Pagination").FirstOrDefault();
            var paginationValues          = xPaginationResponseHeader.Value.FirstOrDefault();

            Assert.Contains("TotalPages", paginationValues);
            Assert.Contains("PageSize", paginationValues);
        }
        public async Task GetAllJoggings_LessThan40Test()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var joggings = await _client.GetFromJsonAsync <IEnumerable <JoggingDto> >(@"https://localhost:44391/api/joggings?$filter=temperatureC lt 40");

            if (joggings.Count() > 0)
            {
                foreach (var j in joggings)
                {
                    Assert.True(j.TemperatureC < 40);
                }
            }
        }
        public async Task GetAllJoggings_AND_OperatorTest_TemperatureLessThan40_And_JoggingDateGreater1January2019()
        {
            var url      = @"https://localhost:44391/api/joggings?$filter=(temperatureC lt 40) And (joggingDate gt 2019-01-01)";
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var joggings = await _client.GetFromJsonAsync <IEnumerable <JoggingDto> >(url);

            if (joggings.Count() > 0)
            {
                foreach (var j in joggings)
                {
                    Assert.True((j.TemperatureC < 40) && (j.JoggingDate > new DateTime(2019, 1, 1)));
                }
            }
        }
        public async Task GetAllJoggings_AND_Operator_and_OR_operatorTest()
        {
            var url      = @"https://localhost:44391/api/joggings?$filter=(joggingDate eq 2020-10-01) And ((distanceInMeters lt 6000) Or (distanceInMeters gt 500))";
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var joggings = await _client.GetFromJsonAsync <IEnumerable <JoggingDto> >(url);

            if (joggings.Count() > 0)
            {
                foreach (var j in joggings)
                {
                    Assert.True(j.JoggingDate.Date.Equals(new DateTime(2020, 10, 01)) && (j.DistanceInMeters < 6000 || j.DistanceInMeters > 500));
                }
            }
        }
Пример #25
0
        public async Task CreateJogging_Returns422BadRequestValidatesDistanceInMetersField()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var requestBody = new JoggingCreateDto
            {
                JoggingDate = new DateTime(2020, 10, 29),
                Location    = "Philadelphia",
                JoggingDurationInMinutes = 30,
                UserId = 2002
            };
            var response = await _client.PostAsJsonAsync("/api/joggings", requestBody);

            Assert.Equal(422, (int)response.StatusCode);
        }
Пример #26
0
        public async Task UpdateJogging_Returns404NotFound()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var requestBody = new JoggingUpdateDto
            {
                JoggingDate              = new DateTime(2020, 10, 29),
                DistanceInMeters         = 5000,
                Location                 = "Philadelphia",
                JoggingDurationInMinutes = 30,
            };
            var response = await _client.PutAsJsonAsync("/api/joggings/654651", requestBody);

            Assert.Equal(404, (int)response.StatusCode);
        }
Пример #27
0
        public async Task UpdateJogging_Returns403ForbiddenWhenUserIsNotOwnerOfJogging()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "userWithoutJoggings");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var requestBody = new JoggingUpdateDto
            {
                JoggingDate              = new DateTime(2020, 10, 29),
                DistanceInMeters         = 5000,
                Location                 = "Philadelphia",
                JoggingDurationInMinutes = 30,
            };
            var response = await _client.PutAsJsonAsync("/api/joggings/1000", requestBody);

            Assert.Equal(403, (int)response.StatusCode);
        }
Пример #28
0
        public async Task UpdateUserWithInvalidData_Returns422BadRequest()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Admin", "adminuser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var requestBody = new UserUpdateDto
            {
                FirstName   = "UpdatedUser",
                LastName    = "UpdatedLasName",
                PhoneNumber = "55525222",
                Email       = "*****@*****.**",
            };
            var response = await _client.PutAsJsonAsync("/api/users/2002", requestBody);

            Assert.Equal(422, (int)response.StatusCode);
        }
Пример #29
0
        public async Task UpdateUserWithManagerRole_Returns204NoContentOnSuccess()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Manager", "manageruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var requestBody = new UserUpdateDto
            {
                FirstName   = "UpdatedUser",
                LastName    = "UpdatedLasName",
                PhoneNumber = "55525222",
                Email       = "*****@*****.**",
                UserName    = "******"
            };
            var response = await _client.PutAsJsonAsync("/api/users/2002", requestBody);

            Assert.Equal(204, (int)response.StatusCode);
        }
Пример #30
0
        public async Task UpdateUserWithJoggerRole_Returns403ForbiddenWhenUserIsNotOwner()
        {
            var jwtToken = MockJWTTokens.CreateRoleJWTToken("Jogger", "joggeruser");

            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
            var requestBody = new UserUpdateDto
            {
                FirstName   = "UpdatedUser",
                LastName    = "UpdatedLasName",
                PhoneNumber = "55525222",
                Email       = "*****@*****.**",
                UserName    = "******"
            };
            var response = await _client.PutAsJsonAsync("/api/users/2001", requestBody);

            Assert.Equal(403, (int)response.StatusCode);
        }