Skip to content

Commit 92d9992

Browse files
author
Caitlin Bales
committed
2 parents 32fc646 + 635b3e4 commit 92d9992

File tree

232 files changed

+128149
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+128149
-403
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Linq;
4+
using Microsoft.Graph.ODataTemplateWriter.Extensions;
5+
using Microsoft.VisualStudio.TestTools.UnitTesting;
6+
using Vipr.Core;
7+
using Vipr.Core.CodeModel;
8+
using Vipr.Reader.OData.v4;
9+
10+
namespace GraphODataTemplateWriter.Test
11+
{
12+
/// <summary>
13+
/// Test GetServiceCollectionNavigationPropertyForPropertyType method
14+
///
15+
/// We have revised the LINQ statement to support the following OData rules
16+
/// regarding containment:
17+
///
18+
/// 1. If a navigation property specifies "ContainsTarget='true'", it is self-contained.
19+
/// Generate a direct path to the item (ie "parent/child").
20+
/// 2. If a navigation property does not specify ContainsTarget but there is a defined EntitySet
21+
/// of the given type, it is a reference relationship. Generate a reference path to the item (ie "item/$ref").
22+
/// 3. If a navigation property does not have a defined EntitySet but there is a Singleton which has
23+
/// a self-contained reference to the given type, we can make a relationship to the implied EntitySet of
24+
/// the singleton. Generate a reference path to the item (ie "singleton/item/$ref").
25+
/// 4. If none of the above pertain to the navigation property, it should be treated as a metadata error.
26+
/// </summary>
27+
[TestClass]
28+
public class ContainmentTests
29+
{
30+
/// <summary>
31+
/// The object model of the test containment metadata
32+
/// </summary>
33+
public OdcmModel model;
34+
35+
/// <summary>
36+
/// These tests load a test metadata file from the file system using VIPR's OData V4 reader
37+
/// </summary>
38+
[TestInitialize]
39+
public void Initialize()
40+
{
41+
string dir = Directory.GetCurrentDirectory();
42+
dir = dir.Replace("\\bin\\Debug", "");
43+
44+
string edmx = File.ReadAllText(dir + "\\Edmx\\Containment.xml");
45+
OdcmReader reader = new OdcmReader();
46+
47+
model = reader.GenerateOdcmModel(new List<TextFile> { new TextFile("$metadata", edmx) });
48+
}
49+
50+
/// <summary>
51+
/// Test an implicit entity set is found for a given navigation property without
52+
/// containment or an explicit entity set
53+
/// </summary>
54+
[TestMethod]
55+
public void TestImplicitEntitySet()
56+
{
57+
var type = model.GetEntityTypes().Where(t => t.Name == "testEntity").First();
58+
var prop = type.Properties.Where(p => p.Name == "testNav").First();
59+
60+
OdcmProperty result = OdcmModelExtensions.GetServiceCollectionNavigationPropertyForPropertyType(prop);
61+
var singleton = model.GetEntityTypes().Where(t => t.Name == "testSingleton").First();
62+
Assert.AreEqual(singleton.Name, result.Name);
63+
}
64+
65+
/// <summary>
66+
/// Test that null is returned when there is no valid explicit or implicit entity set for a
67+
/// given navigation property
68+
/// </summary>
69+
[TestMethod]
70+
public void TestNoValidEntitySet()
71+
{
72+
var type = model.GetEntityTypes().Where(t => t.Name == "testEntity").First();
73+
var prop = type.Properties.Where(p => p.Name == "testInvalidNav").First(); ;
74+
75+
OdcmProperty result = OdcmModelExtensions.GetServiceCollectionNavigationPropertyForPropertyType(prop);
76+
Assert.IsNull(result);
77+
}
78+
79+
/// <summary>
80+
/// Test that an explicit entity set is returned instead of an implicit entity set when both
81+
/// are present in the metadata
82+
/// </summary>
83+
[TestMethod]
84+
public void TestExplicitEntitySet()
85+
{
86+
var type = model.GetEntityTypes().Where(t => t.Name == "testEntity").First();
87+
var prop = type.Properties.Where(p => p.Name == "testExplicitNav").First();
88+
89+
OdcmProperty result = OdcmModelExtensions.GetServiceCollectionNavigationPropertyForPropertyType(prop);
90+
91+
var entitySet = model.EntityContainer.Properties.Where(t => t.Name == "testTypes").First();
92+
Assert.AreEqual(entitySet.Name, result.Name);
93+
}
94+
}
95+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
2+
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
3+
<edmx:DataServices>
4+
<Schema Namespace="graph" xmlns="http://docs.oasis-open.org/odata/ns/edm">
5+
<EntityType Name="entity">
6+
<Key>
7+
<PropertyRef Name="id"/>
8+
</Key>
9+
<Property Name="id" Unicode="false" Nullable="false" Type="Edm.String"/>
10+
</EntityType>
11+
<EntityType Name="testType"></EntityType>
12+
<EntityType Name="testType2"></EntityType>
13+
<EntityType Name="testType3"></EntityType>
14+
<EntityType Name="testEntity">
15+
<NavigationProperty Name="testNav" Type="graph.testType"/>
16+
<NavigationProperty Name="testInvalidNav" Type="graph.testType2"/>
17+
<NavigationProperty Name="testExplicitNav" Type="graph.testType3"/>
18+
</EntityType>
19+
<EntityType Name="testSingleton">
20+
<NavigationProperty Name="testSingleNav" Type="graph.testType" ContainsTarget="true" />
21+
</EntityType>
22+
<EntityType Name="testSingleton2">
23+
<NavigationProperty Name="testSingleNav2" Type="graph.testType3" ContainsTarget="true" />
24+
</EntityType>
25+
<EntityContainer Name="GraphService">
26+
<Singleton Name="testSingleton" Type="graph.testSingleton"/>
27+
<Singleton Name="testSingleton2" Type="graph.testSingleton2"/>
28+
<EntitySet Name="testTypes" EntityType="graph.testType3"/>
29+
</EntityContainer>
30+
</Schema>
31+
</edmx:DataServices>
32+
</edmx:Edmx>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>GraphODataTemplateWriter.Test</RootNamespace>
11+
<AssemblyName>GraphODataTemplateWriter.Test</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
15+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
16+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
17+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
18+
<IsCodedUITest>False</IsCodedUITest>
19+
<TestProjectType>UnitTest</TestProjectType>
20+
<NuGetPackageImportStamp>
21+
</NuGetPackageImportStamp>
22+
</PropertyGroup>
23+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
24+
<DebugSymbols>true</DebugSymbols>
25+
<DebugType>full</DebugType>
26+
<Optimize>false</Optimize>
27+
<OutputPath>bin\Debug\</OutputPath>
28+
<DefineConstants>DEBUG;TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
34+
<HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
35+
</Reference>
36+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
37+
<HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
38+
</Reference>
39+
<Reference Include="System" />
40+
<Reference Include="System.Core" />
41+
<Reference Include="Vipr.Core">
42+
<HintPath>..\submodules\vipr\src\Core\Vipr.Core\bin\Debug\Vipr.Core.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Vipr.Reader.OData.v4">
45+
<HintPath>..\submodules\vipr\src\Readers\Vipr.Reader.OData.v4\bin\Debug\Vipr.Reader.OData.v4.dll</HintPath>
46+
</Reference>
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="*.cs" />
50+
<Compile Include="*\*.cs" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<None Include="packages.config" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<ProjectReference Include="..\src\GraphODataTemplateWriter\GraphODataTemplateWriter.csproj">
57+
<Project>{e6b5202f-4f66-428a-ab92-0aaa11ba81de}</Project>
58+
<Name>GraphODataTemplateWriter</Name>
59+
</ProjectReference>
60+
</ItemGroup>
61+
<ItemGroup>
62+
<Content Include="Edmx\Containment.xml" />
63+
</ItemGroup>
64+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
65+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
66+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
67+
<PropertyGroup>
68+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
69+
</PropertyGroup>
70+
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props'))" />
71+
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets'))" />
72+
</Target>
73+
<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" />
74+
</Project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
[assembly: AssemblyTitle("GraphODataTemplateWriter.Test")]
6+
[assembly: AssemblyProduct("GraphODataTemplateWriter.Test")]
7+
[assembly: AssemblyCopyright("Copyright © 2018")]
8+
9+
[assembly: ComVisible(false)]
10+
11+
[assembly: Guid("2256ec8d-fd7e-4a49-b616-70755afc9f6c")]
12+
13+
[assembly: AssemblyVersion("1.0.0.0")]
14+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="MSTest.TestAdapter" version="1.1.18" targetFramework="net461" />
4+
<package id="MSTest.TestFramework" version="1.1.18" targetFramework="net461" />
5+
</packages>

GraphODataTemplateWriter.sln

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27004.2005
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{6ACF6CEE-A594-4DFE-9286-C7154E91738B}"
77
ProjectSection(SolutionItems) = preProject
@@ -14,6 +14,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphODataTemplateWriter",
1414
EndProject
1515
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Templates", "Templates\Templates.csproj", "{5F526973-F69E-4C26-B8AD-612590A17A9E}"
1616
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphODataTemplateWriter.Test", "GraphODataTemplateWriter.Test\GraphODataTemplateWriter.Test.csproj", "{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}"
18+
ProjectSection(ProjectDependencies) = postProject
19+
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE} = {E6B5202F-4F66-428A-AB92-0AAA11BA81DE}
20+
{5F526973-F69E-4C26-B8AD-612590A17A9E} = {5F526973-F69E-4C26-B8AD-612590A17A9E}
21+
EndProjectSection
22+
EndProject
1723
Global
1824
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1925
Debug|Any CPU = Debug|Any CPU
@@ -26,8 +32,15 @@ Global
2632
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Release|Any CPU.Build.0 = Release|Any CPU
2733
{5F526973-F69E-4C26-B8AD-612590A17A9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2834
{5F526973-F69E-4C26-B8AD-612590A17A9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
38+
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Release|Any CPU.Build.0 = Release|Any CPU
2939
EndGlobalSection
3040
GlobalSection(SolutionProperties) = preSolution
3141
HideSolutionNode = FALSE
3242
EndGlobalSection
43+
GlobalSection(ExtensibilityGlobals) = postSolution
44+
SolutionGuid = {C61920F8-6272-4B08-8A79-3E2B6EDD0C60}
45+
EndGlobalSection
3346
EndGlobal

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Currently the following target languages are supported by this writer:
1010
- Objective-C
1111
- Python
1212
- TypeScript
13+
- PHP
1314

1415
# Contents
1516
- [Prerequisites](#prerequisites)
@@ -19,8 +20,8 @@ Currently the following target languages are supported by this writer:
1920
- [License](#license)
2021

2122
## Prerequisites
22-
- [Visual Studio SDK](https://www.microsoft.com/en-us/download/details.aspx?id=40758)
23-
- [Visual Studio Modeling SDK](https://www.microsoft.com/en-us/download/details.aspx?id=40754)
23+
- [Visual Studio SDK](https://msdn.microsoft.com/en-us/library/bb166441.aspx)
24+
- [Visual Studio Modeling SDK](https://msdn.microsoft.com/en-us/library/bb126259.aspx)
2425

2526
# Getting started
2627

@@ -123,10 +124,27 @@ Note: You can also check in a template by `odcjObject.LongDescriptionContains("f
123124

124125
**Note: Includes/Excludes and Ignore/Matches were used before Vipr had full support for annotations; now that annotations have been added to Vipr usage of these parameters should be limited to legacy scenarios**
125126

127+
## Building against Graph Metadata
128+
129+
There are currently several steps we take to form the metadata into one that will successfully generate SDKs in the shape we expect:
130+
131+
- Remove capability annotations (see [#132](https://github.com/Microsoft/Vipr/issues/132))
132+
- Add navigation annotation to thumbnail
133+
```xml
134+
<Annotation String="navigable" Term="Org.OData.Core.V1.LongDescription"/>
135+
```
136+
- Remove HasStream properties from ```onenotePage``` and ```onenoteEntityBaseModel```
137+
- Add ```ContainsTarget="true"``` to navigation properties that do not have a corresponding EntitySet
138+
- Add long descriptions to types and properties from [docs](https://developer.microsoft.com/en-us/graph/docs/concepts/overview)
139+
140+
In order to build against metadata other than that stored in the [metadata](https://github.com/microsoftgraph/MSGraph-SDK-Code-Generator/tree/master/metadata) directory, you will need to perform the first four on this list.
141+
126142
## Contributing
127143

128144
Before we can accept your pull request, you'll need to electronically complete Microsoft's [Contributor License Agreement](https://cla.microsoft.com/). If you've done this for other Microsoft projects, then you're already covered.
129145

146+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
147+
130148
[Why a CLA?](https://www.gnu.org/licenses/why-assign.html) (from the FSF)
131149

132150
## License

0 commit comments

Comments
 (0)