public void Post_VirtualMachineHasNoName_ThrowsHttpException()
        {
            // Arrange
            var repository = MockRepository.GenerateStub<IVirtualMachineRepository>();
            var messenger = MockRepository.GenerateStub<IMessenger>();
            var controller = new VirtualMachinesController(repository, messenger);

            // Act

            // Assert
            Assert.That(() => controller.Post(new VirtualMachine()), Throws.InstanceOf<HttpException>());
        }
        public void Post_VirtualMachineAlreadyExists_ThrowsHttpException()
        {
            // Arrange
            var repository = MockRepository.GenerateMock<IVirtualMachineRepository>();
            repository.Expect(x => x.Read())
                .Repeat.Once()
                .Return(new EnumerableQuery<VirtualMachine>(new[] {new VirtualMachine {Name = "Machine"}}));

            var messenger = MockRepository.GenerateStub<IMessenger>();
            var controller = new VirtualMachinesController(repository, messenger);

            // Act
            var virtualMachine = new VirtualMachine
            {
                Name = "Machine",
                AdminPassword = "******",
                AdminUserName = "******",
                Location = "a;sdgh;",
                Size = AzureVirtualMachineSize.ExtraSmall,
                TimeZone = "kl;agh;"
            };

            // Assert
            Assert.That(() => controller.Post(virtualMachine), Throws.InstanceOf<HttpException>());
            repository.VerifyAllExpectations();
        }
        public void Post_ValidVirtualMachine_RepositoryIsCalled()
        {
            // Arrange
            var repository = MockRepository.GenerateMock<IVirtualMachineRepository>();
            repository.Expect(x => x.Read())
                .Repeat.Once()
                .Return(new EnumerableQuery<VirtualMachine>(Enumerable.Empty<VirtualMachine>()));
            repository.Expect(x => x.Create(Arg<VirtualMachine>.Is.TypeOf));

            var messenger = MockRepository.GenerateStub<IMessenger>();

            var controller = new VirtualMachinesController(repository, messenger);

            var virtualMachine = new VirtualMachine
            {
                Name = "Machine",
                AdminPassword = "******",
                AdminUserName = "******",
                Location = "a;sdgh;",
                Size = AzureVirtualMachineSize.ExtraSmall,
                TimeZone = "kl;agh;"
            };

            // Act
            controller.Post(virtualMachine);

            // Assert
            repository.VerifyAllExpectations();
        }
        public void Post_ValidVirtualMachine_ReturnsMachine()
        {
            // Arrange
            var repository = MockRepository.GenerateMock<IVirtualMachineRepository>();
            repository.Expect(x => x.Read())
                .Repeat.Once()
                .Return(new EnumerableQuery<VirtualMachine>(Enumerable.Empty<VirtualMachine>()));
            var messenger = MockRepository.GenerateStub<IMessenger>();
            var controller = new VirtualMachinesController(repository, messenger);

            // Act
            var virtualMachine = new VirtualMachine
            {
                Name = "Machine",
                AdminPassword = "******",
                AdminUserName = "******",
                Location = "a;sdgh;",
                Size = AzureVirtualMachineSize.ExtraSmall,
                TimeZone = "kl;agh;"
            };
            var result = controller.Post(virtualMachine);

            // Assert
            Assert.That(result.Name, Is.EqualTo("Machine"));
        }
        public void Post_InvalidVirtualMachine_RepositoryIsNotCalled()
        {
            // Arrange
            var repository = MockRepository.GenerateMock<IVirtualMachineRepository>();
            repository.Expect(x => x.Create(Arg<VirtualMachine>.Is.TypeOf))
                .Repeat.Never();

            var messenger = MockRepository.GenerateStub<IMessenger>();

            var controller = new VirtualMachinesController(repository, messenger);

            var machine = new VirtualMachine();

            // Act
            try
            {
                controller.Post(machine);
            }
            catch (HttpException) { }

            // Assert
            repository.VerifyAllExpectations();
        }