Exemplo n.º 1
0
        public void NewAzureSBNamespaceGetsDefaultLocation()
        {
            // Setup
            Mock <ServiceBusClientExtensions> client      = new Mock <ServiceBusClientExtensions>();
            MockCommandRuntime         mockCommandRuntime = new MockCommandRuntime();
            string                     name     = "test";
            string                     location = "West US";
            NewAzureSBNamespaceCommand cmdlet   = new NewAzureSBNamespaceCommand()
            {
                Name           = name,
                CommandRuntime = mockCommandRuntime,
                Client         = client.Object,
                Location       = location
            };
            ExtendedServiceBusNamespace expected = new ExtendedServiceBusNamespace {
                Name = name, Region = location
            };

            client.Setup(f => f.CreateNamespace(name, location)).Returns(expected);

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            ExtendedServiceBusNamespace actual = mockCommandRuntime.OutputPipeline[0] as ExtendedServiceBusNamespace;

            Assert.AreEqual <ExtendedServiceBusNamespace>(expected, actual);
        }
Exemplo n.º 2
0
        public void NewAzureSBNamespaceWithInternalServerError()
        {
            // Setup
            SimpleServiceBusManagement channel            = new SimpleServiceBusManagement();
            MockCommandRuntime         mockCommandRuntime = new MockCommandRuntime();
            string name     = "test";
            string location = "West US";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel)
            {
                Name = name, Location = location, CommandRuntime = mockCommandRuntime
            };

            channel.CreateServiceBusNamespaceThunk = csbns => { throw new Exception(Resources.InternalServerErrorMessage); };
            channel.ListServiceBusRegionsThunk     = lsbr =>
            {
                List <ServiceBusRegion> list = new List <ServiceBusRegion>();
                list.Add(new ServiceBusRegion {
                    Code = location
                });
                return(list);
            };
            string expected = Resources.NewNamespaceErrorMessage;

            Testing.AssertThrows <Exception>(() => cmdlet.ExecuteCmdlet(), expected);
        }
Exemplo n.º 3
0
        public void CreatesNewSBCaseInsensitiveRegion()
        {
            // Setup
            MockCommandRuntime mockCommandRuntime    = new MockCommandRuntime();
            Mock <ServiceBusClientExtensions> client = new Mock <ServiceBusClientExtensions>();
            string name     = "test";
            string location = "West US";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand()
            {
                Name           = name,
                Location       = location.ToLower(),
                CommandRuntime = mockCommandRuntime,
                Client         = client.Object
            };
            ExtendedServiceBusNamespace expected = new ExtendedServiceBusNamespace {
                Name = name, Region = location
            };

            client.Setup(f => f.CreateNamespace(name, location.ToLower())).Returns(expected);
            client.Setup(f => f.GetServiceBusRegions()).Returns(new List <ServiceBusLocation>()
            {
                new ServiceBusLocation()
                {
                    Code = location
                }
            });

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            ExtendedServiceBusNamespace actual = mockCommandRuntime.OutputPipeline[0] as ExtendedServiceBusNamespace;

            Assert.AreEqual <ExtendedServiceBusNamespace>(expected, actual);
        }
        public void CreatesNewSBCaseInsensitiveRegion()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            string location = "West US";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel)
            {
                Name = name,
                Location = "west Us",
                CommandRuntime = mockCommandRuntime
            };
            ServiceBusNamespace expected = new ServiceBusNamespace { Name = name, Region = location };
            channel.CreateServiceBusNamespaceThunk = csbn => { return expected; };
            channel.ListServiceBusRegionsThunk = lsbr =>
            {
                List<ServiceBusRegion> list = new List<ServiceBusRegion>();
                list.Add(new ServiceBusRegion { Code = location });
                return list;
            };

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            ServiceBusNamespace actual = mockCommandRuntime.OutputPipeline[0] as ServiceBusNamespace;
            Assert.AreEqual<ServiceBusNamespace>(expected, actual);
        }
