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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ docker-compose up
Детали конфигурации docker-compose вы можете найти [здесь](https://github.com/bezlla/RtuItLab/blob/master/src/docker-compose.yml).
### UnitTests

В проекте есть Smoke - тесты, для запуска которых необходимо запустить менеджера RabbitMQ.
В проекте есть Smoke - тесты, для запуска которых необходимо запустить менеджера RabbitMQ и SQLServer из docker вручную. Дефолтные настройки для них прописаны в файлах ```appsettings.Tests.json```, которые подключаются во время прогона тестов.

Они покрывают доступность функционала.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace RtuItLab.Infrastructure.MassTransit.Purchases.Responses
{
public class GetTransactionsResponse
{
public List<Transaction> Transactions { get; set; }
public int Count { get; set; }
public ICollection<Transaction> Transactions { get; set; }
public int Count => Transactions.Count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace RtuItLab.Infrastructure.MassTransit.Shops.Responses
{
public class GetProductsResponse
{
public bool Success { get; set; }
public List<Product> Products { get; set; }
public ICollection<Product> Products { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using RtuItLab.Infrastructure.Models.Shops;

namespace RtuItLab.Infrastructure.MassTransit.Shops.Responses
{
public class GetShopsResponse
{
public ICollection<Shop> Shops { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using RtuItLab.Infrastructure.Filters;
using RtuItLab.Infrastructure.MassTransit;
using RtuItLab.Infrastructure.Models;
using RtuItLab.Infrastructure.Models.Identity;
using System;
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Identity/Identity.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void ConfigureServices(IServiceCollection services)
x.UsingRabbitMq((context, cfg) =>
{

cfg.Host(new Uri("rabbitmq://host.docker.internal/"));
cfg.Host(new Uri(Configuration["RabbitMq"]));
cfg.ReceiveEndpoint("identityQueue", e =>
{
e.PrefetchCount = 20;
Expand Down
13 changes: 13 additions & 0 deletions src/Services/Identity/Identity.API/appsettings.Tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Secret": "7c9e6679-7425-40de-944b-e07fc1f90ae6",
"DefaultConnection": "Server=127.0.0.1;Database=identity;User=sa;Password=YourPassword123;",
"RabbitMq": "rabbitmq://127.0.0.1/"
}
3 changes: 2 additions & 1 deletion src/Services/Identity/Identity.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
},
"AllowedHosts": "*",
"Secret": "7c9e6679-7425-40de-944b-e07fc1f90ae6",
"DefaultConnection": "Server=db;Database=identity;User=sa;Password=YourPassword123;"
"DefaultConnection": "Server=db;Database=identity;User=sa;Password=YourPassword123;",
"RabbitMq": "rabbitmq://host.docker.internal/"
}
2 changes: 0 additions & 2 deletions src/Services/Identity/Identity.Domain/Services/UserService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Identity.DAL.ContextModels;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using RtuItLab.Infrastructure.Models.Identity;
Expand All @@ -11,7 +10,6 @@
using System.Text;
using System.Threading.Tasks;
using RtuItLab.Infrastructure.Exceptions;
using RtuItLab.Infrastructure.MassTransit;

namespace Identity.Domain.Services
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public TestServer CreateServer()
.UseContentRoot(Path.GetDirectoryName(path))
.ConfigureAppConfiguration(cb =>
{
cb.AddJsonFile("appsettings.json", optional: false)
cb.AddJsonFile("appsettings.Tests.json", optional: false)
.AddEnvironmentVariables();
})
.UseUrls("http://*:7001")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using MassTransit;
using Purchases.Domain.Services;
using RtuItLab.Infrastructure.MassTransit.Purchases.Responses;
using RtuItLab.Infrastructure.Models.Identity;

namespace Purchases.API.Consumers
Expand All @@ -13,8 +14,8 @@ public GetTransactions( IPurchasesService purchasesService) : base(purchasesServ
}
public async Task Consume(ConsumeContext<User> context)
{
var order = await PurchasesService.GetTransactions(context.Message);
await context.RespondAsync(order);
var transactions = await PurchasesService.GetTransactions(context.Message);
await context.RespondAsync(new GetTransactionsResponse() { Transactions = transactions });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using RtuItLab.Infrastructure.Filters;
using RtuItLab.Infrastructure.MassTransit;
using RtuItLab.Infrastructure.MassTransit.Purchases.Requests;
using RtuItLab.Infrastructure.MassTransit.Purchases.Responses;
using RtuItLab.Infrastructure.Models;
using RtuItLab.Infrastructure.Models.Identity;
using RtuItLab.Infrastructure.Models.Purchases;
Expand All @@ -29,8 +30,8 @@ public PurchasesController(IBusControl busControl)
public async Task<IActionResult> GetAllHistory()
{
var user = HttpContext.Items["User"] as User;
var response = await GetResponseRabbitTask<User, ICollection<Transaction>>(user);
return Ok(ApiResult<ICollection<Transaction>>.Success200(response));
var response = await GetResponseRabbitTask<User, GetTransactionsResponse>(user);
return Ok(ApiResult<GetTransactionsResponse>.Success200(response));
}
[HttpGet("{id}")]
public async Task<IActionResult> GetHistory(int id)
Expand Down Expand Up @@ -58,7 +59,7 @@ await GetResponseRabbitTask<AddTransactionRequest, BaseResponseMassTransit>(new
return Ok(ApiResult<int>.Success200(transaction.Id));
}
[HttpPut("update")]
public async Task<IActionResult> UpdateTransaction( [FromBody] UpdateTransaction updateTransaction)
public async Task<IActionResult> UpdateTransaction([FromBody] UpdateTransaction updateTransaction)
{
if (!ModelState.IsValid) return BadRequest("Invalid request");
var user = HttpContext.Items["User"] as User;
Expand Down
5 changes: 2 additions & 3 deletions src/Services/Purchases/Purchases.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public void ConfigureServices(IServiceCollection services)
},
Scheme = "oauth2",
Name = "Bearer",
In = ParameterLocation.Header,

In = ParameterLocation.Header
},
new List<string>()
}
Expand All @@ -83,7 +82,7 @@ public void ConfigureServices(IServiceCollection services)
x.UsingRabbitMq((context, cfg) =>
{

cfg.Host(new Uri("rabbitmq://host.docker.internal/"));
cfg.Host(new Uri(Configuration["RabbitMq"]));
cfg.ReceiveEndpoint("purchasesQueue", e =>
{
e.PrefetchCount = 20;
Expand Down
13 changes: 13 additions & 0 deletions src/Services/Purchases/Purchases.API/appsettings.Tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Secret": "7c9e6679-7425-40de-944b-e07fc1f90ae6",
"DefaultConnection": "Server=127.0.0.1;Database=identity;User=sa;Password=YourPassword123;",
"RabbitMq": "rabbitmq://127.0.0.1/"
}
4 changes: 3 additions & 1 deletion src/Services/Purchases/Purchases.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
}
},
"AllowedHosts": "*",
"DefaultConnection": "Server=db;Database=purchases;User=sa;Password=YourPassword123;"
"Secret": "7c9e6679-7425-40de-944b-e07fc1f90ae6",
"DefaultConnection": "Server=db;Database=purchases;User=sa;Password=YourPassword123;",
"RabbitMq": "rabbitmq://host.docker.internal/"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public TestServer CreateServer()
.UseContentRoot(Path.GetDirectoryName(path))
.ConfigureAppConfiguration(cb =>
{
cb.AddJsonFile("appsettings.json", optional: false)
cb.AddJsonFile("appsettings.Tests.json", optional: false)
.AddEnvironmentVariables();
})
.UseUrls("http://*:7002")
Expand Down
7 changes: 4 additions & 3 deletions src/Services/Shops/Shops.API/Consumers/BuyProducts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using MassTransit;
using RtuItLab.Infrastructure.MassTransit.Purchases.Requests;
using RtuItLab.Infrastructure.MassTransit.Shops.Requests;
using RtuItLab.Infrastructure.MassTransit.Shops.Responses;
using Shops.Domain.Services;

namespace Shops.API.Consumers
Expand All @@ -20,11 +21,11 @@ public BuyProducts(IShopsService shopsService,

public async Task Consume(ConsumeContext<BuyProductsRequest> context)
{
var order = await ShopsService.BuyProducts(context.Message.ShopId, context.Message.Products);
await context.RespondAsync(order);
var products = await ShopsService.BuyProducts(context.Message.ShopId, context.Message.Products);
await context.RespondAsync(new GetProductsResponse() { Products = products });

var transaction =
await ShopsService.CreateTransaction(context.Message.ShopId, order);
await ShopsService.CreateTransaction(context.Message.ShopId, products);
await ShopsService.AddReceipt(transaction.Receipt);

var endpoint = await _busControl.GetSendEndpoint(_rabbitMqUrl);
Expand Down
5 changes: 3 additions & 2 deletions src/Services/Shops/Shops.API/Consumers/GetAllShops.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using MassTransit;
using RtuItLab.Infrastructure.MassTransit.Shops.Requests;
using RtuItLab.Infrastructure.MassTransit.Shops.Responses;
using Shops.Domain.Services;

namespace Shops.API.Consumers
Expand All @@ -12,8 +13,8 @@ public GetAllShops(IShopsService shopsService) : base(shopsService)
}
public async Task Consume(ConsumeContext<GetAllShopsRequest> context)
{
var order = ShopsService.GetAllShops();
await context.RespondAsync(order);
var shops = ShopsService.GetAllShops();
await context.RespondAsync(new GetShopsResponse() { Shops = shops });
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using MassTransit;
using RtuItLab.Infrastructure.MassTransit.Shops.Requests;
using RtuItLab.Infrastructure.MassTransit.Shops.Responses;
using Shops.Domain.Services;

namespace Shops.API.Consumers
Expand All @@ -13,8 +14,8 @@ public GetProductsByCategory( IShopsService shopsService) : base(shopsService)

public async Task Consume(ConsumeContext<GetProductsByCategoryRequest> context)
{
var order = await ShopsService.GetProductsByCategory(context.Message.ShopId, context.Message.Category);
await context.RespondAsync(order);
var products = await ShopsService.GetProductsByCategory(context.Message.ShopId, context.Message.Category);
await context.RespondAsync(new GetProductsResponse() { Products = products });
}
}
}
3 changes: 2 additions & 1 deletion src/Services/Shops/Shops.API/Consumers/GetProductsByShop.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using MassTransit;
using RtuItLab.Infrastructure.MassTransit.Shops.Requests;
using RtuItLab.Infrastructure.MassTransit.Shops.Responses;
using Shops.Domain.Services;

namespace Shops.API.Consumers
Expand All @@ -14,7 +15,7 @@ public GetProductsByShop(IShopsService shopsService) : base(shopsService)
public async Task Consume(ConsumeContext<GetProductsRequest> context)
{
var products = await ShopsService.GetProductsByShop(context.Message.ShopId);
await context.RespondAsync(products);
await context.RespondAsync(new GetProductsResponse() { Products = products });
}
}
}
17 changes: 9 additions & 8 deletions src/Services/Shops/Shops.API/Controllers/ShopsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using RtuItLab.Infrastructure.Filters;
using RtuItLab.Infrastructure.MassTransit;
using RtuItLab.Infrastructure.MassTransit.Shops.Requests;
using RtuItLab.Infrastructure.MassTransit.Shops.Responses;
using RtuItLab.Infrastructure.Models;
using RtuItLab.Infrastructure.Models.Identity;
using RtuItLab.Infrastructure.Models.Shops;
Expand All @@ -26,30 +27,30 @@ public ShopsController(IBusControl busControl)
[HttpGet]
public async Task<IActionResult> GetAllShops()
{
var response = await GetResponseRabbitTask<GetAllShopsRequest, ICollection<Shop>>(new GetAllShopsRequest());
return Ok(ApiResult<ICollection<Shop>>.Success200(response));
var response = await GetResponseRabbitTask<GetAllShopsRequest, GetShopsResponse> (new GetAllShopsRequest());
return Ok(ApiResult<GetShopsResponse>.Success200(response));
}

[HttpGet("{shopId}")]
public async Task<IActionResult> GetProducts(int shopId)
{
var response = await GetResponseRabbitTask<GetProductsRequest, ICollection<Product>>(new GetProductsRequest
var response = await GetResponseRabbitTask<GetProductsRequest, GetProductsResponse>(new GetProductsRequest
{
ShopId = shopId,
});
return Ok(ApiResult<ICollection<Product>>.Success200(response));
return Ok(ApiResult<GetProductsResponse>.Success200(response));
}

[HttpPost("{shopId}/find_by_category")]
public async Task<IActionResult> GetProductsByCategory(int shopId, [FromBody] Category category)
{
if (!ModelState.IsValid) return BadRequest();
var response = await GetResponseRabbitTask<GetProductsByCategoryRequest, ICollection<Product>>(new GetProductsByCategoryRequest
var response = await GetResponseRabbitTask<GetProductsByCategoryRequest, GetProductsResponse>(new GetProductsByCategoryRequest
{
ShopId = shopId,
Category = category.CategoryName
});
return Ok(ApiResult<ICollection<Product>>.Success200(response));
return Ok(ApiResult<GetProductsResponse>.Success200(response));
}

[Authorize]
Expand All @@ -58,13 +59,13 @@ public async Task<IActionResult> BuyProducts(int shopId, [FromBody] ICollection<
{
if (!ModelState.IsValid) return BadRequest();
var user = HttpContext.Items["User"] as User;
var productsResponse = await GetResponseRabbitTask<BuyProductsRequest,ICollection<Product>>(new BuyProductsRequest()
var productsResponse = await GetResponseRabbitTask<BuyProductsRequest, GetProductsResponse>(new BuyProductsRequest()
{
User = user,
ShopId = shopId,
Products = products,
});
return Ok(ApiResult<ICollection<Product>>.Success200(productsResponse));
return Ok(ApiResult<GetProductsResponse>.Success200(productsResponse));
}
private async Task<TOut> GetResponseRabbitTask<TIn, TOut>(TIn request)
where TIn : class
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Shops/Shops.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void ConfigureServices(IServiceCollection services)
x.AddConsumer<AddProductsByFactory>();
x.UsingRabbitMq((context, cfg) =>
{
cfg.Host(new Uri("rabbitmq://host.docker.internal/"));
cfg.Host(new Uri(Configuration["RabbitMq"]));
cfg.ReceiveEndpoint("shopsQueue", e =>
{
e.PrefetchCount = 20;
Expand Down
13 changes: 13 additions & 0 deletions src/Services/Shops/Shops.API/appsettings.Tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Secret": "7c9e6679-7425-40de-944b-e07fc1f90ae6",
"DefaultConnection": "Server=127.0.0.1;Database=shops;User=sa;Password=YourPassword123;",
"RabbitMq": "rabbitmq://127.0.0.1/"
}
4 changes: 3 additions & 1 deletion src/Services/Shops/Shops.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
}
},
"AllowedHosts": "*",
"DefaultConnection": "Server=db;Database=shops;User=sa;Password=YourPassword123;"
"Secret": "7c9e6679-7425-40de-944b-e07fc1f90ae6",
"DefaultConnection": "Server=db;Database=shops;User=sa;Password=YourPassword123;",
"RabbitMq": "rabbitmq://host.docker.internal/"
}
1 change: 0 additions & 1 deletion src/Services/Shops/Shops.Domain/Services/IShopsService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using RtuItLab.Infrastructure.MassTransit;
using RtuItLab.Infrastructure.Models.Purchases;
using RtuItLab.Infrastructure.Models.Shops;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public TestServer CreateServer()
.UseContentRoot(Path.GetDirectoryName(path))
.ConfigureAppConfiguration(cb =>
{
cb.AddJsonFile("appsettings.json", optional: false)
cb.AddJsonFile("appsettings.Tests.json", optional: false)
.AddEnvironmentVariables();
})
.UseUrls("http://*:7003")
Expand Down
Loading