Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrated from templates to documents #8

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-api
WORKDIR /app

EXPOSE 80

COPY DocumentService/*.csproj ./DocumentService/

WORKDIR /app/DocumentService
RUN dotnet restore

WORKDIR /app
COPY DocumentService/ ./DocumentService/

WORKDIR /app/DocumentService
RUN dotnet publish /property:PublishWithAspNetCoreTargetManifest=false -c Release -o out


FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS final
WORKDIR /app

COPY --from=build-api /app/DocumentService/out ./
ENTRYPOINT ["dotnet", "DocumentService.dll"]
7 changes: 7 additions & 0 deletions DocumentService.Tests/DocumentService.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand All @@ -23,4 +24,10 @@
<ProjectReference Include="..\DocumentService\DocumentService.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="TestData\blank-zayavleniya-na-otpusk.doc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
117 changes: 91 additions & 26 deletions DocumentService.Tests/DocumentServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,73 @@
#define HAS_STUPID_REDIS_SERVICE_WITHOUT_DI

using System;
using System.IO;
using System.Linq;
using System.Reflection;
using DocumentService.DTOs;
using DocumentService.Dto;
using DocumentService.Services;
using HarmonyLib;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;

using DocumentServiceClass = DocumentService.Services.DocumentService;

namespace DocumentService.Tests
{
public class DocumentServiceTests
{
private static DocumentServiceClass CreateDocumentService() =>
new(new Logger<DocumentServiceClass>(new LoggerFactory()));
private readonly ITestOutputHelper _testOutputHelper;

[Fact]
public void NotInTypeList_DoesntCauseExceptions()
public DocumentServiceTests(ITestOutputHelper testOutputHelper)
{
var documentService = CreateDocumentService();
_testOutputHelper = testOutputHelper;
}

private static DocumentServiceClass CreateDocumentService()
{
//Данная магия обосновывается тем, что господа не удосужились сделать DI для RedisService в DocumentService,
//как это делают нормальные люди, вместо этого они зашили зависимость в инициализацию поля (!!!)
//private readonly RedisService _redisService = new("https://localhost:5003", 2);

//Ну мы люди не гордые, мы в рантайме заменили конструктор RedisService
//c:

/*
public RedisService(string connectionString, int database)
{
var redisConfig = new RedisConfiguration
{
ConnectionString = connectionString,
Database = database,
AbortOnConnectFail = false
};

var poolManager = new RedisCacheConnectionPoolManager(redisConfig);
var client = new RedisCacheClient(poolManager, new MsgPackObjectSerializer(), redisConfig);
_db = client.GetDbFromConfiguration();
}
*/

//на что-то вроде:
/*
RedisService(string connectionString, int database){
_db = new RedisDatabaseMock();
}
*/
#if HAS_STUPID_REDIS_SERVICE_WITHOUT_DI
var harmony = new Harmony("harmony");
harmony.PatchAll(Assembly.GetExecutingAssembly());

return new DocumentServiceClass(new Logger<DocumentServiceClass>(new LoggerFactory()));
#else
return new DocumentServiceClass(new Logger<DocumentServiceClass>(new LoggerFactory()));
#endif
}

documentService.FillInTemplate("not in type list!!!!", 1, new VacationDTO()
private static VacationDto GetVacationDto()
{
return new VacationDto()
{
Duration = "1",
DateDay = "1",
Expand All @@ -35,36 +82,54 @@ public void NotInTypeList_DoesntCauseExceptions()
StartDateDay = "1",
StartDateMonth = "1",
StartDateYear = "1",
});
};
}

[Fact]
public void NotInTypeList_DoesntCauseExceptions()
{
var documentService = CreateDocumentService();

documentService.FillInTemplate("not in type list!!!!", 1, GetVacationDto());
}

[Fact]
public void FillInVacationTemplate_NewOutputFileCreated()
//что за клоуны...
public void PredefinedTemplateInTheirPath_NewOutputFileCreated()
{
var fileName = "blank-zayavleniya-na-otpusk.doc";

var inputDirectory = @"C:\.NetITIS\Dev\DocumentService\data";
var inputPath = $@"{inputDirectory}\{fileName}";
var outputPath = $@"{inputDirectory}\vacation.doc";

if (!Directory.Exists(inputDirectory))
Directory.CreateDirectory(inputDirectory);
File.Copy($@"./TestData/{fileName}", inputPath);

FillInVacationTemplate_NewOutputFileCreated(inputPath, outputPath);

if (File.Exists(inputPath))
File.Delete(inputPath);
if (Directory.Exists(inputDirectory))
Directory.Delete(inputDirectory);
}

[Theory]
[InlineData(@".\vacation_input.doc", @".\vacation_output.doc")]
public void FillInVacationTemplate_NewOutputFileCreated(string inputPath, string outputPath)
{
var documentService = CreateDocumentService();

const string outputPath = @"C:\.NetITIS\Dev\DocumentService\data\vacation.doc";
if (File.Exists(outputPath))
File.Delete(outputPath);

documentService.FillInTemplate("vacation", 1, new VacationDTO()
{
Duration = "1",
DateDay = "1",
DateMonth = "1",
DateYear = "1",
FromWhom = "1",
FullName = "1",
ToWhom = "1",
EndDateDay = "1",
EndDateMonth = "1",
EndDateYear = "1",
StartDateDay = "1",
StartDateMonth = "1",
StartDateYear = "1",
});
documentService.FillInTemplate("vacation", 1, GetVacationDto());

Assert.True(File.Exists(outputPath));

if (File.Exists(outputPath))
File.Delete(outputPath);
}

[Fact]
Expand Down
Loading