public void ShouldReplaceInstanceSubResourceForHasOnePlaceholder() { var getRobotExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Get, JsonFormatExpectation(), "/admin/robots/420", EmptyQueryParametersExpectation(), null)); getRobotExpectation.Returns(TaskForResult <string>("Robot #420's json")); // Robot #42 has Brain #56 var translationExpectation = A.CallTo(() => Shopify.TranslateObject <Robot>("robot", "Robot #420's json")); var translatedRobot = new Robot { Id = 420, Brain = new HasOneDeserializationPlaceholder <Brain>(56) }; translationExpectation.Returns(translatedRobot); var answer = Robots.Find(420); answer.Wait(); getRobotExpectation.MustHaveHappened(); translationExpectation.MustHaveHappened(); Assert.IsInstanceOf <SingleInstanceSubResource <Brain> >(answer.Result.Brain); Assert.AreEqual(56, answer.Result.Brain.Id); }
public void ShouldFetchARecord() { var callRawExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Get, JsonFormatExpectation(), "/admin/robots/89", EmptyQueryParametersExpectation(), null)); callRawExpectation.Returns(TaskForResult <string>("robot #89's json")); var translationExpectation = A.CallTo(() => Shopify.TranslateObject <Robot>("robot", "robot #89's json")); var translatedRobot = new Robot { Id = 89 }; // // TODO: .Get will start setting translationExpectation.Returns(translatedRobot); var answer = Robots.Find(89); answer.Wait(); Assert.AreSame(answer.Result, translatedRobot); // check for the Parts subresource object Assert.AreEqual("/admin/robots/89/parts", answer.Result.Parts.Path()); callRawExpectation.MustHaveHappened(); translationExpectation.MustHaveHappened(); }
public void ShouldReplaceInstanceSubResourceForHasOnePlaceholdersWithinAHasOneInline() { // if we receive a has one inline, we need to be sure that the post-processing also // happens for the resourcemodels deserialized inside a HasOneInline<> var getRobotExpectation = A.CallTo(() => Shopify.CallRaw(HttpMethod.Get, JsonFormatExpectation(), "/admin/robots/420", EmptyQueryParametersExpectation(), null)); getRobotExpectation.Returns(TaskForResult <string>("Robot #420's json")); // Robot #42 has Brain #56 var translationExpectation = A.CallTo(() => Shopify.TranslateObject <Robot>("robot", "Robot #420's json")); var translatedBrain = new Brain { Id = 747, DeepNested = new HasOneDeserializationPlaceholder <DeepNestedHasAInline>(8010) }; var translatedRobot = new Robot { Id = 420, Brain = new HasOneInline <Brain>(translatedBrain) }; translationExpectation.Returns(translatedRobot); var answer = Robots.Find(420); answer.Wait(1000); getRobotExpectation.MustHaveHappened(); translationExpectation.MustHaveHappened(); Assert.IsInstanceOf <HasOneInline <Brain> >(answer.Result.Brain); var hasOneBrain = (HasOneInline <Brain>)(answer.Result.Brain); var brain = hasOneBrain.Get(); brain.Wait(1000); Assert.IsInstanceOf <SingleInstanceSubResource <DeepNestedHasAInline> >(brain.Result.DeepNested); Assert.AreEqual(8010, brain.Result.DeepNested.Id); }