diff --git a/Documents/Black Pearl PFR - Installation and Configuration.pdf b/Documents/Black Pearl PFR - Installation and Configuration.pdf new file mode 100644 index 0000000..c2c6ffb Binary files /dev/null and b/Documents/Black Pearl PFR - Installation and Configuration.pdf differ diff --git a/Documents/Extended PFR Indexer Web Service API_15Dec2016.pdf b/Documents/Extended PFR Indexer Web Service API_15Dec2016.pdf new file mode 100644 index 0000000..461ebe7 Binary files /dev/null and b/Documents/Extended PFR Indexer Web Service API_15Dec2016.pdf differ diff --git a/Documents/Extended PFR Indexer Web Service API_16Dec2016.pdf b/Documents/Extended PFR Indexer Web Service API_16Dec2016.pdf new file mode 100644 index 0000000..6592ab4 Binary files /dev/null and b/Documents/Extended PFR Indexer Web Service API_16Dec2016.pdf differ diff --git a/Documents/PFRRelease v3.1.0.370.zip b/Documents/PFRRelease v3.1.0.370.zip new file mode 100644 index 0000000..c6336a9 Binary files /dev/null and b/Documents/PFRRelease v3.1.0.370.zip differ diff --git a/TpfrClient/Calls/ReWrapRequest.cs b/TpfrClient/Calls/ReWrapRequest.cs index 3373067..6846274 100644 --- a/TpfrClient/Calls/ReWrapRequest.cs +++ b/TpfrClient/Calls/ReWrapRequest.cs @@ -26,21 +26,17 @@ public class ReWrapRequest : RestRequest /// Timecode of the first frame requested /// Timecode of the last frame requested /// Frame rate, as returned in the file status report - /// Byte offset of start of partial file relative to original file - /// Byte offset of end of partial file relative to original file /// Full UNC path to partial restored file fragment - /// output file name for partial media file (care should be taken that this does not clash with other part restores, e.g. from other sections of the same source file) - public ReWrapRequest(string filePath, TimeCode firstFrame, TimeCode lastFrame, string frameRate, string inByte, - string outByte, string partialRestoreFilePath, string outputFileName) + /// output file name for partial media file (care should be taken that this does not clash with other part restores, e.g. from other sections of the same source file). This should not have an extension, as this will added automatically. + public ReWrapRequest(string filePath, TimeCode firstFrame, TimeCode lastFrame, string frameRate, + string partialRestoreFilePath, string outputFileName) { AddQueryParam("filepath", filePath); AddQueryParam("tcin", firstFrame.Time); AddQueryParam("tcout", lastFrame.Time); AddQueryParam("fileframerate", frameRate); - AddQueryParam("in_byte", inByte); - AddQueryParam("out_byte", outByte); AddQueryParam("part_file", partialRestoreFilePath); - AddQueryParam("out_fileName", outputFileName); + AddQueryParam("out_filename", outputFileName); } internal override HttpVerb Verb => HttpVerb.PUT; diff --git a/TpfrClient/Calls/ReWrapStatusRequest.cs b/TpfrClient/Calls/ReWrapStatusRequest.cs index fd0de82..ee190b9 100644 --- a/TpfrClient/Calls/ReWrapStatusRequest.cs +++ b/TpfrClient/Calls/ReWrapStatusRequest.cs @@ -20,7 +20,7 @@ public class ReWrapStatusRequest : RestRequest /// /// /// - /// The out_filename value passed in the Partial File Request + /// The out_filename value passed in the Partial File Request. This is Case Sensitive public ReWrapStatusRequest(string outputFileName) { AddQueryParam("targetpartialname", outputFileName); diff --git a/TpfrClient/ITpfrClient.cs b/TpfrClient/ITpfrClient.cs index 4b16acf..7409efd 100644 --- a/TpfrClient/ITpfrClient.cs +++ b/TpfrClient/ITpfrClient.cs @@ -55,10 +55,9 @@ public interface ITpfrClient /// /// This method will use the parameters supplied to generate a Marquis XML file that will be used to create the partial output file. /// - /// - /// - /// - void ReWrap(ReWrapRequest request); + /// + /// + ReWrapResponse ReWrap(ReWrapRequest request); /// /// This method will return status (% complete) for the creation of a partial media file initiated using the Partial File Request API call. diff --git a/TpfrClient/Model/ReWrapResponse.cs b/TpfrClient/Model/ReWrapResponse.cs new file mode 100644 index 0000000..46cf1a6 --- /dev/null +++ b/TpfrClient/Model/ReWrapResponse.cs @@ -0,0 +1,31 @@ +/* + * ****************************************************************************** + * Copyright 2014 - 2016 Spectra Logic Corporation. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use + * this file except in compliance with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * **************************************************************************** + */ + +namespace TpfrClient.Model +{ + public class ReWrapResponse + { + public ReWrapResult Result { get; set; } + } + + public enum ReWrapResult + { + Succeeded, + ErrorDuplicateParameter, + ErrorMissingParameter, + ErrorBadFramerate, + Unknown + } +} \ No newline at end of file diff --git a/TpfrClient/ResponseParsers/ReWrapResponseParser.cs b/TpfrClient/ResponseParsers/ReWrapResponseParser.cs index 6eabb71..a2a79f9 100644 --- a/TpfrClient/ResponseParsers/ReWrapResponseParser.cs +++ b/TpfrClient/ResponseParsers/ReWrapResponseParser.cs @@ -14,19 +14,28 @@ */ using System.Net; +using TpfrClient.Model; using TpfrClient.Runtime; namespace TpfrClient.ResponseParsers { - internal class ReWrapResponseParser : IResponseParser + internal class ReWrapResponseParser : IResponseParser { - public object Parse(IHttpWebResponse response) + public ReWrapResponse Parse(IHttpWebResponse response) { using (response) { - ResponseParseUtils.HandleStatusCode(response, (HttpStatusCode)200); - return null; + ResponseParseUtils.HandleStatusCode(response, (HttpStatusCode) 200, (HttpStatusCode) 400); + using (var stream = response.GetResponseStream()) + { + var element = XmlExtensions.ReadDocument(stream).ElementOrThrow("partialfile"); + + return new ReWrapResponse + { + Result = ResponseParseUtils.GetReWrapResult(element.AttributeTextOrNull("partialfileResult")), + }; + } } } } -} +} \ No newline at end of file diff --git a/TpfrClient/ResponseParsers/ResponseParseUtils.cs b/TpfrClient/ResponseParsers/ResponseParseUtils.cs index 08ef70c..55cdd42 100644 --- a/TpfrClient/ResponseParsers/ResponseParseUtils.cs +++ b/TpfrClient/ResponseParsers/ResponseParseUtils.cs @@ -90,5 +90,22 @@ public static OffsetsResult GetOffsetsResult(string result) return Phase.Unknown; } } + + public static ReWrapResult GetReWrapResult(string result) + { + switch (result) + { + case "Succeeded": + return ReWrapResult.Succeeded; + case "Error Duplicate parameter": + return ReWrapResult.ErrorDuplicateParameter; + case "Error Missing parameter": + return ReWrapResult.ErrorMissingParameter; + case "Error Bad framerate": + return ReWrapResult.ErrorBadFramerate; + default: + return ReWrapResult.Unknown; + } + } } -} +} \ No newline at end of file diff --git a/TpfrClient/Runtime/Network.cs b/TpfrClient/Runtime/Network.cs index f16ed6c..42bbd30 100644 --- a/TpfrClient/Runtime/Network.cs +++ b/TpfrClient/Runtime/Network.cs @@ -42,7 +42,19 @@ public INetwork WithProxy(Uri proxy) public IHttpWebResponse Invoke(RestRequest request) { var httpWebRequest = CreateHttpWebRequest(request); - return httpWebRequest.GetResponse(); + + try + { + return httpWebRequest.GetResponse(); + } + catch (WebException e) + { + if (e.Response == null) + { + throw; + } + return new TpfrHttpWebResponse((HttpWebResponse) e.Response); + } } private IHttpWebRequest CreateHttpWebRequest(RestRequest request) @@ -57,7 +69,7 @@ private IHttpWebRequest CreateHttpWebRequest(RestRequest request) var httpRequest = (HttpWebRequest) WebRequest.Create(uriBuilder.Uri); httpRequest.Method = request.Verb.ToString(); - + if (Proxy != null) { var webProxy = new WebProxy diff --git a/TpfrClient/TpfrClient.cs b/TpfrClient/TpfrClient.cs index 2fed2a2..b852662 100644 --- a/TpfrClient/TpfrClient.cs +++ b/TpfrClient/TpfrClient.cs @@ -35,45 +35,70 @@ public TpfrClient(INetwork network) _network = network; } - public TpfrClient WithProxy(string proxy) - { - return !string.IsNullOrEmpty(proxy) ? WithProxy(new Uri(proxy)) : this; - } - private TpfrClient WithProxy(Uri proxy) - { - _network.WithProxy(proxy); - return this; - } - + /// + /// This method will block while the index is created and will only return when either the index file has been created or for some reason it has not been possible to create the index file. + /// On HFS systems that leave stub files on disk, such as StorNext, if a request is made to create an index for a media file which has been truncated by StorNext, this call will cause the entire media file to be restored by StorNext. + /// The Web Service will support multiple concurrent calls to this command. + /// + /// + /// public IndexStatus IndexFile(IndexFileRequest request) { return new IndexFileResponseParser().Parse(_network.Invoke(request)); } + /// + /// This method will block while retrieving the index status for a previously indexed file. + /// This method internally uses an XML file, generated by the indexer to retrieve the detailed status.This XML file is only generated by Quantum PFR version 1.1 and later.For files that were indexed in an earlier version of Quantum PFR, minimal information will be retrieved (just whether the file had been indexed or not). + /// The Web Service will support multiple concurrent calls to this API call. + /// + /// + /// public IndexStatus FileStatus(FileStatusRequest request) { return new FileStatusResponseParser().Parse(_network.Invoke(request)); } - [Obsolete("Not Implemented")] + /// + /// This method will block whilst retrieving the start and end byte offsets for the requested timecodes. The offsets are extended in order to handle GOP and interleave ordering. + /// Timecode format should be in form hh:mm:ss:ff for non-drop framerates and hh:mm:ss;ff for drop framerates + /// + /// + /// public OffsetsStatus QuestionTimecode(QuestionTimecodeRequest request) { - throw new NotImplementedException(); return new QuestionTimecodeResponseParser().Parse(_network.Invoke(request)); } - [Obsolete("Not Implemented")] - public void ReWrap(ReWrapRequest request) + /// + /// This method will use the parameters supplied to generate a Marquis XML file that will be used to create the partial output file. + /// + /// + /// + public ReWrapResponse ReWrap(ReWrapRequest request) { - throw new NotImplementedException(); - new ReWrapResponseParser().Parse(_network.Invoke(request)); + return new ReWrapResponseParser().Parse(_network.Invoke(request)); } - [Obsolete("Not Implemented")] + /// + /// This method will return status (% complete) for the creation of a partial media file initiated using the Partial File Request API call. + /// + /// + /// public ReWrapStatus ReWrapStatus(ReWrapStatusRequest request) { - throw new NotImplementedException(); return new ReWrapStatusResponseParser().Parse(_network.Invoke(request)); } + + public TpfrClient WithProxy(string proxy) + { + return !string.IsNullOrEmpty(proxy) ? WithProxy(new Uri(proxy)) : this; + } + + private TpfrClient WithProxy(Uri proxy) + { + _network.WithProxy(proxy); + return this; + } } } \ No newline at end of file diff --git a/TpfrClient/TpfrClient.csproj b/TpfrClient/TpfrClient.csproj index 9eca311..dae0644 100644 --- a/TpfrClient/TpfrClient.csproj +++ b/TpfrClient/TpfrClient.csproj @@ -22,6 +22,7 @@ 4 bin\Debug\TpfrClient.XML false + 1591 pdbonly @@ -31,6 +32,7 @@ prompt 4 bin\Release\TpfrClient.XML + 1591 @@ -49,6 +51,7 @@ + diff --git a/TpfrClientIntegrationTest/TpfrClientIntegrationTest.cs b/TpfrClientIntegrationTest/TpfrClientIntegrationTest.cs index bc3e12d..ee3403a 100644 --- a/TpfrClientIntegrationTest/TpfrClientIntegrationTest.cs +++ b/TpfrClientIntegrationTest/TpfrClientIntegrationTest.cs @@ -13,10 +13,7 @@ * **************************************************************************** */ -using System; -using System.Collections.Generic; using System.Configuration; -using System.Net; using NUnit.Framework; using TpfrClient; using TpfrClient.Calls; @@ -27,39 +24,40 @@ namespace TpfrClientIntegrationTest [TestFixture] public class TpfrClientIntegrationTest { - private ITpfrClient _client; - private string _path; - [SetUp] public void Setup() { _client = new TpfrClient.TpfrClient( - ConfigurationManager.AppSettings["HostName"], - int.Parse(ConfigurationManager.AppSettings["Port"])) + ConfigurationManager.AppSettings["HostName"], + int.Parse(ConfigurationManager.AppSettings["Port"])) .WithProxy(ConfigurationManager.AppSettings["Proxy"]); _path = ConfigurationManager.AppSettings["Path"]; } + private ITpfrClient _client; + private string _path; + [Test] - public void TestOkFileIndex() + public void TestErrorFileNotFoundFileStatus() { - var status = _client.IndexFile(new IndexFileRequest($"{_path}ok.mov")); - Assert.AreEqual(IndexResult.Succeeded, status.IndexResult); + var status = _client.FileStatus(new FileStatusRequest($"{_path}not_found.mov")); + Assert.AreEqual(IndexResult.ErrorFileNotFound, status.IndexResult); } [Test] - public void TestFailedFileIndex() + public void TestErrorReWrapStatus() { - var status = _client.IndexFile(new IndexFileRequest($"{_path}error_file.xmf")); - Assert.AreEqual(IndexResult.Failed, status.IndexResult); + var reWrapStatus = _client.ReWrapStatus(new ReWrapStatusRequest("JobNotFound")); + Assert.AreEqual(null, reWrapStatus.Phase); + Assert.AreEqual("Job not found", reWrapStatus.Error); } [Test] - public void TestOkFileStatus() + public void TestFailedFileIndex() { - var status = _client.FileStatus(new FileStatusRequest($"{_path}ok.mov")); - Assert.AreEqual(IndexResult.Succeeded, status.IndexResult); + var status = _client.IndexFile(new IndexFileRequest($"{_path}error.mov")); + Assert.AreEqual(IndexResult.Failed, status.IndexResult); } [Test] @@ -70,38 +68,70 @@ public void TestNotIndexedFileStatus() } [Test] - public void TestErrorFileNotFoundFileStatus() + public void TestOkFileIndex() { - var status = _client.FileStatus(new FileStatusRequest($"{_path}not_found.mov")); - Assert.AreEqual(IndexResult.ErrorFileNotFound, status.IndexResult); + var status = _client.IndexFile(new IndexFileRequest($"{_path}sample.mov")); + Assert.AreEqual(IndexResult.Succeeded, status.IndexResult); + } + + [Test] + public void TestOkFileStatus() + { + var status = _client.FileStatus(new FileStatusRequest($"{_path}sample.mov")); + Assert.AreEqual(IndexResult.Succeeded, status.IndexResult); } [Test] public void TestQuestionTimecode() { - Assert.Ignore(); + var firstFrame = new TimeCode("00:00:00:00"); + var lastFrame = new TimeCode("00:00:10:00"); + var response = + _client.QuestionTimecode(new QuestionTimecodeRequest($"{_path}sample.mov", firstFrame, lastFrame, + "29.97")); + Assert.AreEqual(OffsetsResult.Succeeded, response.OffsetsResult); + Assert.AreEqual("0x0", response.InBytes); + Assert.AreEqual("0x3647974", response.OutBytes); + } + [Test] + public void TestQuestionTimecodeFileNotFound() + { var firstFrame = new TimeCode("00:00:00:00"); var lastFrame = new TimeCode("00:00:10:00"); - _client.QuestionTimecode(new QuestionTimecodeRequest(@"C:\Users\sharons\Videos\tpft\SampleFile.mov", firstFrame, lastFrame, "30")); + var response = + _client.QuestionTimecode(new QuestionTimecodeRequest($"{_path}not_found.mov", firstFrame, lastFrame, + "29.97")); + Assert.AreEqual(OffsetsResult.ErrorFileNotFound, response.OffsetsResult); } [Test] public void TestReWrap() { - Assert.Ignore(); + var firstFrame = new TimeCode("00:00:00:00"); + var lastFrame = new TimeCode("00:00:10:00"); + var response = + _client.ReWrap(new ReWrapRequest($"{_path}sample.mov", firstFrame, lastFrame, "29.97", + @"C:\Users\Administrator\Desktop\sample_10sec.mov", "PartSampleFile")); + Assert.AreEqual(ReWrapResult.Succeeded, response.Result); + } - var firstFrame = new TimeCode("00:00:10:00"); - var lastFrame = new TimeCode("00:05:00:00"); - _client.ReWrap(new ReWrapRequest(@"C:\Media\SampleFile.mxf", firstFrame, lastFrame, "25", "0x0060000", "0x0080000", @"C:\Media\PartialSampleFile.mfx", "PartSampleFile")); + [Test] + public void TestReWrapErrorBadFramerate() + { + var firstFrame = new TimeCode("00:00:00:00"); + var lastFrame = new TimeCode("00:00:10:00"); + var response = + _client.ReWrap(new ReWrapRequest($"{_path}sample.mov", firstFrame, lastFrame, "0", + @"C:\Users\Administrator\Desktop\sample_10sec.mov", "PartSampleFile")); + Assert.AreEqual(ReWrapResult.ErrorBadFramerate, response.Result); } [Test] public void TestReWrapStatus() { - Assert.Ignore(); - - _client.ReWrapStatus(new ReWrapStatusRequest("PartSampleFile")); + var reWrapStatus = _client.ReWrapStatus(new ReWrapStatusRequest("PartSampleFile")); + Assert.AreEqual(Phase.Complete, reWrapStatus.Phase); } } -} +} \ No newline at end of file diff --git a/TpfrClientTest/TestFiles/DuplicateParameter.xml b/TpfrClientTest/TestFiles/DuplicateParameter.xml new file mode 100644 index 0000000..e8d26a8 --- /dev/null +++ b/TpfrClientTest/TestFiles/DuplicateParameter.xml @@ -0,0 +1,2 @@ + + diff --git a/TpfrClientTest/TestFiles/IncorrectFramerate.xml b/TpfrClientTest/TestFiles/IncorrectFramerate.xml new file mode 100644 index 0000000..5204d3c --- /dev/null +++ b/TpfrClientTest/TestFiles/IncorrectFramerate.xml @@ -0,0 +1,2 @@ + + diff --git a/TpfrClientTest/TestFiles/MissingParameter.xml b/TpfrClientTest/TestFiles/MissingParameter.xml new file mode 100644 index 0000000..e56fb53 --- /dev/null +++ b/TpfrClientTest/TestFiles/MissingParameter.xml @@ -0,0 +1,2 @@ + + diff --git a/TpfrClientTest/TestFiles/SuccessfulReWrap.xml b/TpfrClientTest/TestFiles/SuccessfulReWrap.xml new file mode 100644 index 0000000..bd232c2 --- /dev/null +++ b/TpfrClientTest/TestFiles/SuccessfulReWrap.xml @@ -0,0 +1,2 @@ + + diff --git a/TpfrClientTest/TpfrClientTest.cs b/TpfrClientTest/TpfrClientTest.cs index d43e0a3..599c852 100644 --- a/TpfrClientTest/TpfrClientTest.cs +++ b/TpfrClientTest/TpfrClientTest.cs @@ -27,45 +27,89 @@ namespace TpfrClientTest [TestFixture] public class TpfrClientTest { + private static readonly object[] GoodTimeCodes = + { + new object[] {"00:00:00:00"}, + new object[] {"00:00:00;00"}, + new object[] {"12:34:56:78"}, + new object[] {"12:34:56;78"} + }; + + private static readonly object[] BadTimeCodes = + { + new object[] {"00:00:00.00"}, + new object[] {"00.00.00.00"}, + new object[] {"00"}, + new object[] {"00:00"}, + new object[] {"00:00:00"}, + new object[] {"x0:00:00:00"}, + new object[] {"00:x0:00:00"}, + new object[] {"00:00:x0:00"}, + new object[] {"00:00:00:x0"} + }; + + private static readonly object[] ReWrapObjects = + { + new object[] {"SuccessfulReWrap.xml", ReWrapResult.Succeeded}, + new object[] {"DuplicateParameter.xml", ReWrapResult.ErrorDuplicateParameter}, + new object[] {"MissingParameter.xml", ReWrapResult.ErrorMissingParameter}, + new object[] {"IncorrectFramerate.xml", ReWrapResult.ErrorBadFramerate} + }; + + + private static readonly object[] ReWrapStatusObjects = + { + new object[] {"JobPending.xml", Phase.Pending, "0"}, + new object[] {"JobParsing.xml", Phase.Parsing, "25"}, + new object[] {"JobTransferring.xml", Phase.Transferring, "50"}, + new object[] {"JobComplete.xml", Phase.Complete, "100"}, + new object[] {"JobFailed.xml", Phase.Failed, "0"} + }; + [Test] - public void TestFailedIndexFile() + public void TesReWrapError() { var mockNetwork = new Mock(MockBehavior.Strict); mockNetwork .Setup(n => n.Invoke(It.IsAny())) - .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.FailedToIndex.xml", HttpStatusCode.OK)); + .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.PartialFileStatusError.xml", + HttpStatusCode.OK)); var client = new TpfrClient.TpfrClient(mockNetwork.Object); - var status = client.IndexFile(new IndexFileRequest("filePath")); + var status = client.ReWrapStatus(new ReWrapStatusRequest("outputFileName")); - Assert.AreEqual(IndexResult.Failed, status.IndexResult); - Assert.AreEqual("2011/10/21 15:30:15", status.IndexTime); + Assert.AreEqual("Job not found", status.Error); mockNetwork.VerifyAll(); } [Test] - public void TestSuccessfulIndexFile() + [TestCaseSource(nameof(ReWrapStatusObjects))] + public void TesReWrapStatus(string xmlFile, Phase phase, string percentComplete) { var mockNetwork = new Mock(MockBehavior.Strict); mockNetwork .Setup(n => n.Invoke(It.IsAny())) - .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.SuccessfulIndexFileOrFileStatusCall.xml", HttpStatusCode.OK)); + .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles." + xmlFile, HttpStatusCode.OK)); var client = new TpfrClient.TpfrClient(mockNetwork.Object); - var status = client.IndexFile(new IndexFileRequest("filePath")); + var status = client.ReWrapStatus(new ReWrapStatusRequest("outputFileName")); - Assert.AreEqual(IndexResult.Succeeded, status.IndexResult); - Assert.AreEqual("2011/10/21 11:40:53", status.IndexTime); - Assert.AreEqual("01:00:00;00", status.FileStartTc); - Assert.AreEqual("1800", status.FileDuration); - Assert.AreEqual("29.97", status.FileFrameRate); + Assert.AreEqual(phase, status.Phase); + Assert.AreEqual(percentComplete, status.Percentcomplete); mockNetwork.VerifyAll(); } [Test] - public void TestFailedIndexStatus() + [TestCaseSource(nameof(BadTimeCodes))] + public void TestBadTimeCodeFormat(string timeCode) + { + Assert.Throws(() => new TimeCode(timeCode)); + } + + [Test] + public void TestFailedIndexFile() { var mockNetwork = new Mock(MockBehavior.Strict); mockNetwork @@ -73,7 +117,7 @@ public void TestFailedIndexStatus() .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.FailedToIndex.xml", HttpStatusCode.OK)); var client = new TpfrClient.TpfrClient(mockNetwork.Object); - var status = client.FileStatus(new FileStatusRequest("filePath")); + var status = client.IndexFile(new IndexFileRequest("filePath")); Assert.AreEqual(IndexResult.Failed, status.IndexResult); Assert.AreEqual("2011/10/21 15:30:15", status.IndexTime); @@ -82,21 +126,18 @@ public void TestFailedIndexStatus() } [Test] - public void TestSuccessfulFileStatus() + public void TestFailedIndexStatus() { var mockNetwork = new Mock(MockBehavior.Strict); mockNetwork .Setup(n => n.Invoke(It.IsAny())) - .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.SuccessfulIndexFileOrFileStatusCall.xml", HttpStatusCode.OK)); + .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.FailedToIndex.xml", HttpStatusCode.OK)); var client = new TpfrClient.TpfrClient(mockNetwork.Object); var status = client.FileStatus(new FileStatusRequest("filePath")); - Assert.AreEqual(IndexResult.Succeeded, status.IndexResult); - Assert.AreEqual("2011/10/21 11:40:53", status.IndexTime); - Assert.AreEqual("01:00:00;00", status.FileStartTc); - Assert.AreEqual("1800", status.FileDuration); - Assert.AreEqual("29.97", status.FileFrameRate); + Assert.AreEqual(IndexResult.Failed, status.IndexResult); + Assert.AreEqual("2011/10/21 15:30:15", status.IndexTime); mockNetwork.VerifyAll(); } @@ -107,7 +148,8 @@ public void TestFileNotFoundFileStatus() var mockNetwork = new Mock(MockBehavior.Strict); mockNetwork .Setup(n => n.Invoke(It.IsAny())) - .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.FileStatusWhenFileNotPresent.xml", HttpStatusCode.OK)); + .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.FileStatusWhenFileNotPresent.xml", + HttpStatusCode.OK)); var client = new TpfrClient.TpfrClient(mockNetwork.Object); var status = client.FileStatus(new FileStatusRequest("filePath")); @@ -118,176 +160,126 @@ public void TestFileNotFoundFileStatus() } [Test] - public void TestFileNotIndexedFileStatus() + public void TestFileNotFoundQuestionTimecode() { var mockNetwork = new Mock(MockBehavior.Strict); mockNetwork .Setup(n => n.Invoke(It.IsAny())) - .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.FileStatusWhenFileNotIndexed.xml", HttpStatusCode.OK)); - - var client = new TpfrClient.TpfrClient(mockNetwork.Object); - var status = client.FileStatus(new FileStatusRequest("filePath")); - - Assert.AreEqual(IndexResult.NotIndexed, status.IndexResult); - - mockNetwork.VerifyAll(); - } - - [Test] - public void TestSucceededQuestionTimecode() - { - Assert.Ignore("Not Implemented"); - - var mockNetwork = new Mock(MockBehavior.Strict); - mockNetwork - .Setup(n => n.Invoke(It.IsAny())) - .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.GoodFileOffsetsCall.xml", HttpStatusCode.OK)); + .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.FileNotFoundOffsetsCall.xml", + HttpStatusCode.OK)); var client = new TpfrClient.TpfrClient(mockNetwork.Object); var status = client.QuestionTimecode( new QuestionTimecodeRequest( "filePath", new TimeCode("00:00:00:00"), new TimeCode("00:00:00:00"), "00")); - Assert.AreEqual(OffsetsResult.Succeeded, status.OffsetsResult); - Assert.AreEqual("0x0060000", status.InBytes); - Assert.AreEqual("0x0080000", status.OutBytes); + Assert.AreEqual(OffsetsResult.ErrorFileNotFound, status.OffsetsResult); mockNetwork.VerifyAll(); } [Test] - public void TestFileNotFoundQuestionTimecode() + public void TestFileNotIndexedFileStatus() { - Assert.Ignore("Not Implemented"); - var mockNetwork = new Mock(MockBehavior.Strict); mockNetwork .Setup(n => n.Invoke(It.IsAny())) - .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.FileNotFoundOffsetsCall.xml", HttpStatusCode.OK)); + .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.FileStatusWhenFileNotIndexed.xml", + HttpStatusCode.OK)); var client = new TpfrClient.TpfrClient(mockNetwork.Object); - var status = client.QuestionTimecode( - new QuestionTimecodeRequest( - "filePath", new TimeCode("00:00:00:00"), new TimeCode("00:00:00:00"), "00")); + var status = client.FileStatus(new FileStatusRequest("filePath")); - Assert.AreEqual(OffsetsResult.ErrorFileNotFound, status.OffsetsResult); + Assert.AreEqual(IndexResult.NotIndexed, status.IndexResult); mockNetwork.VerifyAll(); } - private static readonly object[] GoodTimeCodes = - { - new object[] {"00:00:00:00"}, - new object[] {"00:00:00;00"}, - new object[] {"12:34:56:78"}, - new object[] {"12:34:56;78"} - }; - - [Test, TestCaseSource(nameof(GoodTimeCodes))] + [Test] + [TestCaseSource(nameof(GoodTimeCodes))] public void TestGoodTimeCodeFormat(string timeCode) { Assert.AreEqual(timeCode, new TimeCode(timeCode).Time); } - private static readonly object[] BadTimeCodes = - { - new object[] {"00:00:00.00"}, - new object[] {"00.00.00.00"}, - new object[] {"00"}, - new object[] {"00:00"}, - new object[] {"00:00:00"}, - new object[] {"x0:00:00:00"}, - new object[] {"00:x0:00:00"}, - new object[] {"00:00:x0:00"}, - new object[] {"00:00:00:x0"} - }; - - [Test, TestCaseSource(nameof(BadTimeCodes))] - public void TestBadTimeCodeFormat(string timeCode) - { - Assert.Throws(() => new TimeCode(timeCode)); - } - [Test] - public void TestReWrap() + [TestCaseSource(nameof(ReWrapObjects))] + public void TestReWrap(string xmlFile, ReWrapResult expected) { - Assert.Ignore("Not Implemented"); - var mockNetwork = new Mock(MockBehavior.Strict); mockNetwork .Setup(n => n.Invoke(It.IsAny())) - .Returns(new MockHttpWebResponse("", HttpStatusCode.OK)); + .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles." + xmlFile, HttpStatusCode.OK)); var client = new TpfrClient.TpfrClient(mockNetwork.Object); - client.ReWrap( + var response = client.ReWrap( new ReWrapRequest( "filePath", new TimeCode("00:00:00:00"), new TimeCode("00:00:00:00"), "00", - "0x0060000", "0x0080000", "partialFilePath", "outputFileName")); + "partialFilePath", "outputFileName")); + + Assert.AreEqual(expected, response.Result); mockNetwork.VerifyAll(); } [Test] - public void TestFailedReWrap() + public void TestSucceededQuestionTimecode() { - Assert.Ignore("Not Implemented"); - var mockNetwork = new Mock(MockBehavior.Strict); mockNetwork .Setup(n => n.Invoke(It.IsAny())) - .Returns(new MockHttpWebResponse("", HttpStatusCode.BadRequest)); + .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.GoodFileOffsetsCall.xml", HttpStatusCode.OK)); var client = new TpfrClient.TpfrClient(mockNetwork.Object); - Assert.Throws(() => client.ReWrap( - new ReWrapRequest( - "filePath", new TimeCode("00:00:00:00"), new TimeCode("00:00:00:00"), "00", - "0x0060000", "0x0080000", "partialFilePath", "outputFileName"))); + var status = client.QuestionTimecode( + new QuestionTimecodeRequest( + "filePath", new TimeCode("00:00:00:00"), new TimeCode("00:00:00:00"), "00")); + + Assert.AreEqual(OffsetsResult.Succeeded, status.OffsetsResult); + Assert.AreEqual("0x0060000", status.InBytes); + Assert.AreEqual("0x0080000", status.OutBytes); mockNetwork.VerifyAll(); } - private static readonly object[] ReWrapStatusObjects = - { - new object[] {"JobPending.xml", Phase.Pending, "0"}, - new object[] {"JobParsing.xml", Phase.Parsing, "25"}, - new object[] {"JobTransferring.xml", Phase.Transferring, "50"}, - new object[] {"JobComplete.xml", Phase.Complete, "100"}, - new object[] { "JobFailed.xml", Phase.Failed, "0"} - }; - - [Test, TestCaseSource(nameof(ReWrapStatusObjects))] - public void TesReWrapStatus(string xmlFile, Phase phase, string percentComplete) + [Test] + public void TestSuccessfulFileStatus() { - Assert.Ignore("Not Implemented"); - var mockNetwork = new Mock(MockBehavior.Strict); mockNetwork .Setup(n => n.Invoke(It.IsAny())) - .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles."+xmlFile, HttpStatusCode.OK)); + .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.SuccessfulIndexFileOrFileStatusCall.xml", + HttpStatusCode.OK)); var client = new TpfrClient.TpfrClient(mockNetwork.Object); - var status = client.ReWrapStatus(new ReWrapStatusRequest("outputFileName")); + var status = client.FileStatus(new FileStatusRequest("filePath")); - Assert.AreEqual(phase, status.Phase); - Assert.AreEqual(percentComplete, status.Percentcomplete); + Assert.AreEqual(IndexResult.Succeeded, status.IndexResult); + Assert.AreEqual("2011/10/21 11:40:53", status.IndexTime); + Assert.AreEqual("01:00:00;00", status.FileStartTc); + Assert.AreEqual("1800", status.FileDuration); + Assert.AreEqual("29.97", status.FileFrameRate); mockNetwork.VerifyAll(); } [Test] - public void TesReWrapError() + public void TestSuccessfulIndexFile() { - Assert.Ignore("Not Implemented"); - var mockNetwork = new Mock(MockBehavior.Strict); mockNetwork .Setup(n => n.Invoke(It.IsAny())) - .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.PartialFileStatusError.xml", HttpStatusCode.OK)); + .Returns(new MockHttpWebResponse("TpfrClientTest.TestFiles.SuccessfulIndexFileOrFileStatusCall.xml", + HttpStatusCode.OK)); var client = new TpfrClient.TpfrClient(mockNetwork.Object); - var status = client.ReWrapStatus(new ReWrapStatusRequest("outputFileName")); + var status = client.IndexFile(new IndexFileRequest("filePath")); - Assert.AreEqual("Job not found", status.Error); + Assert.AreEqual(IndexResult.Succeeded, status.IndexResult); + Assert.AreEqual("2011/10/21 11:40:53", status.IndexTime); + Assert.AreEqual("01:00:00;00", status.FileStartTc); + Assert.AreEqual("1800", status.FileDuration); + Assert.AreEqual("29.97", status.FileFrameRate); mockNetwork.VerifyAll(); } diff --git a/TpfrClientTest/TpfrClientTest.csproj b/TpfrClientTest/TpfrClientTest.csproj index 1307681..364bd03 100644 --- a/TpfrClientTest/TpfrClientTest.csproj +++ b/TpfrClientTest/TpfrClientTest.csproj @@ -104,6 +104,18 @@ + + + + + + + + + + + +