public void RoleInstanceReturnAnInstanceIdThatMatchesAnAzureInstanceId()
        {
            ServiceRuntime serviceRuntime = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);
            Assert.NotNull(roleEnvironment);

            RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;
            Assert.NotNull(roleInstance);

            string expectedId = string.Format(
                                    CultureInfo.InvariantCulture,
                                    TestRoleInstance.IdFormat,
                                    ServiceRuntimeHelper.RoleName,
                                    ServiceRuntimeHelper.RoleInstanceOrdinal);
            Assert.Equal(expectedId, roleInstance.Id);

            ServiceRuntimeHelper.RoleName = "MyTestRole_" + Guid.NewGuid().ToString("N");
            ServiceRuntimeHelper.RoleInstanceOrdinal = new Random().Next(0, 10);

            roleInstance = roleEnvironment.CurrentRoleInstance;
            Assert.NotNull(roleInstance);

            expectedId = string.Format(
                                    CultureInfo.InvariantCulture,
                                    TestRoleInstance.IdFormat,
                                    ServiceRuntimeHelper.RoleName,
                                    ServiceRuntimeHelper.RoleInstanceOrdinal);
            Assert.Equal(expectedId, roleInstance.Id);
        }
Ejemplo n.º 2
0
        public void RoleReturnsCorrectName()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);

            Assert.NotNull(roleEnvironment);

            RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;

            Assert.NotNull(roleInstance);

            Role role = roleInstance.Role;

            Assert.NotNull(role);

            Assert.Equal(ServiceRuntimeHelper.RoleName, role.Name);

            ServiceRuntimeHelper.RoleName = "MyTestRole_" + Guid.NewGuid().ToString("N");

            roleInstance = roleEnvironment.CurrentRoleInstance;
            Assert.NotNull(roleInstance);

            role = roleInstance.Role;
            Assert.NotNull(role);

            Assert.Equal(ServiceRuntimeHelper.RoleName, role.Name);
        }
        public void ServiceRuntimeProducesARoleEnvironmentObject()
        {
            ServiceRuntime serviceRuntime = new ServiceRuntime();

            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);
            Assert.NotNull(roleEnvironment);
        } 
Ejemplo n.º 4
0
        public void RoleInstanceReturnAnInstanceIdThatMatchesAnAzureInstanceId()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime(typeof(Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment).Assembly);
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment();

            Assert.NotNull(roleEnvironment);

            RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;

            Assert.NotNull(roleInstance);

            string expectedId = string.Format(
                CultureInfo.InvariantCulture,
                TestRoleInstance.IdFormat,
                ServiceRuntimeHelper.RoleName,
                ServiceRuntimeHelper.RoleInstanceOrdinal);

            Assert.Equal(expectedId, roleInstance.Id);

            ServiceRuntimeHelper.RoleName            = "MyTestRole_" + Guid.NewGuid().ToString("N");
            ServiceRuntimeHelper.RoleInstanceOrdinal = new Random().Next(0, 10);

            roleInstance = roleEnvironment.CurrentRoleInstance;
            Assert.NotNull(roleInstance);

            expectedId = string.Format(
                CultureInfo.InvariantCulture,
                TestRoleInstance.IdFormat,
                ServiceRuntimeHelper.RoleName,
                ServiceRuntimeHelper.RoleInstanceOrdinal);
            Assert.Equal(expectedId, roleInstance.Id);
        }
