Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions APITestingUnit/APITestingUnit.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WebApiTraining2\WebApiTraining2.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions APITestingUnit/BaseTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc.Testing;
namespace APITestingUnit
{
public class BaseTest
{
protected readonly WebApplicationFactory<Program> _factory;
public BaseTest()
{
_factory = new WebApplicationFactory<Program>();
}

public HttpClient GetClient => _factory.CreateClient();
}
}
53 changes: 53 additions & 0 deletions APITestingUnit/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Contracts.RequestModels.Customer;
using Newtonsoft.Json;
using System.Text;

namespace APITestingUnit
{
public class Tests : BaseTest
{
private readonly HttpClient _client;
public Tests()
{
_client = GetClient;
}
[SetUp]
public void Setup()
{
}

[Test]
public async Task Test1()
{
var client = _factory.CreateClient();
/*var product = new Product
{
ProductID = Guid.NewGuid(),
Name = "Product 1",
Price = 10000
};*/

var fromBody = new CreateCustomerRequest
{
Email = "jemynathanael0821@gmail.com",
Name = "Jemy Nathanael"
};

var requestBody = new StringContent(JsonConvert.SerializeObject(fromBody), Encoding.UTF8, "application/json");
var response = await client.PostAsync("api/v1/customer", requestBody);

//var response = await client.GetAsync("api/v1/customer");
//var response = await client.PostAsync("api/v1/customer", new StringContent(JsonConvert.SerializeObject(fromBody), Encoding.UTF8, "");

Assert.That(response.IsSuccessStatusCode, Is.False);
Assert.Pass();
}

public async Task TestGet()
{
var client = _factory.CreateClient();
var response = await client.GetAsync("api/v1/customer");
Assert.That(response.IsSuccessStatusCode, Is.True);
}
}
}
12 changes: 12 additions & 0 deletions Contracts/RequestModels/Cart/CreateCartRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Contracts.ResponseModels.Cart;
using MediatR;

namespace Contracts.RequestModels.Cart
{
public class CreateCartRequest : IRequest<CreateCartResponse>
{
public int Quantity { get; set; }
public Guid CustomerId { get; set; }
public Guid ProductId { get; set; }
}
}
10 changes: 10 additions & 0 deletions Contracts/RequestModels/Cart/DeleteCartRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Contracts.ResponseModels.Cart;
using MediatR;

namespace Contracts.RequestModels.Cart
{
public class DeleteCartRequest : IRequest<DeleteCartResponse>
{
public Guid CartId { get; set; }
}
}
11 changes: 11 additions & 0 deletions Contracts/RequestModels/Cart/GetCartByIdRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Contracts.ResponseModels.Cart;
using MediatR;

namespace Contracts.RequestModels.Cart
{
public class GetCartByIdRequest : IRequest<GetCartByIdResponse>
{
public Guid? CartId { get; set; }

}
}
9 changes: 9 additions & 0 deletions Contracts/RequestModels/Cart/GetCartRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Contracts.ResponseModels.Cart;
using MediatR;

namespace Contracts.RequestModels.Cart
{
public class GetCartRequest : IRequest<GetCartResponse>
{
}
}
15 changes: 15 additions & 0 deletions Contracts/RequestModels/Cart/UpdateCartRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Contracts.ResponseModels.Cart;
using MediatR;

namespace Contracts.RequestModels.Cart
{
public class UpdateCartRequest : UpdateCartModel, IRequest<UpdateCartResponse>
{
public Guid? CartId { get; set; }
}

public class UpdateCartModel
{
public int Quantity { get; set; }
}
}
10 changes: 10 additions & 0 deletions Contracts/RequestModels/Customer/DeleteCustomerDataRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Contracts.ResponseModels.Customer;
using MediatR;

namespace Contracts.RequestModels.Customer
{
public class DeleteCustomerDataRequest : IRequest<DeleteCustomerDataResponse>
{
public Guid? CustomerId { get; set; }
}
}
16 changes: 16 additions & 0 deletions Contracts/RequestModels/Customer/EditCustomerDataListRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Contracts.ResponseModels.Customer;
using MediatR;

namespace Contracts.RequestModels.Customer
{
public class EditCustomerDataListRequest : UpdateCustomerDataModel, IRequest<EditCustomerDataListResponse>
{
public Guid? Id { get; set; }
}

public class UpdateCustomerDataModel
{
public string Name { get; set;} = string.Empty;
public string Email { get; set; } = string.Empty;
}
}
12 changes: 12 additions & 0 deletions Contracts/RequestModels/Customer/GetCustomerDataByIdRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Contracts.ResponseModels.Customer;
using MediatR;

namespace Contracts.RequestModels.Customer
{
public class GetCustomerDataByIdRequest : IRequest<GetCustomerDataByIdResponse>
{
public Guid? CustomerId { get; set; }
}


}
11 changes: 11 additions & 0 deletions Contracts/RequestModels/Product/CreateProductRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Contracts.ResponseModels.Product;
using MediatR;

