private static Mock <Host> GetAMockHost(string productVersion, string buildNumber, List <Pool_patch> applied_patches = null) { var id = System.Guid.NewGuid().ToString(); MockObjectManager mom = new MockObjectManager(); mom.CreateNewConnection(id); Mock <Host> master = mom.NewXenObject <Host>(id); Mock <Pool> pool = mom.NewXenObject <Pool>(id); XenRef <Host> masterRef = new XenRef <Host>("master-ref"); pool.Setup(p => p.master).Returns(masterRef); mom.MockCacheFor(id).Setup(c => c.Resolve(It.IsAny <XenRef <Pool> >())).Returns(pool.Object); mom.MockConnectionFor(id).Setup(c => c.Resolve(masterRef)).Returns(master.Object); mom.MockConnectionFor(id).Setup(c => c.Cache.Hosts).Returns(new Host[] { master.Object }); mom.MockConnectionFor(id).Setup(c => c.Cache.Pools).Returns(new Pool[] { pool.Object }); master.Setup(h => h.software_version).Returns(new Dictionary <string, string>()); master.Setup(h => h.ProductVersion()).Returns(productVersion); master.Setup(h => h.AppliedPatches()).Returns(applied_patches ?? new List <Pool_patch>()); master.Setup(h => h.BuildNumberRaw()).Returns(buildNumber); master.Setup(h => h.uuid).Returns(id); return(master); }
private void SetupMocks(List <XenServerPatch> xenServerPatches, List <XenServerVersion> xenServerVersions) { Mock <Host> master = mom.NewXenObject <Host>(id); Mock <Pool> pool = mom.NewXenObject <Pool>(id); XenRef <Host> masterRef = new XenRef <Host>("ref"); pool.Setup(p => p.master).Returns(masterRef); mom.MockCacheFor(id).Setup(c => c.Resolve(It.IsAny <XenRef <Pool> >())).Returns(pool.Object); mom.MockConnectionFor(id).Setup(c => c.Resolve(masterRef)).Returns(master.Object); master.Setup(h => h.software_version).Returns(new Dictionary <string, string>()); master.Setup(h => h.ProductVersion).Returns(ServerVersion); master.Setup(h => h.AppliedPatches()).Returns(GenerateMockPoolPatches(xenServerPatches)); //Currently build number will be referenced first so if it's present hook it up string buildNumber = xenServerVersions.First(v => v.Version.ToString() == ServerVersion).BuildNumber; master.Setup(h => h.BuildNumberRaw).Returns(buildNumber); }
private static Mock<Host> GetAMockHost(string productVersion, string buildNumber, List<Pool_patch> applied_patches = null) { var id = System.Guid.NewGuid().ToString(); MockObjectManager mom = new MockObjectManager(); mom.CreateNewConnection(id); Mock<Host> master = mom.NewXenObject<Host>(id); Mock<Pool> pool = mom.NewXenObject<Pool>(id); XenRef<Host> masterRef = new XenRef<Host>("master-ref"); pool.Setup(p => p.master).Returns(masterRef); mom.MockCacheFor(id).Setup(c => c.Resolve(It.IsAny<XenRef<Pool>>())).Returns(pool.Object); mom.MockConnectionFor(id).Setup(c => c.Resolve(masterRef)).Returns(master.Object); mom.MockConnectionFor(id).Setup(c => c.Cache.Hosts).Returns(new Host[] { master.Object }); mom.MockConnectionFor(id).Setup(c => c.Cache.Pools).Returns(new Pool[] { pool.Object }); master.Setup(h => h.software_version).Returns(new Dictionary<string, string>()); master.Setup(h => h.ProductVersion).Returns(productVersion); master.Setup(h => h.AppliedPatches()).Returns(applied_patches ?? new List<Pool_patch>()); master.Setup(h => h.BuildNumberRaw).Returns(buildNumber); master.Setup(h => h.uuid).Returns(id); return master; }