Ejemplo n.º 5
0
        public void RoleReturnsCorrectName()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime(typeof(Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment).Assembly);
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment();

            Assert.NotNull(roleEnvironment);

            RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;

            Assert.NotNull(roleInstance);

            Role role = roleInstance.Role;

            Assert.NotNull(role);

            Assert.Equal(ServiceRuntimeHelper.RoleName, role.Name);

            ServiceRuntimeHelper.RoleName = "MyTestRole_" + Guid.NewGuid().ToString("N");

            roleInstance = roleEnvironment.CurrentRoleInstance;
            Assert.NotNull(roleInstance);

            role = roleInstance.Role;
            Assert.NotNull(role);

            Assert.Equal(ServiceRuntimeHelper.RoleName, role.Name);
        }
        public virtual bool ReadAndPopulateContextInformation(out string roleName, out string roleInstanceId)
        {
            roleName       = string.Empty;
            roleInstanceId = string.Empty;

            Assembly loadedAssembly = null;

            try
            {
                // As this is executed inside a separate AppDomain, it is safe to load assemblies here without interfering with user code.
                loadedAssembly = AttemptToLoadAssembly(this.AssemblyNameToLoad, this.VersionsToAttempt);
                if (loadedAssembly != null)
                {
                    ServiceRuntime  serviceRuntime  = new ServiceRuntime(loadedAssembly);
                    RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment();

                    if (roleEnvironment.IsAvailable == true)
                    {
                        RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;
                        if (roleInstance != null)
                        {
                            roleInstanceId = roleInstance.Id;
                            Role role = roleInstance.Role;
                            roleName = role.Name;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WindowsServerEventSource.Log.UnknownErrorOccured("AzureServiceRuntimeAssemblyLoader populate context", ex.ToString());
            }

            return(loadedAssembly != null);
        }
 public void RoleEnvironmentIsAvailableReturnsFalseIfServiceRuntimeDoesntExit()
 {
     ServiceRuntime serviceRuntime = new ServiceRuntime();
     RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);
     roleEnvironment.TargetType = null;
     Assert.NotNull(roleEnvironment);
     Assert.False(roleEnvironment.IsAvailable);
 }
Ejemplo n.º 8
0
        public void ServiceRuntimeProducesARoleEnvironmentObject()
        {
            ServiceRuntime serviceRuntime = new ServiceRuntime(typeof(Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment).Assembly);

            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment();

            Assert.NotNull(roleEnvironment);
        }
Ejemplo n.º 9
0
        public void ServiceRuntimeProducesARoleEnvironmentObject()
        {
            ServiceRuntime serviceRuntime = new ServiceRuntime();

            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);

            Assert.NotNull(roleEnvironment);
        }
Ejemplo n.º 10
0
        public void RoleEnvironmentIsAvailableReturnsFalseIfServiceRuntimeDoesntExit()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime(typeof(Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment).Assembly);
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment();

            roleEnvironment.TargetType = null;
            Assert.NotNull(roleEnvironment);
            Assert.False(roleEnvironment.IsAvailable);
        }
        public void RoleEnvironmentReturnsTheCurrentRoleInstanceWhichIsNotNull()
        {
            ServiceRuntime serviceRuntime = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);
            Assert.NotNull(roleEnvironment);

            RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;
            Assert.NotNull(roleInstance);
        }
Ejemplo n.º 12
0
        public void RoleEnvironmentIsAvailableReturnsFalseIfServiceRuntimeDoesntExit()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);

            roleEnvironment.TargetType = null;
            Assert.NotNull(roleEnvironment);
            Assert.False(roleEnvironment.IsAvailable);
        }
Ejemplo n.º 13
0
        public void RoleEnvironmentReturnsTheCurrentRoleInstanceWhichIsNotNull()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);

            Assert.NotNull(roleEnvironment);

            RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;

            Assert.NotNull(roleInstance);
        }
Ejemplo n.º 14
0
        public void RoleEnvironmentReturnsTheCurrentRoleInstanceWhichIsNotNull()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime(typeof(Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment).Assembly);
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment();

            Assert.NotNull(roleEnvironment);

            RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;

            Assert.NotNull(roleInstance);
        }
        public void RoleEnvironmentReturnsCorrectAvailabilityState()
        {
            ServiceRuntime serviceRuntime = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);
            Assert.NotNull(roleEnvironment);

            Assert.Equal(ServiceRuntimeHelper.IsAvailable, roleEnvironment.IsAvailable);

            ServiceRuntimeHelper.IsAvailable = !ServiceRuntimeHelper.IsAvailable;

            Assert.Equal(ServiceRuntimeHelper.IsAvailable, roleEnvironment.IsAvailable);
        }
        public void RoleEnvironmentReturnsCorrectDeploymentId()
        {
            ServiceRuntime serviceRuntime = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);
            Assert.NotNull(roleEnvironment);

            Assert.Equal(ServiceRuntimeHelper.DeploymentId, roleEnvironment.DeploymentId);

            ServiceRuntimeHelper.DeploymentId = Guid.NewGuid().ToString("N");

            Assert.Equal(ServiceRuntimeHelper.DeploymentId, roleEnvironment.DeploymentId);
        }
