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);
        }
Ejemplo n.º 2
0
 public void SetupTest()
 {
     channel = new SimpleServiceManagement();
     serviceBusChannel = new SimpleServiceBusManagement();
     mockCommandRuntime = new MockCommandRuntime();
     cmdlet = new TestAzureNameCommand(channel, serviceBusChannel) { CommandRuntime = mockCommandRuntime };
     CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
 }
        public void RemoveAzureSBNamespaceWithInternalServerError()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            RemoveAzureSBNamespaceCommand cmdlet = new RemoveAzureSBNamespaceCommand(channel) { Name = name, CommandRuntime = mockCommandRuntime };
            string expected = Resources.RemoveNamespaceErrorMessage;
            channel.DeleteServiceBusNamespaceThunk = dsbn => { throw new Exception(Resources.InternalServerErrorMessage); };

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            ErrorRecord actual = mockCommandRuntime.ErrorStream[0];
            Assert.AreEqual<string>(expected, actual.Exception.Message);
        }
        public void RemoveAzureSBNamespaceSuccessfull()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            RemoveAzureSBNamespaceCommand cmdlet = new RemoveAzureSBNamespaceCommand(channel) { Name = name, CommandRuntime = mockCommandRuntime, PassThru = true };
            bool deleted = false;
            channel.DeleteServiceBusNamespaceThunk = dsbn => { deleted = true; };

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            Assert.IsTrue(deleted);
            Assert.IsTrue((bool)mockCommandRuntime.OutputPipeline[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 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 GetAzureSBLocationSuccessfull()
        {
            // Setup
            SimpleServiceBusManagement channel = new SimpleServiceBusManagement();
            MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
            string name = "test";
            GetAzureSBLocationCommand cmdlet = new GetAzureSBLocationCommand(channel) { CommandRuntime = mockCommandRuntime };
            List<ServiceBusRegion> expected = new List<ServiceBusRegion>();
            expected.Add(new ServiceBusRegion { Code = name, FullName = name });
            channel.ListServiceBusRegionsThunk = gn => { return expected; };

            // Test
            cmdlet.ExecuteCmdlet();

            // Assert
            List<ServiceBusRegion> actual = mockCommandRuntime.OutputPipeline[0] as List<ServiceBusRegion>;
            Assert.AreEqual<int>(expected.Count, actual.Count);

            for (int i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual<string>(expected[i].Code, actual[i].Code);
                Assert.AreEqual<string>(expected[i].FullName, actual[i].FullName);
            }
        }
 public void SetupTest()
 {
     CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
     new FileSystemHelper(this).CreateAzureSdkDirectoryAndImportPublishSettings();
     channel = new SimpleServiceBusManagement();
     mockCommandRuntime = new MockCommandRuntime();
     cmdlet = new GetAzureSBNamespaceCommand(channel) { CommandRuntime = mockCommandRuntime };
 }