Skip to content

Commit

Permalink
Merge pull request #52 from MabOneSdk/csm-pikumar
Browse files Browse the repository at this point in the history
Csm pikumar
  • Loading branch information
pikumarmsft16 committed Jul 31, 2015
2 parents 9ef967d + a4f6def commit 9a73ea6
Show file tree
Hide file tree
Showing 39 changed files with 2,687 additions and 1,204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
<Import Project="$(LibraryToolsFolder)\Test.Dependencies.target" />
<ItemGroup>
<Compile Include="Helpers\VaultTestHelper.cs" />
<Compile Include="ScenarioTests\AzureBackupItemTests.cs" />
<Compile Include="ScenarioTests\BackupServicesTestBase.cs" />
<Compile Include="ScenarioTests\BackUpTests.cs" />
<Compile Include="ScenarioTests\ContainerTests.cs" />
<Compile Include="ScenarioTests\CSMAzureBackupItem.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="ScenarioTests\JobsTests.cs" />
<Compile Include="ScenarioTests\CSMProtectionPolicyTests.cs" />
<Compile Include="ScenarioTests\RecoveryPointTests.cs" />
<Compile Include="ScenarioTests\RestoreTest.cs" />
<Compile Include="ScenarioTests\VaultTests.cs" />
<Compile Include="ScenarioTests\VaultTests.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.WindowsAzure.Management.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
//
// Copyright (c) Microsoft. 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.
//

using Microsoft.Azure.Management.BackupServices;
using Microsoft.Azure.Management.BackupServices.Models;
using Microsoft.Azure.Test;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