Exemplo n.º 5
0
        public void NewAzureSBNamespaceSuccessfull()
        {
            // Setup
            SimpleServiceBusManagement channel            = new SimpleServiceBusManagement();
            MockCommandRuntime         mockCommandRuntime = new MockCommandRuntime();
            string name     = "test";
            string location = "West US";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel)
            {
                Name = name, Location = location, CommandRuntime = mockCommandRuntime
            };
            ServiceBusNamespace expected = new ServiceBusNamespace {
                Name = name, Region = location
            };

            channel.CreateServiceBusNamespaceThunk = csbn => { return(expected); };
            channel.ListServiceBusRegionsThunk     = lsbr =>
            {
                List <ServiceBusRegion> list = new List <ServiceBusRegion>();
                list.Add(new ServiceBusRegion {
                    Code = location
                });
                return(list);
            };

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            ServiceBusNamespace actual = mockCommandRuntime.OutputPipeline[0] as ServiceBusNamespace;

            Assert.AreEqual <ServiceBusNamespace>(expected, actual);
        }
        public void NewAzureSBNamespaceSuccessfull()
        {
            // Setup
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            Mock<ServiceBusClientExtensions> client = new Mock<ServiceBusClientExtensions>();
            string name = "test";
            string location = "West US";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand()
            {
                Name = name,
                Location = location,
                CommandRuntime = mockCommandRuntime,
                Client = client.Object
            };
            ExtendedServiceBusNamespace expected = new ExtendedServiceBusNamespace { Name = name, Region = location };
            client.Setup(f => f.CreateNamespace(name, location)).Returns(expected);
            client.Setup(f => f.GetServiceBusRegions()).Returns(new List<ServiceBusLocation>()
            {
                new ServiceBusLocation () { Code = location }
            });

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            ExtendedServiceBusNamespace actual = mockCommandRuntime.OutputPipeline[0] as ExtendedServiceBusNamespace;
            Assert.AreEqual<ExtendedServiceBusNamespace>(expected, actual);
        }
Exemplo n.º 7
0
        public void NewAzureSBNamespaceWithInvalidNamesFail()
        {
            // Setup
            string[] invalidNames = { "1test", "test#", "test invaid", "-test", "_test" };

            foreach (string invalidName in invalidNames)
            {
                MockCommandRuntime         mockCommandRuntime = new MockCommandRuntime();
                NewAzureSBNamespaceCommand cmdlet             = new NewAzureSBNamespaceCommand()
                {
                    Name = invalidName, Location = "West US", CommandRuntime = mockCommandRuntime
                };
                string expected = string.Format("{0}\r\nParameter name: Name", string.Format(Resources.InvalidNamespaceName, invalidName));

                Testing.AssertThrows <ArgumentException>(() => cmdlet.ExecuteCmdlet(), expected);
            }
        }
        public void NewAzureSBNamespaceWithInternalServerError()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            string location = "West US";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel) { Name = name, Location = location, CommandRuntime = mockCommandRuntime };
            channel.CreateServiceBusNamespaceThunk = csbns => { throw new Exception(Resources.InternalServerErrorMessage); };
            channel.ListServiceBusRegionsThunk = lsbr =>
            {
                List<ServiceBusRegion> list = new List<ServiceBusRegion>();
                list.Add(new ServiceBusRegion { Code = location });
                return list;
            };
            string expected = Resources.NewNamespaceErrorMessage;

            Testing.AssertThrows<Exception>(() => cmdlet.ExecuteCmdlet(), expected);
        }
        public void NewAzureSBNamespaceNoACSSuccessfull()
        {
            // Setup
            MockCommandRuntime mockCommandRuntime    = new MockCommandRuntime();
            Mock <ServiceBusClientExtensions> client = new Mock <ServiceBusClientExtensions>();
            string        name                = "test1";
            string        location            = "West US";
            NamespaceType type                = NamespaceType.NotificationHub;
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand()
            {
                Name               = name,
                Location           = location,
                CreateACSNamespace = false,
                NamespaceType      = type,
                CommandRuntime     = mockCommandRuntime,
                Client             = client.Object
            };
            ExtendedServiceBusNamespace expected = new ExtendedServiceBusNamespace {
                Name = name, Region = location, NamespaceType = type
            };

            client.Setup(f => f.CreateNamespace(name, location, type, false)).Returns(expected);
            client.Setup(f => f.GetServiceBusRegions()).Returns(new List <ServiceBusLocation>()
            {
                new ServiceBusLocation()
                {
                    Code = location
                }
            });

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            ExtendedServiceBusNamespace actual = mockCommandRuntime.OutputPipeline[0] as ExtendedServiceBusNamespace;

            Assert.Equal <ExtendedServiceBusNamespace>(expected, actual);
        }
