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
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SharpIpp.Mapping;
using SharpIpp.Mapping.Extensions;
using SharpIpp.Protocol;
using SharpIpp.Protocol.Models;

namespace SharpIpp.Tests.Unit.Mapping.Profiles;

[TestClass]
[ExcludeFromCodeCoverage]
public class JobTemplateAttributesProfileTests
{
private readonly IMapper _mapper;

public JobTemplateAttributesProfileTests()
{
var mapper = new SimpleMapper();
var assembly = Assembly.GetAssembly(typeof(SimpleMapper));
mapper.FillFromAssembly(assembly!);
_mapper = mapper;
}

[TestMethod]
public void Map_JobTemplateAttributes_WithMediaSource_ShouldMapToIppRequestMessage()
{
var src = new JobTemplateAttributes
{
MediaSource = MediaSource.Main
};

var result = _mapper.Map<IppRequestMessage>(src);
var mediaSourceAttr = result.JobAttributes.Single(a => a.Name == JobAttribute.MediaSource);

mediaSourceAttr.Tag.Should().Be(Tag.Keyword);
mediaSourceAttr.Value.Should().Be("main");
}

[TestMethod]
public void Map_IppRequestMessage_WithMediaSource_ShouldMapToJobTemplateAttributes()
{
var src = new Mock<IIppRequestMessage>();
src.SetupGet(x => x.JobAttributes).Returns(
[
new IppAttribute(Tag.Keyword, JobAttribute.MediaSource, "main")
]);

var result = _mapper.Map<JobTemplateAttributes>(src.Object);

result.MediaSource.Should().Be(MediaSource.Main);
}
}
5 changes: 5 additions & 0 deletions SharpIpp/Mapping/Profiles/JobTemplateAttributesProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public void CreateMaps(IMapperConstructor mapper)
if (src.MediaCol != null)
job.AddRange(map.Map<IEnumerable<IppAttribute>>(src.MediaCol).ToBegCollection(JobAttribute.MediaCol));

if (src.MediaSource != null)
job.Add(new IppAttribute(Tag.Keyword, JobAttribute.MediaSource, map.Map<string>(src.MediaSource.Value)));

return dst;
});

Expand All @@ -125,6 +128,8 @@ public void CreateMaps(IMapperConstructor mapper)
dst.PrintColorMode = map.MapFromDicNullable<PrintColorMode?>(jobDict, JobAttribute.PrintColorMode);
if (jobDict.ContainsKey(JobAttribute.MediaCol))
dst.MediaCol = map.Map<MediaCol>(jobDict[JobAttribute.MediaCol].FromBegCollection().ToIppDictionary());
if (jobDict.ContainsKey(JobAttribute.MediaSource))
dst.MediaSource = map.MapFromDicNullable<MediaSource?>(jobDict, JobAttribute.MediaSource);
return dst;
});
}
Expand Down
1 change: 1 addition & 0 deletions SharpIpp/Protocol/Models/JobAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ public static class JobAttribute
public const string NumberOfDocuments = "number-of-documents";
public const string OutputDeviceAssigned = "output-device-assigned";
public const string MediaCol = "media-col";
public const string MediaSource = "media-source";
}
}
2 changes: 2 additions & 0 deletions SharpIpp/Protocol/Models/JobTemplateAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,7 @@ public class JobTemplateAttributes

public MediaCol? MediaCol { get; set; }

public MediaSource? MediaSource { get; set; }

}
}