public void Ctor_MerakiDashboardClientSettings_Null_BaseAddress() { MerakiDashboardClientOptions merakiDashboardClientSettings = new MerakiDashboardClientOptions { BaseAddress = null, ApiKey = "apiKey" }; Assert.Throws <ArgumentNullException>("baseAddress", () => new MerakiDashboardClient(merakiDashboardClientSettings)); }
public void Ctor_MerakiDashboardClientSettings_Null_ApiKey(string apiKey) { MerakiDashboardClientOptions merakiDashboardClientSettings = new MerakiDashboardClientOptions { BaseAddress = new Uri("http://www.myserver.com"), ApiKey = apiKey }; Assert.Throws <ArgumentException>("apiKey", () => new MerakiDashboardClient(merakiDashboardClientSettings)); }
public void Ctor_MerakiDashboardClientSettings() { Uri baseAddress = new Uri("http://www.myserver.com"); const string apiKey = "000111222333444555666777888999000aaabbbbcccdddeee"; MerakiDashboardClientOptions merakiDashboardClientSettings = new MerakiDashboardClientOptions { BaseAddress = baseAddress, ApiKey = apiKey }; using (MerakiDashboardClient merakiDashboardClient = new MerakiDashboardClient(merakiDashboardClientSettings)) { Assert.Equal(baseAddress, merakiDashboardClient.Client.BaseAddress); Assert.Equal(apiKey, merakiDashboardClient.Client.ApiKey); } }
public async void TestMocking() { Organization organization = new Organization { Name = "White house", Id = "Org Id" }; Network network = new Network { Id = "Network Id", Name = "White House Network", NetworkType = "Wireless", OrganizationId = organization.Id, Tags = "tags", TimeZone = "UTC-06:00" }; Device device = new Device { Address = "1600 Pennsylania Ave Washington DC", LanIpAddress = new IPAddress(new byte[] { 127, 0, 0, 1 }), Lattitude = 38.8977, Longitude = 77.0365, Mac = "00:00:00:00:00:00", Model = "MR33", Name = "Presidential AP", NetworkId = network.Id, Serial = "AAAA-BBBB-CCCC", Tags = "Tags" }; DeviceClient dclient = new DeviceClient { Id = Guid.NewGuid().ToString(), Description = "description", IPAddress = "127.0.0.1", MacAddress = "80:c5:f2:79:be:e1", MDnsName = "Test", DhcpHostName = "Test", SwitchPort = null, User = "******", VLan = "10" }; MerakiDashboardClientOptions merakiDashboardClientSettings = new MerakiDashboardClientOptions { ApiKey = "api key", BaseAddress = new Uri("http://myapi.com") }; Mock <MerakiDashboardClient> merakiDashboardlientMock = new Mock <MerakiDashboardClient>(MockBehavior.Strict, merakiDashboardClientSettings); merakiDashboardlientMock.Setup(merakiDashboardClient => merakiDashboardClient.GetOrganizationsAsync()) .Returns(Task.FromResult(new[] { organization })); merakiDashboardlientMock.Setup(merakiDashboardClient => merakiDashboardClient.GetOrganizationNetworksAsync(organization)) .Returns(Task.FromResult(new[] { network })); merakiDashboardlientMock.Setup(merakiDashboardClient => merakiDashboardClient.GetNetworkDevicesAsync(network)) .Returns(Task.FromResult(new[] { device })); merakiDashboardlientMock.Setup(merakiDashboardClient => merakiDashboardClient.GetDeviceClientsAsync(device.Serial, new TimeSpan(24, 0, 0))) .Returns(Task.FromResult(new[] { dclient })); // Required by mocking framework merakiDashboardlientMock.Protected().Setup("Dispose", true); using (MerakiDashboardClient merakiDashboardClient = merakiDashboardlientMock.Object) { Assert.Equal(new[] { device }, await GetDevicesInAnOrganization(merakiDashboardClient)); var deviceClients = await merakiDashboardClient.GetDeviceClientsAsync(device.Serial, new TimeSpan(24, 0, 0)); Assert.NotNull(deviceClients); Assert.Single(deviceClients); Assert.Equal(dclient.MacAddress, deviceClients.Single().MacAddress); } merakiDashboardlientMock.VerifyAll(); }