Skip to content

Commit

Permalink
#14 Rename DeploymentMetaInfo to DeploymentMetaInfoModel & adjust tes…
Browse files Browse the repository at this point in the history
…t data
  • Loading branch information
tiwalter committed May 10, 2020
1 parent 3d54bc9 commit a985aee
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DeploymentMetaInfoExtensiontest
[Fact]
public void ValidateDeploymentMeta_Valid()
{
var testDeploymentMetaInfo = new DeploymentMetaInfo
var testDeploymentMetaInfo = new DeploymentMetaInfoModel
{
ArtifactFileName = "testArtifact.zip",
ChangelogFileName = "changelog.txt",
Expand All @@ -25,28 +25,28 @@ public void ValidateDeploymentMeta_Invalid()
{

//Without Changelog
var testDeploymentMetaInfo1 = new DeploymentMetaInfo
var testDeploymentMetaInfo1 = new DeploymentMetaInfoModel
{
ArtifactFileName = "testArtifact.zip",
ReleaseDate = new DateTime(2020, 02, 01)
};

//Without ReleaseDate
var testDeploymentMetaInfo2 = new DeploymentMetaInfo
var testDeploymentMetaInfo2 = new DeploymentMetaInfoModel
{
ArtifactFileName = "testArtifact.zip",
ChangelogFileName = "changelog.txt",
};

//Without ArtifactFileName
var testDeploymentMetaInfo3 = new DeploymentMetaInfo
var testDeploymentMetaInfo3 = new DeploymentMetaInfoModel
{
ChangelogFileName = "changelog.txt",
ReleaseDate = new DateTime(2020, 02, 01)
};

//Empty
var testDeploymentMetaInfo4 = new DeploymentMetaInfo();
var testDeploymentMetaInfo4 = new DeploymentMetaInfoModel();

Assert.False(testDeploymentMetaInfo1.IsValid());
Assert.False(testDeploymentMetaInfo2.IsValid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace ReleaseServer.WebApi.Test
public class DeploymentMetaMapperTest
{
private readonly string ProjectDirectory;
private readonly DeploymentMetaInfo ExpectedMeta;
private readonly DeploymentMetaInfoModel ExpectedMeta;

public DeploymentMetaMapperTest()
{
ProjectDirectory = TestUtils.GetProjectDirectory();
ExpectedMeta = new DeploymentMetaInfo
ExpectedMeta = new DeploymentMetaInfoModel
{
ChangelogFileName = "changelog.txt",
ArtifactFileName = "artifact.zip",
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace ReleaseServer.WebApi.Extensions
{
public static class DeploymentMetaInfoExtension
{
public static bool IsValid(this DeploymentMetaInfo deploymentMetaInfo)
public static bool IsValid(this DeploymentMetaInfoModel deploymentMetaInfoModel)
{
if (deploymentMetaInfo.ReleaseDate == new DateTime() || deploymentMetaInfo.ArtifactFileName == null ||
deploymentMetaInfo.ChangelogFileName == null)
if (deploymentMetaInfoModel.ReleaseDate == new DateTime() || deploymentMetaInfoModel.ArtifactFileName == null ||
deploymentMetaInfoModel.ChangelogFileName == null)
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace ReleaseServer.WebApi.Mappers
{
public static class DeploymentMetaInfoMapper
{
public static DeploymentMetaInfo ParseDeploymentMetaInfo(string fileName)
public static DeploymentMetaInfoModel ParseDeploymentMetaInfo(string fileName)
{
return JsonConvert.DeserializeObject<DeploymentMetaInfo>(File.ReadAllText(fileName));
return JsonConvert.DeserializeObject<DeploymentMetaInfoModel>(File.ReadAllText(fileName));
}

public static DeploymentMetaInfo ParseDeploymentMetaInfo(byte[] byteContent)
public static DeploymentMetaInfoModel ParseDeploymentMetaInfo(byte[] byteContent)
{
return JsonConvert.DeserializeObject<DeploymentMetaInfo>(Encoding.UTF8.GetString(byteContent));
return JsonConvert.DeserializeObject<DeploymentMetaInfoModel>(Encoding.UTF8.GetString(byteContent));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ReleaseServer.WebApi.Config
{
public class DeploymentMetaInfo
public class DeploymentMetaInfoModel
{
public string ChangelogFileName { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private string GenerateTemporaryPath()
return Path.Combine(ArtifactRootDir.ToString(), "temp", Guid.NewGuid().ToString());
}

private DeploymentMetaInfo GetDeploymentMetaInfo(IEnumerable<FileInfo> fileInfos)
private DeploymentMetaInfoModel GetDeploymentMetaInfo(IEnumerable<FileInfo> fileInfos)
{
var deploymentMetaName = fileInfos.FirstOrDefault(f => f.Name == "deployment.json");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public async Task<ValidationResultModel> ValidateUploadPayload(IFormFile payload
{
using (var zipMapper = new ZipArchiveMapper())
{
DeploymentMetaInfo deploymentMetaInfo;
DeploymentMetaInfoModel deploymentMetaInfoModel;

Logger.LogDebug("convert the uploaded payload to a ZIP archive");
var payloadZipArchive = zipMapper.FormFileToZipArchive(payload);
Expand All @@ -201,29 +201,29 @@ public async Task<ValidationResultModel> ValidateUploadPayload(IFormFile payload
await deploymentInfoStream.CopyToAsync(memoryStream);
var deploymentInfoByteArray = memoryStream.ToArray();

deploymentMetaInfo = DeploymentMetaInfoMapper.ParseDeploymentMetaInfo(deploymentInfoByteArray);
deploymentMetaInfoModel = DeploymentMetaInfoMapper.ParseDeploymentMetaInfo(deploymentInfoByteArray);
}

//Check if the deployment.json file is valid
if (!deploymentMetaInfo.IsValid())
if (!deploymentMetaInfoModel.IsValid())
{
var validationError = "the deployment meta information (deployment.json) is invalid!";
Logger.LogError(validationError);
return new ValidationResultModel {IsValid = false, ValidationError = validationError};
}

//Check if the uploaded payload contains the rest of the expected parts
if (payloadZipArchive.GetEntry(deploymentMetaInfo.ArtifactFileName) == null)
if (payloadZipArchive.GetEntry(deploymentMetaInfoModel.ArtifactFileName) == null)
{
var validationError = "the expected artifact" + " \"" + deploymentMetaInfo.ArtifactFileName +
var validationError = "the expected artifact" + " \"" + deploymentMetaInfoModel.ArtifactFileName +
"\"" + " does not exist in the uploaded payload!";
Logger.LogError(validationError);
return new ValidationResultModel {IsValid = false, ValidationError = validationError};
}

if (payloadZipArchive.GetEntry(deploymentMetaInfo.ChangelogFileName) == null)
if (payloadZipArchive.GetEntry(deploymentMetaInfoModel.ChangelogFileName) == null)
{
var validationError = "the expected changelog file" + " \"" + deploymentMetaInfo.ChangelogFileName +
var validationError = "the expected changelog file" + " \"" + deploymentMetaInfoModel.ChangelogFileName +
"\"" + " does not exist in the uploaded payload!";
Logger.LogError(validationError);
return new ValidationResultModel {IsValid = false, ValidationError = validationError};
Expand Down

0 comments on commit a985aee

Please sign in to comment.