// PUBLIC METHODS /////////////////////////////////////////////////// #region Assert Methods public static void Equal(IEnumerable <Resource> expected, DomNode actual) { if (expected == null) { Assert.Null(actual); return; } Assert.NotNull(actual); Assert.Equal(DomNodeType.Included, actual.NodeType); var actualDomIncluded = (DomIncluded)actual; var actualDomResources = actualDomIncluded.Nodes() .ToList(); var expectedCollection = expected.SafeToReadOnlyList(); var expectedCount = expectedCollection.Count(); var actualCount = actualDomResources.Count(); Assert.Equal(expectedCount, actualCount); var count = expectedCount; for (var i = 0; i < count; ++i) { var expectedResource = expectedCollection[i]; var actualDomResource = (IDomResource)actualDomResources[i]; var actualResource = actualDomResource.ApiResource; ResourceAssert.Equal(expectedResource, actualResource); } }
public void TestDomDocumentDomResources(string name, IServiceModel serviceModel, Document apiDocument) { // Arrange var domDocument = DomDocument.Parse(apiDocument, serviceModel); var expectedApiResources = new List <Resource>(); if (!apiDocument.IsDataNullOrEmpty()) { if (apiDocument.IsResourceDocument()) { var apiResource = apiDocument.GetResource(); expectedApiResources.Add(apiResource); } else if (apiDocument.IsResourceCollectionDocument()) { var apiResourceCollection = apiDocument.GetResourceCollection(); expectedApiResources.AddRange(apiResourceCollection); } } if (!apiDocument.IsIncludedNullOrEmpty()) { var apiIncludedResources = apiDocument.GetIncludedResources(); expectedApiResources.AddRange(apiIncludedResources); } // Act var actualDomResources = domDocument.DomResources() .SafeToList(); var actualApiResources = actualDomResources.Select(x => x.ApiResource) .SafeToList(); this.Output.WriteLine("Test Name: {0}", name); this.Output.WriteLine(String.Empty); this.OutputDomTree(domDocument); this.OutputEmptyLine(); this.Output.WriteLine("Expected Resources"); foreach (var expectedApiResource in expectedApiResources) { this.Output.WriteLine(expectedApiResource.ToString()); } this.OutputEmptyLine(); this.Output.WriteLine("Actual Resources"); foreach (var actualApiResource in actualApiResources) { this.Output.WriteLine(actualApiResource.ToString()); } // Assert ResourceAssert.Equal(expectedApiResources, actualApiResources); }
public void TestResourceParse(string name, Resource expected) { // Arrange var json = expected.ToJson(); // Act this.Output.WriteLine(json); var actual = JsonObject.Parse <Resource>(json); // Assert ResourceAssert.Equal(expected, actual); }
public void TestResourceToJson(string name, Resource expected) { // Arrange // Act var actual = expected.ToJson(); this.Output.WriteLine(actual); // Assert ResourceAssert.Equal(expected, actual); }
// PUBLIC METHODS /////////////////////////////////////////////////// #region Assert Methods public static void Equal(Resource expected, DomReadOnlyResource actual) { if (expected == null) { Assert.Null(actual); return; } Assert.NotNull(actual); Assert.Equal(DomNodeType.Resource, actual.NodeType); var actualResource = actual.ApiResource; ResourceAssert.Equal(expected, actualResource); }
internal void TestIDomResourceAbstraction(string name, Resource expectedApiResource, object expectedClrResource, DomNode actualNode) { // Arrange IDomResource actualDomResource; var actualNodeType = actualNode.NodeType; switch (actualNodeType) { case DomNodeType.Document: { var domDocument = (DomDocument)actualNode; actualDomResource = domDocument.DomResources().Single(); } break; case DomNodeType.Resource: actualDomResource = (IDomResource)actualNode; break; default: throw new ArgumentOutOfRangeException(); } // Act this.Output.WriteLine("Test Name: {0}", name); this.Output.WriteLine(String.Empty); this.OutputDomTree(actualNode); this.Output.WriteLine(String.Empty); this.Output.WriteLine("Expected Resource"); this.OutputJson(expectedApiResource); var actualApiResource = actualDomResource.ApiResource; var actualClrResource = actualDomResource.ClrResource; this.Output.WriteLine(String.Empty); this.Output.WriteLine("Actual Resource"); this.OutputJson(actualApiResource); // Assert ResourceAssert.Equal(expectedApiResource, actualApiResource); ClrResourceAssert.Equal(expectedClrResource, actualClrResource); }