예제 #1
0
        public async Task GivenValidRequest_ShouldDeleteUser()
        {
            var client = _factory.GetAnonymousClient();

            var response = await client.DeleteAsync($"/api/users/{Utilities.KnownUserID2}");

            response.EnsureSuccessStatusCode();
        }
예제 #2
0
        public async Task GivenId_ReturnsSuccessStatusCode()
        {
            var client = _factory.GetAnonymousClient();

            var validId = 2;

            var response = await client.DeleteAsync($"/api/customers/delete/{validId}");

            response.EnsureSuccessStatusCode();
        }
예제 #3
0
        public async Task GivenId_ReturnUserModel()
        {
            var client = await _factory.GetAnonymousClient();

            var id       = 1;
            var response = await client.GetAsync($"/api/users/{id}");

            response.EnsureSuccessStatusCode();

            var result = await ClientUtilities.GetResponseContent <GetUserByIdQueryResponse>(response);

            Assert.IsType <GetUserByIdQueryResponse>(result);
            Assert.Equal(id, result.Id);
        }
예제 #4
0
        public async Task GivenId_ReturnsCustomerViewModel()
        {
            var client = _factory.GetAnonymousClient();

            var id = 1;

            var response = await client.GetAsync($"/api/customers/get/{id}");

            response.EnsureSuccessStatusCode();

            var customer = await Utilities.GetResponseContent <CustomerDetailVm>(response);

            Assert.Equal(id, customer.Id);
        }
