protected void Arrange() { _serviceFactoryMock = new Mock <IServiceFactory>(MockBehavior.Strict); _sessionMock = new Mock <ISession>(MockBehavior.Strict); _netConfSessionMock = new Mock <INetConfSession>(MockBehavior.Strict); _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); _operationTimeout = new Random().Next(1000, 10000); _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); _netConfClient.OperationTimeout = TimeSpan.FromMilliseconds(_operationTimeout); var sequence = new MockSequence(); _serviceFactoryMock.InSequence(sequence) .Setup(p => p.CreateSession(_connectionInfo)) .Returns(_sessionMock.Object); _sessionMock.InSequence(sequence).Setup(p => p.Connect()); _serviceFactoryMock.InSequence(sequence) .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _operationTimeout)) .Returns(_netConfSessionMock.Object); _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); _netConfSessionMock.InSequence(sequence).Setup(p => p.Dispose()); _netConfClient.Connect(); _netConfClient.Disconnect(); }
protected void Arrange() { _serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Loose); _sessionMock = new Mock<ISession>(MockBehavior.Loose); _netConfSessionMock = new Mock<INetConfSession>(MockBehavior.Loose); _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); var sequence = new MockSequence(); _serviceFactoryMock.InSequence(sequence) .Setup(p => p.CreateSession(_connectionInfo)) .Returns(_sessionMock.Object); _sessionMock.InSequence(sequence).Setup(p => p.Connect()); _serviceFactoryMock.InSequence(sequence) .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout)) .Returns(_netConfSessionMock.Object); _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); _netConfClient.Connect(); _netConfClient = null; // we need to dereference all other mocks as they might otherwise hold the target alive _sessionMock = null; _connectionInfo = null; _serviceFactoryMock = null; }
protected void Arrange() { _serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict); _sessionMock = new Mock<ISession>(MockBehavior.Strict); _netConfSessionMock = new Mock<INetConfSession>(MockBehavior.Strict); _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); var sequence = new MockSequence(); _serviceFactoryMock.InSequence(sequence) .Setup(p => p.CreateSession(_connectionInfo)) .Returns(_sessionMock.Object); _sessionMock.InSequence(sequence).Setup(p => p.Connect()); _serviceFactoryMock.InSequence(sequence) .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout)) .Returns(_netConfSessionMock.Object); _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); _netConfSessionMock.InSequence(sequence).Setup(p => p.Dispose()); _netConfClient.Connect(); _netConfClient.Dispose(); }
protected override void Arrange() { base.Arrange(); _netConfClient.Connect(); _netConfClient.Disconnect(); }
protected void Arrange() { _serviceFactoryMock = new Mock <IServiceFactory>(MockBehavior.Loose); _sessionMock = new Mock <ISession>(MockBehavior.Loose); _netConfSessionMock = new Mock <INetConfSession>(MockBehavior.Loose); _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); var sequence = new MockSequence(); _serviceFactoryMock.InSequence(sequence) .Setup(p => p.CreateSession(_connectionInfo)) .Returns(_sessionMock.Object); _sessionMock.InSequence(sequence).Setup(p => p.Connect()); _serviceFactoryMock.InSequence(sequence) .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout)) .Returns(_netConfSessionMock.Object); _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); _netConfClient.Connect(); _netConfClient = null; // we need to dereference all other mocks as they might otherwise hold the target alive _sessionMock = null; _connectionInfo = null; _serviceFactoryMock = null; }
protected override void Arrange() { base.Arrange(); _netConfClient.Connect(); _netConfClient = null; // We need to dereference all mocks as they might otherwise hold the target alive //(through recorded invocations?) CreateMocks(); }
protected override void Act() { try { _netConfClient.Connect(); Assert.Fail(); } catch (ApplicationException ex) { _actualException = ex; } }
public void Load(string host, int port, string user, string password) { using (var client = new NetConfClient(host, port, user, password)) { client.AutomaticMessageIdHandling = false; client.OperationTimeout = new TimeSpan(0, 0, 60); client.Connect(); var nsManager = Ns.CreateManager(); var rpc = new XmlDocument(); // // Security Zones rpc.LoadXml("<rpc><get-config><source><running /></source><filter>" + FilterSecurityZones + "</filter></get-config></rpc>"); XmlDocument result = client.SendReceiveRpc(rpc); XDocument xmlZones = XDocument.Parse(result.OuterXml); this.Zones = xmlZones.Root.XPathSelectElements("./nc:data/xnm:configuration/xnm:security/xnm:zones/xnm:security-zone", nsManager).Select(SecurityZone.Parse).ToList(); // // Security Policy Groups rpc.LoadXml("<rpc><get-config><source><running /></source><filter>" + FilterGroups + "</filter></get-config></rpc>"); result = client.SendReceiveRpc(rpc); XDocument xmlGroups = XDocument.Parse(result.OuterXml); this.Groups = xmlGroups.Root.Descendants(Ns.Xnm + "groups") .Where(x => x.Descendants(Ns.Xnm + "security").SelectMany(y => y.Descendants(Ns.Xnm + "policies")).Any()) .Select(SecurityPoliciesGroup.Parse) .ToList(); // // Security Policies rpc.LoadXml("<rpc><get-config><source><running /></source><filter>" + FilterSecurityPolicies + "</filter></get-config></rpc>"); result = client.SendReceiveRpc(rpc); XDocument xmlPolicies = XDocument.Parse(result.OuterXml); this.Policies = xmlPolicies.Root.XPathSelectElements("./nc:data/xnm:configuration/xnm:security/xnm:policies/xnm:policy", nsManager) .Select(xml => SecurityPolicyContainer.Parse(xml, s => this.Groups.FirstOrDefault(g => g.Name == s) ?? new SecurityPoliciesGroup { Name = s })).ToList(); // Close client.SendCloseRpc(); } }