Exemplo n.º 10
0
        public void NewAzureSBNamespaceWithInvalidNamesFail()
        {
            // Setup
            string[] invalidNames = { "1test", "test#", "test invaid", "-test", "_test" };
            Mock <ServiceBusClientExtensions> client = new Mock <ServiceBusClientExtensions>();

            foreach (string invalidName in invalidNames)
            {
                MockCommandRuntime         mockCommandRuntime = new MockCommandRuntime();
                NewAzureSBNamespaceCommand cmdlet             = new NewAzureSBNamespaceCommand()
                {
                    Name           = invalidName,
                    Location       = "West US",
                    CommandRuntime = mockCommandRuntime,
                    Client         = client.Object
                };

                string expected = string.Format("{0}\r\nParameter name: Name", string.Format(Resources.InvalidNamespaceName, invalidName));
                client.Setup(f => f.CreateNamespace(invalidName, "West US")).Throws(new InvalidOperationException(expected));

                Testing.AssertThrows <InvalidOperationException>(() => cmdlet.ExecuteCmdlet(), expected);
            }
        }
Exemplo n.º 11
0
        public void NewAzureSBNamespaceWithInvalidLocation()
        {
            // Setup
            SimpleServiceBusManagement channel            = new SimpleServiceBusManagement();
            MockCommandRuntime         mockCommandRuntime = new MockCommandRuntime();
            string name     = "test";
            string location = "Invalid location";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel)
            {
                Name = name, Location = location, CommandRuntime = mockCommandRuntime
            };

            channel.ListServiceBusRegionsThunk = lsbr =>
            {
                List <ServiceBusRegion> list = new List <ServiceBusRegion>();
                list.Add(new ServiceBusRegion {
                    Code = "West US"
                });
                return(list);
            };
            string expected = string.Format("{0}\r\nParameter name: Location", string.Format(Resources.InvalidServiceBusLocation, location));

            Testing.AssertThrows <ArgumentException>(() => cmdlet.ExecuteCmdlet(), expected);
        }
        public void NewAzureSBNamespaceSuccessfull()
        {
            // Setup
            SimpleServiceManagement channel = new SimpleServiceManagement();
            FakeWriter writer = new FakeWriter();
            string name = "test";
            string location = "West US";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel) { Name = name, Location = location, Writer = writer };
            ServiceBusNamespace expected = new ServiceBusNamespace { Name = name, Region = location };
            channel.CreateServiceBusNamespaceThunk = csbn => { return expected; };
            channel.ListServiceBusRegionsThunk = lsbr =>
            {
                List<ServiceBusRegion> list = new List<ServiceBusRegion>();
                list.Add(new ServiceBusRegion { Code = location });
                return list;
            };

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            ServiceBusNamespace actual = writer.OutputChannel[0] as ServiceBusNamespace;
            Assert.AreEqual<ServiceBusNamespace>(expected, actual);
        }
        public void NewAzureSBNamespaceWithInvalidNamesFail()
        {
            // Setup
            string[] invalidNames = { "1test", "test#", "test invaid", "-test", "_test" };

            foreach (string invalidName in invalidNames)
            {
                MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
                NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand() { Name = invalidName, Location = "West US", CommandRuntime = mockCommandRuntime };
                string expected = string.Format("{0}\r\nParameter name: Name", string.Format(Resources.InvalidNamespaceName, invalidName));

                Testing.AssertThrows<ArgumentException>(() => cmdlet.ExecuteCmdlet(), expected);
            }
        }
        public void NewAzureSBNamespaceWithInvalidLocation()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            string location = "Invalid location";
            NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel) { Name = name, Location = location, CommandRuntime = mockCommandRuntime };
            channel.ListServiceBusRegionsThunk = lsbr =>
            {
                List<ServiceBusRegion> list = new List<ServiceBusRegion>();
                list.Add(new ServiceBusRegion { Code = "West US" });
                return list;
            };
            string expected = string.Format("{0}\r\nParameter name: Location", string.Format(Resources.InvalidServiceBusLocation, location));

            Testing.AssertThrows<ArgumentException>(() => cmdlet.ExecuteCmdlet(), expected);
        }