Skip to content

Commit

Permalink
Merge pull request #2 from nsip/develop
Browse files Browse the repository at this point in the history
Develop 3.2 (do not use as it is an obsolete SIF Infrastructure)
  • Loading branch information
joerghuber authored May 1, 2017
2 parents 1469e47 + 7ca04f4 commit 58b3251
Show file tree
Hide file tree
Showing 94 changed files with 33,285 additions and 53,737 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("3.1.0.0")]
[assembly: AssemblyFileVersion("3.1.0.0")]
[assembly: AssemblyVersion("3.2.0.0")]
[assembly: AssemblyFileVersion("3.2.0.0")]
Binary file modified Code/Sif3Framework/Sif.Framework.Tests/Data files/environment.xml
Binary file not shown.
58 changes: 30 additions & 28 deletions Code/Sif3Framework/Sif.Framework.Tests/DataFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Systemic Pty Ltd
* Copyright 2017 Systemic Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/

using NHibernate.Tool.hbm2ddl;
using System;
using System.Collections.Generic;
using Configuration = NHibernate.Cfg.Configuration;

Expand All @@ -39,26 +40,29 @@ public static void CreateDatabase()
schemaExport.Create(true, true);
}

/// <summary>
/// Create an Environment request populated with dummy data.
/// </summary>
/// <returns>Environment request.</returns>
public static Environment CreateEnvironmentRequest()
{
ProductIdentity adapterProduct = new ProductIdentity { IconURI = "icon url 1", ProductName = "product name 1", ProductVersion = "3.4.1", VendorName = "Systemic" };
ProductIdentity applicationProduct = new ProductIdentity { IconURI = "icon url 2", ProductName = "product name 2", ProductVersion = "9.80", VendorName = "Systemic" };
Property zoneCharge = new Property { Name = "charge", Value = "Negative" };
Property zoneMaster = new Property { Name = "master", Value = "Annihilus" };
IDictionary<string, Property> zoneProperties =
new Dictionary<string, Property> { { zoneCharge.Name, zoneCharge }, { zoneMaster.Name, zoneMaster } };
Zone theNegativeZone = new Zone
IDictionary<string, Property> zoneProperties = new Dictionary<string, Property>
{
Description = "The Negative Zone",
Properties = zoneProperties
{ zoneCharge.Name, zoneCharge },
{ zoneMaster.Name, zoneMaster }
};
Zone theNegativeZone = new Zone { Description = "The Negative Zone", Properties = zoneProperties };
ApplicationInfo applicationInfo = new ApplicationInfo
{
AdapterProduct = adapterProduct,
ApplicationKey = "UnitTesting",
ApplicationProduct = applicationProduct,
DataModelNamespace = "http://www.sifassociation.org/au/datamodel/1.4",
SupportedInfrastructureVersion = "3.0",
DataModelNamespace = "http://www.sifassociation.org/datamodel/au/3.4",
SupportedInfrastructureVersion = "3.2",
Transport = "REST"
};
Environment environmentRequest = new Environment
Expand All @@ -68,15 +72,19 @@ public static Environment CreateEnvironmentRequest()
ConsumerName = "UnitTestConsumer",
DefaultZone = theNegativeZone,
InstanceId = "ThisInstance01",
SessionToken = "2e5dd3ca282fc8ddb3d08dcacc407e8a",
SessionToken = Guid.NewGuid().ToString(),
SolutionId = "auTestSolution",
Type = Model.Infrastructure.EnvironmentType.DIRECT,
Type = EnvironmentType.DIRECT,
UserToken = "UserToken01"
};

return environmentRequest;
}

