Skip to content
Merged
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
26 changes: 22 additions & 4 deletions MagikaNet.Tests/MagikaClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void JpegFile_DetectedSuccessfully()
Assert.That(r, Is.Not.Null);
Assert.That(r.Status, Is.EqualTo("ok"));
Assert.That(r.FileType, Is.EqualTo("file"));
Assert.That(r.Value.Output.Label, Is.EqualTo("jpeg"));
Assert.That(r.Value.Output.MimeType, Is.EqualTo("image/jpeg"));
Assert.That(r.Value!.Output.Label, Is.EqualTo("jpeg"));
Assert.That(r.Value!.Output.MimeType, Is.EqualTo("image/jpeg"));
}

[Test]
Expand All @@ -50,7 +50,7 @@ public void ShellBytes_DetectedSuccessfully()
Assert.That(r, Is.Not.Null);
Assert.That(r.Status, Is.EqualTo("ok"));
Assert.That(r.FileType, Is.EqualTo("file"));
Assert.That(r.Value.Output.Label, Is.EqualTo("shell"));
Assert.That(r.Value!.Output.Label, Is.EqualTo("shell"));
}

[Test]
Expand All @@ -62,4 +62,22 @@ public void EmptyBytes_ReturnsEmptyOutput()
var d = m.DetectBytesJson(bytes);
Assert.That(d, Contains.Substring("label\":\"empty"));
}
}

[Test]
public void MissingFile_ReturnsErrorStatus()
{
using var m = new MagikaClient();

var result = m.DetectPath("nonexistent_file.txt");

Assert.That(result, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(result.Status, Is.EqualTo("error"));
Assert.That(result.Message, Is.Not.Null);
Assert.That(result.Message, Is.Not.Empty);
Assert.That(result.FileType, Is.Null);
Assert.That(result.Value, Is.Null);
});
}
}
7 changes: 5 additions & 2 deletions MagikaNet/DetectionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ public class DetectionResult
[JsonPropertyName("status")]
public required string Status { get; set; }

[JsonPropertyName("message")]
public string? Message { get; set; }

[JsonPropertyName("type")]
public required string FileType { get; set; }
public string? FileType { get; set; }

[JsonPropertyName("value")]
public required ValueData Value { get; set; }
public ValueData? Value { get; set; }
}

public class ValueData
Expand Down
Loading