Skip to content

Commit

Permalink
Add shared sql components (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonpollett authored Mar 20, 2020
1 parent 22968fe commit 13dfd50
Show file tree
Hide file tree
Showing 55 changed files with 4,350 additions and 13 deletions.
28 changes: 28 additions & 0 deletions Microsoft.Health.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Health.Abstractions", "src\Microsoft.Health.Abstractions\Microsoft.Health.Abstractions.csproj", "{E0CD7A0A-116D-4612-83BE-0DE036DADDF1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Health.SqlServer", "src\Microsoft.Health.SqlServer\Microsoft.Health.SqlServer.csproj", "{CF5D97F8-DE8F-4965-923D-82CA40CC9E49}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Health.SqlServer.Api", "src\Microsoft.Health.SqlServer.Api\Microsoft.Health.SqlServer.Api.csproj", "{561B1075-FA22-4D4E-881B-366230423B2D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Health.SqlServer.Api.UnitTests", "src\Microsoft.Health.SqlServer.Api.UnitTests\Microsoft.Health.SqlServer.Api.UnitTests.csproj", "{7650CF08-00B4-419B-8AF9-26E4079F08F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Health.SqlServer.UnitTests", "src\Microsoft.Health.SqlServer.UnitTests\Microsoft.Health.SqlServer.UnitTests.csproj", "{8FEF74DC-94A5-4E20-9BE2-095941935EC4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -43,6 +51,22 @@ Global
{E0CD7A0A-116D-4612-83BE-0DE036DADDF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0CD7A0A-116D-4612-83BE-0DE036DADDF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0CD7A0A-116D-4612-83BE-0DE036DADDF1}.Release|Any CPU.Build.0 = Release|Any CPU
{CF5D97F8-DE8F-4965-923D-82CA40CC9E49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF5D97F8-DE8F-4965-923D-82CA40CC9E49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF5D97F8-DE8F-4965-923D-82CA40CC9E49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF5D97F8-DE8F-4965-923D-82CA40CC9E49}.Release|Any CPU.Build.0 = Release|Any CPU
{561B1075-FA22-4D4E-881B-366230423B2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{561B1075-FA22-4D4E-881B-366230423B2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{561B1075-FA22-4D4E-881B-366230423B2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{561B1075-FA22-4D4E-881B-366230423B2D}.Release|Any CPU.Build.0 = Release|Any CPU
{7650CF08-00B4-419B-8AF9-26E4079F08F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7650CF08-00B4-419B-8AF9-26E4079F08F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7650CF08-00B4-419B-8AF9-26E4079F08F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7650CF08-00B4-419B-8AF9-26E4079F08F2}.Release|Any CPU.Build.0 = Release|Any CPU
{8FEF74DC-94A5-4E20-9BE2-095941935EC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FEF74DC-94A5-4E20-9BE2-095941935EC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FEF74DC-94A5-4E20-9BE2-095941935EC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FEF74DC-94A5-4E20-9BE2-095941935EC4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -52,6 +76,10 @@ Global
{614DE061-52A0-4471-A3F1-50C9C907FFDB} = {8AD2A324-DAB5-4380-94A5-31F7D817C384}
{CA276939-8071-4734-9FE4-ADC825B72116} = {B70945F4-01A6-4351-955B-C4A2943B5E3B}
{E0CD7A0A-116D-4612-83BE-0DE036DADDF1} = {8AD2A324-DAB5-4380-94A5-31F7D817C384}
{CF5D97F8-DE8F-4965-923D-82CA40CC9E49} = {8AD2A324-DAB5-4380-94A5-31F7D817C384}
{561B1075-FA22-4D4E-881B-366230423B2D} = {8AD2A324-DAB5-4380-94A5-31F7D817C384}
{7650CF08-00B4-419B-8AF9-26E4079F08F2} = {8AD2A324-DAB5-4380-94A5-31F7D817C384}
{8FEF74DC-94A5-4E20-9BE2-095941935EC4} = {8AD2A324-DAB5-4380-94A5-31F7D817C384}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
RESX_SortFileContentOnSave = True
Expand Down
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,3 @@ provided by the bot. You will only need to do this once across all repos using o
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.

# Releasing
To publish Nuget packages, you must create a release using the GitHub release feature. The release should be
tagged with a version like `1.0.0-master-{yyyymmdd}-{daily iteration}`. For example if you wanted to create a release
on March 4, 2020 the version would be `1.0.0-master-20200304-1`. If you wanted to create a second release on that
date, the version would be `1.0.0-master-20200304-2`.

Publishing a release will envoke the [.NET Core Build & Publish workflow](.github/workflows/dotnetbuildpublish.yml)
and publish the Nugets with the version specified to the GitHub package repository.
173 changes: 173 additions & 0 deletions THIRDPARTYNOTICES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# Third party notices

Do Not Translate or Localize

This file is based on or incorporates material from the projects listed below (Third Party IP). The original copyright notice and the license under which Microsoft received such Third Party IP, are set forth below. Such licenses and notices are provided for informational purposes only. Microsoft licenses the Third Party IP to you under the licensing terms for the Microsoft product. Microsoft reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise.

## Ensure.That 8.1.2
* Component Source: https://github.com/danielwertheim/Ensure.That/
* Component Copyright and License:
> The MIT License (MIT)
>
> Copyright (c) 2015 Daniel Wertheim
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
## Newtonsoft.Json.Schema 3.0.11
* Component Source: https://github.com/JamesNK/Newtonsoft.Json.Schema/
* Component Copyright and License:
> Json.NET Schema
>
> Copyright (c) 2014 Newtonsoft
>
> This program is free software: you can redistribute it and/or modify it
> under the terms of the GNU Affero General Public License as published by the
> Free Software Foundation, either version 3 of the License, see
> http://www.gnu.org/licenses/agpl-3.0.html.
>
> This program is distributed in the hope that it will be useful, but WITHOUT
> ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
> FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
>
>
> Commercial License
>
> In addition to this license, Json.NET Schema is offered under a commercial license.
## NSubstitute 4.2.1
* Component Source: https://github.com/nsubstitute/
* Component Copyright and License:
> Copyright (c) 2009 Anthony Egerton ([email protected]) and David Tchepak ([email protected])
> All rights reserved.
>
> Redistribution and use in source and binary forms, with or without modification,
> are permitted provided that the following conditions are met:
>
> * Redistributions of source code must retain the above copyright notice,
> this list of conditions and the following disclaimer.
> * Redistributions in binary form must reproduce the above copyright notice,
> this list of conditions and the following disclaimer in the documentation
> and/or other materials provided with the distribution.
> * Neither the names of the copyright holders nor the names of
> contributors may be used to endorse or promote products derived from this
> software without specific prior written permission.
>
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
> ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
> WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
> FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
> SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
> CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
> THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>
> [ http://www.opensource.org/licenses/bsd-license.php ]>
## StyleCop.Analyzers 1.1.118
* Component Source: https://github.com/DotNetAnalyzers/StyleCopAnalyzers/
* Component Copyright and License:
>Copyright (c) Tunnel Vision Laboratories, LLC. All rights reserved.
>
>Licensed under the Apache License, Version 2.0 (the "License"); you may not use
>these files except in compliance with the License. You may obtain a copy of the
>License at
>
>http://www.apache.org/licenses/LICENSE-2.0
>
>Unless required by applicable law or agreed to in writing, software distributed
>under the License 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.
>
>---
>
>This project uses other open source projects, which are used under the terms
>of the following license(s).
>
>.NET Compiler Platform ("Roslyn")
>
> Copyright Microsoft.
>
> Licensed under the Apache License, Version 2.0 (the "License"); you may not use
> these files except in compliance with the License. You may obtain a copy of the
> License at
>
> http://www.apache.org/licenses/LICENSE-2.0
>
> Unless required by applicable law or agreed to in writing, software distributed
> under the License 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.
>
>Code Cracker
>
> Copyright 2014 Giovanni Bassi and Elemar Jr.
>
> Licensed under the Apache License, Version 2.0 (the "License"); you may not use
> these files except in compliance with the License. You may obtain a copy of the
> License at
>
> http://www.apache.org/licenses/LICENSE-2.0
>
> Unless required by applicable law or agreed to in writing, software distributed
> under the License 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.
>
>LightJson
>
> Copyright (c) 2017 Marcos López C.
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
## XUnit 2.4.1
* Component Source: https://github.com/xunit/xunit
* Component Copyright and License:
> Copyright (c) .NET Foundation and Contributors
> 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.
> You may obtain a copy of the License at
>
> http://www.apache.org/licenses/LICENSE-2.0
>
> Unless required by applicable law or agreed to in writing, software
> distributed under the License 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

namespace Microsoft.Health.Abstractions.Exceptions
{
public class ServiceUnavailableException : MicrosoftHealthException
{
public ServiceUnavailableException()
: base(Resources.ServiceUnavailable)
{
}
}
}
11 changes: 10 additions & 1 deletion src/Microsoft.Health.Abstractions/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Microsoft.Health.Abstractions/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@
<data name="RequestRateExceeded" xml:space="preserve">
<value>The request rate has exceeded the maximum API request rate and is being throttled. Please try again later.</value>
</data>
<data name="ServiceUnavailable" xml:space="preserve">
<value>The operation could not be completed, because the service was unable to accept new requests. It is safe to retry the operation. If the issue persists, please contact support.</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// -------------------------------------------------------------------------------------------------
// 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.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Health.SqlServer.Api.Controllers;
using Microsoft.Health.SqlServer.Features.Schema;
using Newtonsoft.Json.Linq;
using NSubstitute;
using Xunit;

namespace Microsoft.Health.SqlServer.Api.UnitTests.Controllers
{
public class SchemaControllerTests
{
private readonly SchemaController _schemaController;
private readonly SchemaInformation _schemaInformation;

public SchemaControllerTests()
{
_schemaInformation = new SchemaInformation((int)TestSchemaVersion.Version1, (int)TestSchemaVersion.Version3);

var urlHelperFactory = Substitute.For<IUrlHelperFactory>();
var urlHelper = Substitute.For<IUrlHelper>();
urlHelper.RouteUrl(Arg.Any<UrlRouteContext>()).Returns("https://localhost/script");
urlHelperFactory.GetUrlHelper(Arg.Any<ActionContext>()).Returns(urlHelper);

var scriptProvider = Substitute.For<IScriptProvider>();

_schemaController = new SchemaController(_schemaInformation, scriptProvider, urlHelperFactory, NullLogger<SchemaController>.Instance);
}

[Fact]
public void GivenAScriptRequest_WhenSchemaIdFound_ThenReturnScriptSuccess()
{
ActionResult result = _schemaController.SqlScript(1);
string script = result.ToString();
Assert.NotNull(script);
}

[Fact]
public void GivenAnAvailableVersionsRequest_WhenCurrentVersionIsNull_ThenAllVersionsReturned()
{
ActionResult result = _schemaController.AvailableVersions();

var jsonResult = result as JsonResult;
Assert.NotNull(jsonResult);

var jArrayResult = JArray.FromObject(jsonResult.Value);
Assert.Equal(Enum.GetNames(typeof(TestSchemaVersion)).Length, jArrayResult.Count);

JToken firstResult = jArrayResult.First;
Assert.Equal(1, firstResult["id"]);
Assert.Equal("https://localhost/script", firstResult["script"]);
}

[Fact]
public void GivenAnAvailableVersionsRequest_WhenCurrentVersionNotNull_ThenCorrectVersionsReturned()
{
_schemaInformation.Current = (int)TestSchemaVersion.Version2;
ActionResult result = _schemaController.AvailableVersions();

var jsonResult = result as JsonResult;
Assert.NotNull(jsonResult);

var jArrayResult = JArray.FromObject(jsonResult.Value);
Assert.Equal(Enum.GetNames(typeof(TestSchemaVersion)).Length - 1, jArrayResult.Count);

JToken firstResult = jArrayResult.First;
Assert.Equal(2, firstResult["id"]);
Assert.Equal("https://localhost/script", firstResult["script"]);
}

[Fact]
public void GivenACurrentVersionRequest_WhenNotImplemented_ThenNotImplementedShouldBeThrown()
{
Assert.Throws<NotImplementedException>(() => _schemaController.CurrentVersion());
}

[Fact]
public void GivenACompatibilityRequest_WhenNotImplemented_ThenNotImplementedShouldBeThrown()
{
Assert.Throws<NotImplementedException>(() => _schemaController.Compatibility());
}
}
}
Loading

0 comments on commit 13dfd50

Please sign in to comment.