/// <summary>
/// Create an Environment response populated with dummy data.
/// </summary>
/// <returns>Environment response.</returns>
public static Environment CreateEnvironmentResponse()
{
InfrastructureService environmentURL = new InfrastructureService { Name = InfrastructureServiceNames.environment, Value = "http://rest3api.sifassociation.org/api/solutions/auTestSolution/environments/5b72f2d4-7a83-4297-a71f-8b5fb26cbf14" };
Expand All @@ -95,31 +103,25 @@ public static Environment CreateEnvironmentResponse()

Right adminRight = new Right() { Type = RightType.ADMIN.ToString(), Value = RightValue.APPROVED.ToString() };
Right createRight = new Right() { Type = RightType.CREATE.ToString(), Value = RightValue.APPROVED.ToString() };
IDictionary<string, Right> rights = new Dictionary<string, Right> { { adminRight.Type, adminRight } };

Infrastructure.Service studentPersonalsService = new Infrastructure.Service
IDictionary<string, Right> rights = new Dictionary<string, Right>
{
ContextId = "DEFAULT",
Name = "StudentPersonals",
Rights = rights,
Type = "OBJECT"
{ adminRight.Type, adminRight }
};
Infrastructure.Service schoolInfosService = new Infrastructure.Service
Service studentPersonalsService = new Service { ContextId = "DEFAULT", Name = "StudentPersonals", Rights = rights, Type = "OBJECT" };
Service schoolInfosService = new Service { ContextId = "DEFAULT", Name = "SchoolInfos", Rights = rights, Type = "OBJECT" };
ICollection<Service> services = new SortedSet<Service>
{
ContextId = "DEFAULT",
Name = "SchoolInfos",
Rights = rights,
Type = "OBJECT"
};
ICollection<Infrastructure.Service> services = new SortedSet<Infrastructure.Service>
{
studentPersonalsService, schoolInfosService
studentPersonalsService,
schoolInfosService
};

ProvisionedZone schoolZone = new ProvisionedZone { SifId = "auSchoolTestingZone", Services = services };
ProvisionedZone studentZone = new ProvisionedZone { SifId = "auStudentTestingZone", Services = services };

IDictionary<string, ProvisionedZone> provisionedZones = new SortedDictionary<string, ProvisionedZone> { { schoolZone.SifId, schoolZone }, { studentZone.SifId, studentZone } };
IDictionary<string, ProvisionedZone> provisionedZones = new SortedDictionary<string, ProvisionedZone>
{
{ schoolZone.SifId, schoolZone },
{ studentZone.SifId, studentZone }
};

Environment environmentResponse = CreateEnvironmentRequest();
environmentResponse.InfrastructureServices = infrastructureServices;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 Systemic Pty Ltd
* Copyright 2017 Systemic Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,42 +17,68 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sif.Framework.Model.Infrastructure;
using System;
using System.Collections;
using System.Collections.Generic;
using Environment = Sif.Framework.Model.Infrastructure.Environment;

namespace Sif.Framework.Persistence.NHibernate
{

/// <summary>
/// Unit test for EnvironmentRepository.
/// </summary>
[TestClass]
public class EnvironmentRepositoryTest
{
private IEnvironmentRepository environmentRepository;

// Use ClassInitialize to run code before running the first test in the class
/// <summary>
/// Use ClassInitialize to run code before running the first test in the class.
/// </summary>
/// <param name="testContext">Context information for the unit test.</param>
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext)
public static void ClassInitialize(TestContext testContext)
{
DataFactory.CreateDatabase();
}

// Use ClassCleanup to run code after all tests in a class have run
/// <summary>
/// Use ClassCleanup to run code after all tests in a class have run.
/// </summary>
[ClassCleanup()]
public static void MyClassCleanup() { }
public static void ClassCleanup()
{
}

// Use TestInitialize to run code before running each test
/// <summary>
/// Use TestInitialize to run code before running each test.
/// </summary>
[TestInitialize()]
public void MyTestInitialize() { }
public void TestInitialize()
{
environmentRepository = new EnvironmentRepository();
}

// Use TestCleanup to run code after each test has run
/// <summary>
/// Use TestCleanup to run code after each test has run.
/// </summary>
[TestCleanup()]
public void MyTestCleanup() { }
public void MyTestCleanup()
{
}

/// <summary>
/// Save a new Environment and then retreieve it.
/// </summary>
[TestMethod]
public void SaveAndRetrieve()
{

// Save a new Environment and then retrieve it using it's identifier.
Environment saved = DataFactory.CreateEnvironmentRequest();
Guid environmentId = (new EnvironmentRepository()).Save(saved);
Environment retrieved = (new EnvironmentRepository()).Retrieve(environmentId);
Guid environmentId = environmentRepository.Save(saved);
Environment retrieved = environmentRepository.Retrieve(environmentId);

// Assert that the retrieved Environment matches the saved Environment.
Assert.AreEqual(saved.Type, retrieved.Type);
Assert.AreEqual(saved.AuthenticationMethod, retrieved.AuthenticationMethod);
Assert.AreEqual(saved.ConsumerName, retrieved.ConsumerName);
Expand All @@ -61,24 +87,32 @@ public void SaveAndRetrieve()
Assert.AreEqual(saved.ApplicationInfo.DataModelNamespace, retrieved.ApplicationInfo.DataModelNamespace);
}

/// <summary>
/// Save a new Environment and then retreieve it using an example Environment instance.
/// </summary>
[TestMethod]
public void SaveAndRetrieveByExample()
{

// Save a new Environment.
Environment saved = DataFactory.CreateEnvironmentRequest();
Guid environmentId = (new EnvironmentRepository()).Save(saved);
ApplicationInfo applicationInfo = new ApplicationInfo
{
ApplicationKey = "UnitTesting", };
environmentRepository.Save(saved);

// Create an example Environment instance for use in the retrieve call.
ApplicationInfo applicationInfo = new ApplicationInfo { ApplicationKey = "UnitTesting" };
Environment example = new Environment
{
ApplicationInfo = applicationInfo,
InstanceId = "ThisInstance01",
SessionToken = "2e5dd3ca282fc8ddb3d08dcacc407e8a",
SolutionId = "auTestSolution",
UserToken = "UserToken01"
InstanceId = saved.InstanceId,
SessionToken = saved.SessionToken,
SolutionId = saved.SolutionId,
UserToken = saved.UserToken
};
IEnumerable<Environment> environments = (new EnvironmentRepository()).Retrieve(example);

// Retrieve Environments based on the example Environment instance.
IEnumerable<Environment> environments = environmentRepository.Retrieve(example);

// Assert that the retrieved Environments match properties of the example Environment instance.
foreach (Environment retrieved in environments)
{
Assert.AreEqual(saved.ApplicationInfo.ApplicationKey, retrieved.ApplicationInfo.ApplicationKey);
Expand All @@ -91,24 +125,19 @@ public void SaveAndRetrieveByExample()

}

/// <summary>
/// Save a new Environment and then retreieve it using its session token.
/// </summary>
[TestMethod]
public void SaveAndRetrieveBySessionToken()
{

// Save a new Environment and then retrieve it based on it's session token.
Environment saved = DataFactory.CreateEnvironmentRequest();
Guid environmentId = (new EnvironmentRepository()).Save(saved);
ApplicationInfo applicationInfo = new ApplicationInfo
{
ApplicationKey = "UnitTesting",
};
Environment example = new Environment
{
ApplicationInfo = applicationInfo,
InstanceId = "ThisInstance01",
SessionToken = "2e5dd3ca282fc8ddb3d08dcacc407e8a",
SolutionId = "auTestSolution",
UserToken = "UserToken01"
};
Environment retrieved = (new EnvironmentRepository()).RetrieveBySessionToken("2e5dd3ca282fc8ddb3d08dcacc407e8a");
environmentRepository.Save(saved);
Environment retrieved = environmentRepository.RetrieveBySessionToken(saved.SessionToken);

// Assert that the retrieved Environment matches the saved Environment.
Assert.AreEqual(saved.ApplicationInfo.ApplicationKey, retrieved.ApplicationInfo.ApplicationKey);
Assert.AreEqual(saved.InstanceId, retrieved.InstanceId);
Assert.AreEqual(saved.SessionToken, retrieved.SessionToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.1.0.0")]
[assembly: AssemblyFileVersion("3.1.0.0")]
[assembly: AssemblyVersion("3.2.0.0")]
[assembly: AssemblyFileVersion("3.2.0.0")]
Loading

0 comments on commit 58b3251

Please sign in to comment.