namespace Contracts.RequestModels.Product
{
public class CreateProductRequest : IRequest<CreateProductResponse>
{
public string ProductName { get; set; } = string.Empty;
public decimal ProductPrice { get; set; }
}
}
11 changes: 11 additions & 0 deletions Contracts/RequestModels/Product/DeleteProductRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Contracts.ResponseModels.Customer;
using Contracts.ResponseModels.Product;
using MediatR;

namespace Services.RequestHandlers.ManageProduct
{
public class DeleteProductRequest : IRequest<DeleteProductResponse>
{
public Guid ProductId { get; set; }
}
}
10 changes: 10 additions & 0 deletions Contracts/RequestModels/Product/GetProductByIdRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Contracts.ResponseModels.Product;
using MediatR;

namespace Contracts.RequestModels.Product
{
public class GetProductByIdRequest : IRequest<GetProductByIdResponse>
{
public Guid? ProductId { get; set; }
}
}
9 changes: 9 additions & 0 deletions Contracts/RequestModels/Product/GetProductDataRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Contracts.ResponseModels.Product;
using MediatR;

namespace Contracts.RequestModels.Product
{
public class GetProductDataRequest : IRequest<GetProductDataResponse>
{
}
}
16 changes: 16 additions & 0 deletions Contracts/RequestModels/Product/UpdateProductDataRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Contracts.ResponseModels.Product;
using MediatR;

namespace Contracts.RequestModels.Product
{
public class UpdateProductDataRequest : UpdateProductModel, IRequest<UpdateProductDataResponse>
{
public Guid? Id { get; set; }
}

public class UpdateProductModel
{
public string ProductName { get; set; } = string.Empty;
public decimal ProductPrice { get; set; }
}
}
7 changes: 7 additions & 0 deletions Contracts/ResponseModels/Cart/CreateCartResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Contracts.ResponseModels.Cart
{
public class CreateCartResponse
{
public Guid CartId { get; set; }
}
}
8 changes: 8 additions & 0 deletions Contracts/ResponseModels/Cart/DeleteCartResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Contracts.ResponseModels.Cart
{
public class DeleteCartResponse
{
public bool IsSuccess { get; set; }
public string Message { get; set; } = string.Empty;
}
}
10 changes: 10 additions & 0 deletions Contracts/ResponseModels/Cart/GetCartByIdResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Contracts.ResponseModels.Cart
{
public class GetCartByIdResponse
{
public string CustomerName { get; set; } = string.Empty;
public string ProductName { get; set; } = string.Empty;
public decimal Price { get; set; }
public int Quantity { get; set; }
}
}
16 changes: 16 additions & 0 deletions Contracts/ResponseModels/Cart/GetCartResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Contracts.ResponseModels.Cart
{
public class GetCartResponse
{
public List<CartData> CartDatas { get; set; } = new List<CartData>();
}

public class CartData
{
public Guid? CartId { get; set; }
public string CustomerName { get; set; } = string.Empty;
public string ProductName { get; set; } = string.Empty;
public decimal Price { get; set; }
public int Quantity { get; set; }
}
}
8 changes: 8 additions & 0 deletions Contracts/ResponseModels/Cart/UpdateCartResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Contracts.ResponseModels.Cart
{
public class UpdateCartResponse
{
public bool IsSuccess { get; set; }
public string Message { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Contracts.ResponseModels.Customer
{
public class DeleteCustomerDataResponse
{
public bool IsSuccess { get; set; }
public string Message { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Contracts.ResponseModels.Customer
{
public class EditCustomerDataListResponse
{
public bool IsSuccess { get; set; }
public string Message { get; set; } = string.Empty;
}
}
14 changes: 14 additions & 0 deletions Contracts/ResponseModels/Customer/GetCustomerDataByIdResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contracts.ResponseModels.Customer
{
public class GetCustomerDataByIdResponse
{
public string CustomerName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
}
}
7 changes: 7 additions & 0 deletions Contracts/ResponseModels/Product/CreateProductResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Contracts.ResponseModels.Product
{
public class CreateProductResponse
{
public Guid ProductId { get; set; }
}
}
14 changes: 14 additions & 0 deletions Contracts/ResponseModels/Product/DeleteProductResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contracts.ResponseModels.Product
{
public class DeleteProductResponse
{
public bool IsSuccess { get; set; }
public string Message { get; set; } = string.Empty;
}
}
8 changes: 8 additions & 0 deletions Contracts/ResponseModels/Product/GetProductByIdResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Contracts.ResponseModels.Product
{
public class GetProductByIdResponse
{
public string ProductName { get; set; } = string.Empty;
public decimal ProductPrice { get; set; }
}
}
14 changes: 14 additions & 0 deletions Contracts/ResponseModels/Product/GetProductDataResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Contracts.ResponseModels.Product
{
public class GetProductDataResponse
{
public List<ProductData> Products { get; set; } = new List<ProductData>();
}

public class ProductData
{
public Guid ProductId { get; set; }
public string ProductName { get; set; } = string.Empty;
public decimal ProductPrice { get; set; }
}
}
Loading