Ejemplo n.º 17
0
        public void RoleEnvironmentReturnsCorrectAvailabilityState()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);

            Assert.NotNull(roleEnvironment);

            Assert.Equal(ServiceRuntimeHelper.IsAvailable, roleEnvironment.IsAvailable);

            ServiceRuntimeHelper.IsAvailable = !ServiceRuntimeHelper.IsAvailable;

            Assert.Equal(ServiceRuntimeHelper.IsAvailable, roleEnvironment.IsAvailable);
        }
Ejemplo n.º 18
0
        public void RoleEnvironmentReturnsCorrectDeploymentId()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);

            Assert.NotNull(roleEnvironment);

            Assert.Equal(ServiceRuntimeHelper.DeploymentId, roleEnvironment.DeploymentId);

            ServiceRuntimeHelper.DeploymentId = Guid.NewGuid().ToString("N");

            Assert.Equal(ServiceRuntimeHelper.DeploymentId, roleEnvironment.DeploymentId);
        }
Ejemplo n.º 19
0
        public void RoleEnvironmentReturnsCorrectDeploymentId()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime(typeof(Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment).Assembly);
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment();

            Assert.NotNull(roleEnvironment);

            Assert.Equal(ServiceRuntimeHelper.DeploymentId, roleEnvironment.DeploymentId);

            ServiceRuntimeHelper.DeploymentId = Guid.NewGuid().ToString("N");

            Assert.Equal(ServiceRuntimeHelper.DeploymentId, roleEnvironment.DeploymentId);
        }
Ejemplo n.º 20
0
        public void RoleEnvironmentReturnsCorrectAvailabilityState()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime(typeof(Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment).Assembly);
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment();

            Assert.NotNull(roleEnvironment);

            Assert.Equal(ServiceRuntimeHelper.IsAvailable, roleEnvironment.IsAvailable);

            ServiceRuntimeHelper.IsAvailable = !ServiceRuntimeHelper.IsAvailable;

            Assert.Equal(ServiceRuntimeHelper.IsAvailable, roleEnvironment.IsAvailable);
        }
        /// <summary>
        /// Initializes the current reader with respect to its environment.
        /// </summary>
        public void Initialize()
        {
            ServiceRuntime  serviceRuntime  = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(AzureRoleEnvironmentContextReader.BaseDirectory);

            if (roleEnvironment.IsAvailable == true)
            {
                RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;
                if (roleInstance != null)
                {
                    this.roleInstanceName = roleEnvironment.CurrentRoleInstance.Id;
                    Role role = roleInstance.Role;
                    if (role != null)
                    {
                        this.roleName = role.Name;
                    }
                }
            }
        }
        /// <summary>
        /// Initializes the current reader with respect to its environment.
        /// </summary>
        public void Initialize()
        {
            ServiceRuntime serviceRuntime = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(AzureRoleEnvironmentContextReader.BaseDirectory);

            if (roleEnvironment.IsAvailable == true)
            {
                RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;
                if (roleInstance != null)
                {
                    this.roleInstanceName = roleEnvironment.CurrentRoleInstance.Id;
                    Role role = roleInstance.Role;
                    if (role != null)
                    {
                        this.roleName = role.Name;
                    }
                }
            }
        }
        public void RoleReturnsCorrectName()
        {
            ServiceRuntime serviceRuntime = new ServiceRuntime();
            RoleEnvironment roleEnvironment = serviceRuntime.GetRoleEnvironment(ServiceRuntimeHelper.TestWithServiceRuntimePath);
            Assert.NotNull(roleEnvironment);

            RoleInstance roleInstance = roleEnvironment.CurrentRoleInstance;
            Assert.NotNull(roleInstance);

            Role role = roleInstance.Role;
            Assert.NotNull(role);

            Assert.Equal(ServiceRuntimeHelper.RoleName, role.Name);

            ServiceRuntimeHelper.RoleName = "MyTestRole_" + Guid.NewGuid().ToString("N");

            roleInstance = roleEnvironment.CurrentRoleInstance;
            Assert.NotNull(roleInstance);

            role = roleInstance.Role;
            Assert.NotNull(role);

            Assert.Equal(ServiceRuntimeHelper.RoleName, role.Name);
        }