~cbehrens/openstack-guest-agents/lp764221

« back to all changes in this revision

Viewing changes to src/xenserver/windows/src/Rackspace.Cloud.Server.Agent.Specs/AgentUpdateSpec.cs

  • Committer: Antony Messerli
  • Date: 2011-03-02 21:56:51 UTC
  • Revision ID: amesserl@rackspace.com-20110302215651-0clqh49spumg13c6
Initial commit Rackspace Windows Guest Agent

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using NUnit.Framework;
 
2
using NUnit.Framework.SyntaxHelpers;
 
3
using Rackspace.Cloud.Server.Agent.Actions;
 
4
using Rackspace.Cloud.Server.Agent.Commands;
 
5
using Rackspace.Cloud.Server.Agent.Configuration;
 
6
using Rackspace.Cloud.Server.Agent.Interfaces;
 
7
using Rackspace.Cloud.Server.Common.AgentUpdate;
 
8
using Rackspace.Cloud.Server.Common.Logging;
 
9
using Rhino.Mocks;
 
10
 
 
11
namespace Rackspace.Cloud.Server.Agent.Specs {
 
12
    [TestFixture]
 
13
    public class AgentUpdateSpec {
 
14
        private IAgentUpdateMessageSender _agentUpdateMessageSender;
 
15
        private AgentUpdate _agentUpdate;
 
16
        private string _agentUpdateInfo;
 
17
        private IConnectionChecker _connectionChecker;
 
18
        private ILogger _logger;
 
19
 
 
20
        [SetUp]
 
21
        public void Setup()
 
22
        {
 
23
            _agentUpdateInfo = "http://something.com/file.zip,544564abc453de787ad";
 
24
 
 
25
            _agentUpdateMessageSender = MockRepository.GenerateMock<IAgentUpdateMessageSender>();
 
26
            _connectionChecker = MockRepository.GenerateMock<IConnectionChecker>();
 
27
            _logger = MockRepository.GenerateMock<ILogger>();
 
28
 
 
29
            _connectionChecker.Stub(x => x.Check());
 
30
 
 
31
            _agentUpdate = new AgentUpdate(_agentUpdateMessageSender, _connectionChecker, new AgentUpdateMessageHandler(), _logger);
 
32
 
 
33
            _agentUpdate.Execute(_agentUpdateInfo);
 
34
        }
 
35
 
 
36
        [Test]
 
37
        public void should_send_a_message_to_the_updater_using_remoting()
 
38
        {
 
39
            _agentUpdateMessageSender.AssertWasCalled(x=>x.Send(Arg<AgentUpdateInfo>.Is.Anything));
 
40
        }
 
41
 
 
42
        [Test]
 
43
        public void should_throw_UnsuccessfulCommandExecutionException_if_connection_to_updater_service_fails() {
 
44
            _agentUpdateMessageSender.Stub(x => x.Send(Arg<AgentUpdateInfo>.Is.Anything))
 
45
                .Throw(new UnsuccessfulCommandExecutionException("error message", new ExecutableResult {ExitCode = "1"}));
 
46
            var result = _agentUpdate.Execute(_agentUpdateInfo);
 
47
            Assert.That(result.ExitCode, Is.EqualTo("1"));
 
48
            Assert.That(result.Error[0], Is.EqualTo("Update failed"));
 
49
        }
 
50
    }
 
51
}