예제 #5
0
        public async Task GivenExistingUserId_ShouldReturnUser()
        {
            var client = _factory.GetAnonymousClient();

            var userId = Utilities.KnownUserID1;

            var response = await client.GetAsync($"/api/users/{userId}");

            response.EnsureSuccessStatusCode();

            var user = await Utilities.GetResponseContent <UserDto>(response);

            Assert.Equal(userId, user.UserId);
        }
        public async Task GivenUnauthorizedUser_ReturnUnauthorizedStatusCode()
        {
            var client = await _factory.GetAnonymousClient();

            var command = new UpdatePetCommand
            {
                Name         = "Wau",
                Age          = 5,
                Gender       = Domain.Enums.Gender.Male,
                Weight       = 0.2,
                Height       = 0.3,
                IsSterilized = true,
                Description  = "Something about",
                PhotoCode    = "",
                CategoryId   = 1,
                UserId       = 3
            };

            var content = ClientUtilities.GetRequestContent(command);

            var validPetId = 1;

            var response = await client.PutAsync($"/api/pets/{validPetId}", content);

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
예제 #7
0
        public async Task ReturnsSuccessResult()
        {
            var client = factory.GetAnonymousClient();

            CreateUserRequest user = new CreateUserRequest
            {
                Email    = "*****@*****.**",
                FullName = "Fake Approver Account",
                Password = "******",
                Roles    = new string[] { "Fake Role", },
                UserName = "******"
            };
            LoginToken loginToken = await auth.GetTokenForTestUser(user, factory, client);

            //var response = await client.GetAsync("/api/v1/category/get");

            var url = "/api/v1/category/get";

            var response = await auth.SendRequest(HttpMethod.Post, url, null, loginToken);

            response.EnsureSuccessStatusCode();

            var responseString = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <List <Category> >(responseString);

            Assert.IsType <List <Category> >(result);
            Assert.NotEmpty(result);
        }
예제 #8
0
        public async Task GivenUpdateCustomerCommand_ReturnsSuccessStatusCode()
        {
            var client = _factory.GetAnonymousClient();

            var command = new UpdateCustomerCommand
            {
                Id   = 2,
                Name = "New Name"
            };

            var content = Utilities.GetRequestContent(command);

            var response = await client.PutAsync($"/api/customers/update/{command.Id}", content);

            response.EnsureSuccessStatusCode();
        }
예제 #9
0
        public async Task GivenValidRequest_ShouldCreateNewUser()
        {
            var client  = _factory.GetAnonymousClient();
            var command = new CreateUserCommand
            {
                FirstName    = "User 1",
                LastName     = "Test",
                EmailAddress = "*****@*****.**",
                DOB          = DateTime.Today.AddYears(-25)
            };

            var response = await client.PostAsync("/api/users", Utilities.GetRequestContent(command));

            response.EnsureSuccessStatusCode();

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
예제 #10
0
        public async Task QueryPlaceholder_ReturnsUnauthorizedResult()
        {
            var client = _factory.GetAnonymousClient();

            var response = await client.GetAsync("UrlPlaceholder");

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
예제 #11
0
        public async Task GivenUnauthorizedUser_ReturnUnauthorizedStatusCode()
        {
            var client = await _factory.GetAnonymousClient();

            var response = await client.GetAsync("/api/comments");

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
예제 #12
0
        public async Task Upload_CsvFileReturnSuccess()
        {
            var url    = "/api/upload";
            var client = _factory.GetAnonymousClient();

            using var file1    = File.OpenRead(@"Files\Test.csv");
            using var content1 = new StreamContent(file1);
            using var formData = new MultipartFormDataContent
                  {
                      { content1, "file", "Test.csv" }
                  };

            var response = await client.PostAsync(url, formData);

            response.EnsureSuccessStatusCode();

            Assert.Equal("OK", response.StatusCode.ToString());
        }
예제 #13
0
        public async Task GivenValidRequest_ShouldUpdateUser()
        {
            var client  = _factory.GetAnonymousClient();
            var command = new UpdateUserCommand
            {
                UserId       = Utilities.KnownUserID1,
                FirstName    = "User 1",
                LastName     = "Test",
                EmailAddress = "*****@*****.**",
                DOB          = DateTime.Today.AddYears(-25)
            };

            HttpContent content = Utilities.GetRequestContent(command);

            var response = await client.PutAsync($"/api/users/{Utilities.KnownUserID1}", content);

            response.EnsureSuccessStatusCode();
        }
        public async Task GivenUser_ReturnsJwtToken()
        {
            var client = await _factory.GetAnonymousClient();

            var command = new UserLoginCommand
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            var content = ClientUtilities.GetRequestContent(command);

            var response = await client.PostAsync($"/api/users/login", content);

            var responseContent = await ClientUtilities.GetResponseContent <UserLoginCommandResponse>(response);

            Assert.IsType <UserLoginCommandResponse>(responseContent);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        public async Task GivenUnauthorizedUser_ReturnUnauthorizedStatusCode()
        {
            var client = await _factory.GetAnonymousClient();

            var validPetId = 1;

            var response = await client.DeleteAsync($"/api/pets/{validPetId}");

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
예제 #16
0
        public async Task GivenNotAutenticatedUser_ReturnUnauthorizedStatusCode()
        {
            var client = await _factory.GetAnonymousClient();

            var validUserId = 1;

            var response = await client.GetAsync($"/api/users/{validUserId}/likes");

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
        public async Task GivenUserEmailAndExists_ReturnsConflictStatusCode()
        {
            var client = await _factory.GetAnonymousClient();

            var command = new CreateUserCommand
            {
                Email       = "*****@*****.**",
                Password    = "******",
                PhoneNumber = "865344095",
                FirstName   = "Vard",
                LastName    = "Pavard"
            };

            var content = ClientUtilities.GetRequestContent(command);

            var response = await client.PostAsync($"/api/users/register", content);

            Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
        }
예제 #18
0
        public async Task ReturnsTransactionDtoList()
        {
            var client = _factory.GetAnonymousClient();

            var response = await client.GetAsync("/api/transaction");

            response.EnsureSuccessStatusCode();

            var vm = await Utilities.GetResponseContent <List <TransactionDto> >(response);

            Assert.IsType <List <TransactionDto> >(vm);
        }
예제 #19
0
        public async Task GivenValidRequest_ShouldReturnUsers()
        {
            var client = _factory.GetAnonymousClient();

            var response = await client.GetAsync($"/api/users");

            response.EnsureSuccessStatusCode();

            var users = await Utilities.GetResponseContent <IEnumerable <UserDto> >(response);

            Assert.True(users.Any());
        }
예제 #20
0
        public async Task ReturnsCustomersListViewModel()
        {
            var client = _factory.GetAnonymousClient();

            var response = await client.GetAsync("/api/customers/getall");

            response.EnsureSuccessStatusCode();

            var vm = await Utilities.GetResponseContent <CustomersListVm>(response);

            Assert.IsType <CustomersListVm>(vm);
            Assert.NotEmpty(vm.Customers);
        }
예제 #21
0
        public async Task ReturnSuccessResult()
        {
            var client = await _factory.GetAnonymousClient();

            var response = await client.GetAsync("/api/categories");

            response.EnsureSuccessStatusCode();

            var result = await ClientUtilities.GetResponseContent <List <GetAllCategoriesByUserIdQueryResponse> >(response);

            Assert.IsType <List <GetAllCategoriesByUserIdQueryResponse> >(result);
            Assert.NotEmpty(result);
        }
예제 #22
0
        public async Task GivenUserIsUnauthorized_ReturnUnauthorizedStatusCode()
        {
            var client = await _factory.GetAnonymousClient();

            var validUserId = 1;
            var validPetId  = 1;

            var content = ClientUtilities.GetRequestContent(null);

            var response = await client.PostAsync($"/api/users/{validUserId}/pets/{validPetId}/likes", content);

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
        public async Task ReturnsSuccessResult()
        {
            var client   = _factory.GetAnonymousClient();
            var response = await client.GetAsync("/api/category/all");

            response.EnsureSuccessStatusCode();

            var responseString = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <List <CategoryListViewModel> >(responseString);

            Assert.IsType <List <CategoryListViewModel> >(result);
            Assert.NotEmpty(result);
        }
        public async Task GetCategories()
        {
            // Act
            var client   = _factory.GetAnonymousClient();
            var response = await client.GetAsync("/api/v1/categories/");;

            // Assert
            response.EnsureSuccessStatusCode();
            var categories = await Utilities.GetResponseContent <IEnumerable <Category> >(response);

            categories.Count().Should().Be(3);
            categories.Should().NotBeEmpty();
        }
예제 #25
0
        public async Task Should_GetSuccessJSONResponse_When_ValidJsonPurchaseInfoSupplied(string paymentInfoJson, string expectedResponseJson)
        {
            //Arrange
            var client             = _factory.GetAnonymousClient();
            var apiEndPoint        = "/api/purchase";
            var contentGrossAmount = Utilities.GetRequestContentFromJSONString(paymentInfoJson);
            PurchaseDataModel expectedResponseObj = JsonConvert.DeserializeObject <PurchaseDataModel>(expectedResponseJson);

            //Act
            var httpResponse = await client.PostAsync(apiEndPoint, contentGrossAmount);

            var responseString = await httpResponse.Content.ReadAsStringAsync();

            PurchaseDataModel responseObj = JsonConvert.DeserializeObject <PurchaseDataModel>(responseString);

            // Assert - HTTP success response
            Assert.True(httpResponse.IsSuccessStatusCode);

            //Assert - compare httpresponse with expectedResponse
            Assert.Equal(expectedResponseObj.VATRate, responseObj.VATRate);
            Assert.Equal(expectedResponseObj.GrossAmount, responseObj.GrossAmount);
            Assert.Equal(expectedResponseObj.NetAmount, responseObj.NetAmount);
            Assert.Equal(expectedResponseObj.VATAmount, responseObj.VATAmount);
        }
예제 #26
0
        public async Task GivenUnauthorizedUser_ReturnsUnauthorizedStatusCode()
        {
            var client = await _factory.GetAnonymousClient();

            var command = new CreateCategoryCommand
            {
                Title = "Snakes"
            };

            var content = ClientUtilities.GetRequestContent(command);

            var response = await client.PostAsync($"/api/categories", content);

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
예제 #27
0
        public async Task GivenCreateCustomerCommand_ReturnsSuccessStatusCode()
        {
            var client = _factory.GetAnonymousClient();

            var command = new CreateCustomerCommand
            {
                Id   = 12,
                Name = "John Does"
            };

            var content = Utilities.GetRequestContent(command);

            var response = await client.PostAsync($"/api/customers/create", content);

            response.EnsureSuccessStatusCode();
        }
예제 #28
0
        public async Task GivenUnauthorizedUser_ReturnUnauthorizedStatusCode()
        {
            var client = await _factory.GetAnonymousClient();

            var command = new CreateCommentCommand
            {
                PetId  = 1,
                UserId = 1,
                Text   = "Comment text"
            };

            var content = ClientUtilities.GetRequestContent(command);

            var response = await client.PostAsync("/api/comments", content);

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
예제 #29
0
        public async Task GivenUnauthorizedUser_ReturnUnauthorizedStatusCode()
        {
            var client = await _factory.GetAnonymousClient();

            var command = new UpdateCommentCommand
            {
                Text   = "Comment text",
                UserId = 2
            };

            var content = ClientUtilities.GetRequestContent(command);

            var validId = 1;

            var response = await client.PutAsync($"/api/comments/{validId}", content);

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
        public async Task GivenUnauthorizedUser_ReturnsUnauthorizedStatusCode()
        {
            var client = await _factory.GetAnonymousClient();

            var validId = 1;

            var command = new UpdateUserCommand
            {
                PhoneNumber = "865344095",
                FirstName   = "Vard",
                LastName    = "Pavard"
            };

            var content = ClientUtilities.GetRequestContent(command);

            var response = await client.PutAsync($"/api/users/{validId}", content);

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