This commit is contained in:
sushilraje 2018-11-27 15:44:03 -08:00
Родитель 4fd8c1ee24
Коммит 50c9aee16b
7 изменённых файлов: 36 добавлений и 68 удалений

Просмотреть файл

@ -850,24 +850,20 @@ namespace Services.Test
var configType = isEdgeManifest ? string.Empty : ConfigType.Firmware.ToString();
var resultPackages = await this.storage.GetFilteredPackagesAsync(
try
{
var resultPackages = await this.storage.GetFilteredPackagesAsync(
packageType,
configType);
// Assert
if (!isEdgeManifest)
{
var pkg = resultPackages.First();
Assert.Single(resultPackages);
Assert.Equal(type, pkg.PackageType);
Assert.Equal(ConfigType.Firmware.ToString(), pkg.ConfigType);
}
else
{
// Assert
var pkg = resultPackages.First();
Assert.Equal(PackageType.EdgeManifest, pkg.PackageType);
Assert.Equal(string.Empty, pkg.ConfigType);
}
catch (Exception)
{
Assert.False(isEdgeManifest);
}
}
[Fact]
@ -890,7 +886,6 @@ namespace Services.Test
Assert.Empty(result.ConfigTypes);
}
[Fact]
public async Task InvalidPackageThrowsTest()
{

Просмотреть файл

@ -214,11 +214,8 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.Services
}
else if (isPackageTypeEmpty && !isConfigTypeEmpty)
{
// Non-empty ConfigType with empty PackageType indicates Packages of type
// DeviceConfiguration
return packages.Where(p => (p.PackageType.ToString().Equals(
PackageType.DeviceConfiguration.ToString()) &&
p.ConfigType.Equals(configType)));
// Non-empty ConfigType with empty PackageType indicates invalid packages
throw new InvalidInputException("Package Type cannot be empty.");
}
else
{

Просмотреть файл

@ -1,25 +0,0 @@
using System;
using System.Threading.Tasks;
using Microsoft.Azure.IoTSolutions.UIConfig.Services;
using Microsoft.Azure.IoTSolutions.UIConfig.Services.External;
using Microsoft.Azure.IoTSolutions.UIConfig.WebService.v1.Controllers;
using Moq;
using Xunit;
namespace WebService.Test.Controllers
{
public class ConfigTypesControllerTest
{
private readonly Mock<IStorage> mockStorage;
private readonly ConfigTypeController controller;
private readonly Random rand;
private const string DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:sszzz";
public ConfigTypesControllerTest()
{
this.mockStorage = new Mock<IStorage>();
this.controller = new ConfigTypeController(this.mockStorage.Object);
this.rand = new Random();
}
}
}

Просмотреть файл

@ -66,11 +66,12 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.Services.Helpers
// Add optional labels
if (model.DeviceGroupName != null)
{
configuration.Labels.Add(DEPLOYMENT_GROUP_NAME_LABEL, model.DeviceGroupName);
configuration.Labels[DEPLOYMENT_GROUP_NAME_LABEL] = model.DeviceGroupName;
}
if (model.PackageName != null)
{
configuration.Labels.Add(DEPLOYMENT_PACKAGE_NAME_LABEL, model.PackageName);
configuration.Labels[DEPLOYMENT_PACKAGE_NAME_LABEL] = model.PackageName;
}
return configuration;

Просмотреть файл

@ -11,14 +11,14 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.Services.Models
{
public static IDictionary<QueryType, string> Queries = new Dictionary<QueryType, string>()
{
{ QueryType.APPLIED, "SELECT deviceId from devices where configurations.[[{0}]].status" +
" = 'Applied'"},
{ QueryType.SUCCESSFUL, "SELECT deviceId FROM devices WHERE " +
"properties.reported.firmware.fwUpdateStatus='Current' " +
"AND properties.reported.firmware.type='IoTDevKit'"},
{ QueryType.FAILED, "SELECT deviceId FROM devices WHERE " +
"properties.reported.firmware.fwUpdateStatus='Error' " +
"AND properties.reported.firmware.type='IoTDevKit'"}
{ QueryType.APPLIED, @"SELECT deviceId from devices where configurations.[[{0}]].status
= 'Applied'"},
{ QueryType.SUCCESSFUL, @"SELECT deviceId FROM devices WHERE
properties.reported.firmware.fwUpdateStatus='Current'
AND properties.reported.firmware.type='IoTDevKit'"},
{ QueryType.FAILED, @"SELECT deviceId FROM devices WHERE
properties.reported.firmware.fwUpdateStatus='Error'
AND properties.reported.firmware.type='IoTDevKit'"}
};
}
@ -26,16 +26,16 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.Services.Models
{
public static IDictionary<QueryType, string> Queries = new Dictionary<QueryType, string>()
{
{ QueryType.APPLIED, "select deviceId from devices.modules" +
" where moduleId = '$edgeAgent' and " +
"configurations.[[{0}]].status = 'Applied'" },
{ QueryType.SUCCESSFUL, "select deviceId from devices.modules" +
" where moduleId = '$edgeAgent' and " +
"properties.desired.$version = properties.reported.lastDesiredVersion and " +
"properties.reported.lastDesiredStatus.code = 200" },
{ QueryType.FAILED, "SELECT deviceId FROM devices WHERE" +
" properties.reported.firmware.fwUpdateStatus='Error'" +
" AND properties.reported.firmware.type='IoTDevKit'" }
{ QueryType.APPLIED, @"select deviceId from devices.modules
where moduleId = '$edgeAgent' and
configurations.[[{0}]].status = 'Applied'" },
{ QueryType.SUCCESSFUL, @"select deviceId from devices.modules
where moduleId = '$edgeAgent' and
properties.desired.$version = properties.reported.lastDesiredVersion and
properties.reported.lastDesiredStatus.code = 200" },
{ QueryType.FAILED, @"SELECT deviceId FROM devices WHERE
properties.reported.firmware.fwUpdateStatus='Error'
AND properties.reported.firmware.type='IoTDevKit'" }
};
}
@ -43,8 +43,8 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.Services.Models
{
public static IDictionary<QueryType, string> Queries = new Dictionary<QueryType, string>()
{
{ QueryType.APPLIED, "SELECT deviceId from devices where" +
" configurations.[[{0}]].status = 'Applied'" },
{ QueryType.APPLIED, @"SELECT deviceId from devices where
configurations.[[{0}]].status = 'Applied'" },
{ QueryType.SUCCESSFUL, String.Empty },
{ QueryType.FAILED, String.Empty }
};

Просмотреть файл

@ -136,7 +136,7 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.Auth
if (!this.InitializeTokenValidationAsync(context.RequestAborted).Result)
{
context.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
context.Response.Headers["Content-PackageType"] = "application/json";
context.Response.Headers["Content-Type"] = "application/json";
context.Response.WriteAsync(ERROR503_AUTH);
return Task.CompletedTask;
}
@ -167,7 +167,7 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.Auth
this.log.Warn("Authentication required", () => { });
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
context.Response.Headers["Content-PackageType"] = "application/json";
context.Response.Headers["Content-Type"] = "application/json";
context.Response.WriteAsync(ERROR401);
return Task.CompletedTask;

Просмотреть файл

@ -28,7 +28,7 @@ namespace Microsoft.Azure.IoTSolutions.IotHubManager.WebService.v1.Models
[JsonProperty(PropertyName = "MaxExecutionTimeInSeconds", NullValueHandling = NullValueHandling.Ignore)]
public long? MaxExecutionTimeInSeconds { get; set; }
[JsonProperty(PropertyName = "PackageType")]
[JsonProperty(PropertyName = "Type")]
public JobType Type { get; set; }
[JsonProperty(PropertyName = "Status")]