2017-11-15 00:40:27 +01:00
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
|
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.OData.Edm;
|
2017-11-22 03:32:29 +01:00
|
|
|
|
using Microsoft.OpenApi.OData.Tests;
|
2017-11-15 00:40:27 +01:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
2017-11-22 03:32:29 +01:00
|
|
|
|
namespace Microsoft.OpenApi.OData.Generator.Tests
|
2017-11-15 00:40:27 +01:00
|
|
|
|
{
|
|
|
|
|
public class OpenApiPathsGeneratorTest
|
|
|
|
|
{
|
2017-11-22 03:32:29 +01:00
|
|
|
|
private OpenApiConvertSettings _settings = new OpenApiConvertSettings();
|
|
|
|
|
|
2017-11-15 00:40:27 +01:00
|
|
|
|
[Fact]
|
2017-11-22 04:44:38 +01:00
|
|
|
|
public void CreatePathsThrowArgumentNullContext()
|
2017-11-15 00:40:27 +01:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
2017-11-22 04:44:38 +01:00
|
|
|
|
ODataContext context = null;
|
2017-11-15 00:40:27 +01:00
|
|
|
|
|
|
|
|
|
// Act & Assert
|
2017-11-22 04:44:38 +01:00
|
|
|
|
Assert.Throws<ArgumentNullException>("context", () => context.CreatePaths());
|
2017-11-15 00:40:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreatePathsReturnsForEmptyModel()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
IEdmModel model = EdmModelHelper.EmptyModel;
|
2017-11-22 04:44:38 +01:00
|
|
|
|
ODataContext context = new ODataContext(model);
|
2017-11-15 00:40:27 +01:00
|
|
|
|
|
|
|
|
|
// Act
|
2017-11-22 04:44:38 +01:00
|
|
|
|
var paths = context.CreatePaths();
|
2017-11-15 00:40:27 +01:00
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.NotNull(paths);
|
|
|
|
|
Assert.Empty(paths);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CreatePathsReturnsForBasicModel()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
IEdmModel model = EdmModelHelper.BasicEdmModel;
|
2017-11-22 04:44:38 +01:00
|
|
|
|
ODataContext context = new ODataContext(model);
|
2017-11-15 00:40:27 +01:00
|
|
|
|
|
|
|
|
|
// Act
|
2017-11-22 04:44:38 +01:00
|
|
|
|
var paths = context.CreatePaths();
|
2017-11-15 00:40:27 +01:00
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.NotNull(paths);
|
2017-11-16 20:19:47 +01:00
|
|
|
|
Assert.Equal(7, paths.Count);
|
2017-11-15 00:40:27 +01:00
|
|
|
|
|
|
|
|
|
Assert.Contains("/People", paths.Keys);
|
|
|
|
|
Assert.Contains("/People('{UserName}')", paths.Keys);
|
|
|
|
|
Assert.Contains("/City", paths.Keys);
|
|
|
|
|
Assert.Contains("/City('{Name}')", paths.Keys);
|
|
|
|
|
Assert.Contains("/CountryOrRegion", paths.Keys);
|
|
|
|
|
Assert.Contains("/CountryOrRegion('{Name}')", paths.Keys);
|
2017-11-16 20:19:47 +01:00
|
|
|
|
Assert.Contains("/Me", paths.Keys);
|
2017-11-15 00:40:27 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|