namespace BackupServices.Tests
{
public class CSMAzureBackupItem : BackupServicesTestsBase
{
[Fact]
public void EnableAzureBackupProtectionTest()
{
using (UndoContext context = UndoContext.Current)
{
var client = GetServiceClient<BackupServicesManagementClient>();
context.Start();
CSMSetProtectionRequest input = new CSMSetProtectionRequest();
input.Properties = new CSMSetProtectionRequestProperties();
input.Properties.PolicyId = ConfigurationManager.AppSettings["PolicyId"];
string itemName = ConfigurationManager.AppSettings["AzureBackupItemName"];
string containerName = ConfigurationManager.AppSettings["ContainerName"];

var response = client.DataSource.EnableProtectionCSM(GetCustomRequestHeaders(),
containerName,
itemName,
input);

Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
}
}

[Fact]
public void UpdateAzureBackupProtectionTest()
{
using (UndoContext context = UndoContext.Current)
{
var client = GetServiceClient<BackupServicesManagementClient>();
context.Start();

CSMUpdateProtectionRequest input = new CSMUpdateProtectionRequest();
input.Properties = new CSMUpdateProtectionRequestProperties();
string itemName = ConfigurationManager.AppSettings["AzureBackupItemName"];
string containerName = ConfigurationManager.AppSettings["ContainerName"];
input.Properties.PolicyId = string.Empty;

var response = client.DataSource.UpdateProtectionCSM(GetCustomRequestHeaders(),
containerName,
itemName,
input);

Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
}
}

[Fact]
public void DisableAzureBackupProtectionTest()
{
using (UndoContext context = UndoContext.Current)
{
var client = GetServiceClient<BackupServicesManagementClient>();
context.Start();

string itemName = ConfigurationManager.AppSettings["AzureBackupItemName"];
string containerName = ConfigurationManager.AppSettings["ContainerName"];
var response = client.DataSource.DisableProtectionCSM(GetCustomRequestHeaders(),
containerName,
itemName);

Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
}
}

[Fact]
public void ListAzureBackupItemPOTest()
{
using (UndoContext context = UndoContext.Current)
{
context.Start();

CSMItemQueryObject POQueryParam = new CSMItemQueryObject()
{
Status = null,
Type = null
};

var client = GetServiceClient<BackupServicesManagementClient>();

var response = client.ProtectableObject.ListCSMAsync(POQueryParam, GetCustomRequestHeaders()).Result;

Assert.True(response.CSMItemListResponse.Value.Count > 0, "Protectable Object Result count can't be less than 1");

foreach (var po in response.CSMItemListResponse.Value)
{
Assert.True(!string.IsNullOrEmpty(po.Properties.ContainerId), "ContainerId can't be null or empty");
Assert.True(!string.IsNullOrEmpty(po.Properties.FriendlyName), "FriendlyName can't be null or empty");
Assert.True(!string.IsNullOrEmpty(po.Properties.ItemType), "ItemType can't be null or empty");
Assert.True(!string.IsNullOrEmpty(po.Properties.Status), "Status can't be null or empty");
Assert.True(!string.IsNullOrEmpty(po.Name), "Name can't be null or empty");
Assert.True(!string.IsNullOrEmpty(po.Type), "Type can't be null or empty");
}

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}

[Fact]
public void ListAzureBackupItemDSTest()
{
using (UndoContext context = UndoContext.Current)
{
context.Start();

CSMProtectedItemQueryObject DSQueryParam = new CSMProtectedItemQueryObject()
{
ProtectionStatus = null,
Status = null,
Type = null
};

var client = GetServiceClient<BackupServicesManagementClient>();

var response = client.DataSource.ListCSMAsync(DSQueryParam, GetCustomRequestHeaders()).Result;
foreach (var ds in response.CSMProtectedItemListResponse.Value)
{
Assert.True(!string.IsNullOrEmpty(ds.Properties.ContainerId), "ContainerId can't be null or empty");
Assert.True(!string.IsNullOrEmpty(ds.Properties.FriendlyName), "FriendlyName can't be null or empty");
Assert.True(!string.IsNullOrEmpty(ds.Properties.ItemType), "ItemType can't be null or empty");
Assert.True(!string.IsNullOrEmpty(ds.Properties.LastBackupJobId), "LastBackupJobId can't be null or empty");
Assert.True(!string.IsNullOrEmpty(ds.Properties.LastBackupStatus), "LastBackupStatus can't be null or empty");
Assert.True(!string.IsNullOrEmpty(ds.Properties.ProtectionPolicyId), "ProtectionPolicyId can't be null or empty");
Assert.True(!string.IsNullOrEmpty(ds.Properties.ProtectionStatus), "ProtectionStatus can't be null or empty");
Assert.True(!string.IsNullOrEmpty(ds.Properties.RecoveryPointsCount.ToString()), "RecoveryPointsCount can't be null or empty");
Assert.True(!string.IsNullOrEmpty(ds.Properties.Status), "Status can't be null or empty");
Assert.True(!string.IsNullOrEmpty(ds.Name), "Name can't be null or empty");
Assert.True(!string.IsNullOrEmpty(ds.Type), "Type can't be null or empty");
}

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void ListProtectionPolicyTest()
context.Start();
var client = GetServiceClient<BackupServicesManagementClient>();

var response = client.ProtectionPolicy.List(GetCustomRequestHeaders());
var response = client.CSMProtectionPolicy.List(GetCustomRequestHeaders());

Assert.True(response.CSMProtectionPolicyListResponse.Value.Count > 0, "Protection Policies Result count can't be less than 1");

Expand All @@ -32,12 +32,12 @@ public void ListProtectionPolicyTest()
Assert.True(!string.IsNullOrEmpty(ppo.Name), "Policy Name can't be null or empty");
if(ppo.Properties.BackupSchedule.ScheduleRun == "Daily")
{
Assert.True(ppo.Properties.LTRRetentionPolicy.DailySchedule == null, "Daily RetentionType can't be null or empty for Daily Schedule");
Assert.True(ppo.Properties.LtrRetentionPolicy.DailySchedule == null, "Daily RetentionType can't be null or empty for Daily Schedule");

}
else
{
Assert.True(ppo.Properties.LTRRetentionPolicy.WeeklySchedule == null, "Weekly RetentionType can't be null or empty for Weekly Schedule");
Assert.True(ppo.Properties.LtrRetentionPolicy.WeeklySchedule == null, "Weekly RetentionType can't be null or empty for Weekly Schedule");

}
}
Expand All @@ -61,7 +61,7 @@ public void AddProtectionPolicyTest()
addProtectionPolicyRequest.Properties.BackupSchedule = backupSchedule;
addProtectionPolicyRequest.Properties.WorkloadType = ConfigurationManager.AppSettings["WorkloadType"];
addProtectionPolicyRequest.Properties.LtrRetentionPolicy = GetRetentionPolicy(backupSchedule.ScheduleRunTimes);
var response = client.ProtectionPolicy.Add(policyName, addProtectionPolicyRequest, GetCustomRequestHeaders());
var response = client.CSMProtectionPolicy.Add(policyName, addProtectionPolicyRequest, GetCustomRequestHeaders());

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
Expand All @@ -81,7 +81,7 @@ public void UpdateProtectionPolicyTest()
string policyName = ConfigurationManager.AppSettings["PolicyName"];
updateProtectionPolicyRequest.Properties.BackupSchedule = backupSchedule;
updateProtectionPolicyRequest.Properties.LtrRetentionPolicy = GetRetentionPolicy(backupSchedule.ScheduleRunTimes);
var response = client.ProtectionPolicy.Update(policyName, updateProtectionPolicyRequest, GetCustomRequestHeaders());
var response = client.CSMProtectionPolicy.Update(policyName, updateProtectionPolicyRequest, GetCustomRequestHeaders());
var isSuccess = (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted) ? true : false;
Assert.Equal(true, isSuccess);
}
Expand All @@ -95,7 +95,7 @@ public void DeleteProtectionPolicyTest()
context.Start();
var client = GetServiceClient<BackupServicesManagementClient>();
string policyName = ConfigurationManager.AppSettings["PolicyName"];
var response = client.ProtectionPolicy.Delete(policyName, GetCustomRequestHeaders());
var response = client.CSMProtectionPolicy.Delete(policyName, GetCustomRequestHeaders());

Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
}
Expand Down
Loading

0 comments on commit 9a73ea6

Please sign in to comment.