示例#1
0
        public void Live_Push_Monitoring()
        {
            // Arrange
            Random.Org.Random rand = new Random.Org.Random();
            var widgetKey          = MONITORING_WIDGETKEY; // replace this value with your own
            var obj = new GeckoMonitoring()
            {
                Status       = rand.Next(1, 2) % 2 == 1 ? MonitoringStatus.Up : MonitoringStatus.Down,
                Downtime     = DateTime.Now.AddDays(rand.Next(1, 60)).Humanize(),
                ResponseTime = string.Format("{0} ms", rand.Next(1, 1000))
            };

            var push = new PushPayload <GeckoMonitoring>()
            {
                ApiKey = _apiKey,
                Data   = obj
            };
            var client = new GeckoConnect();

            // Act
            Assert.AreNotEqual("<api key here>", _apiKey);
            Assert.AreNotEqual("<widget key here>", widgetKey);
            var result = client.Push <GeckoMonitoring>(push, widgetKey);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Success);
            Assert.IsTrue(string.IsNullOrWhiteSpace(result.Message));
        }
示例#2
0
文件: BlackJack.cs 项目: borgej/YTBot
        // Procedure to shuffle the deck of cards
        static void shuffleDeck(ref PlayingCard[] deck)
        {
            Random.Org.Random rnd = new Random.Org.Random(); // Creates new Random object
            PlayingCard       temp;                          // Creates a variable for temporarily storing a PlayingCard
            int num;                                         // Creates an integer variable for storing the randomly generated numbers

            for (int i = 0; i < deck.Length; i++)            // Loop through each index in the array
            {
                num = rnd.Next(0, deck.Length);              // Generate random num between 0 & 51

                // Swap the contents of deck[i] and deck[num]
                temp      = deck[i];
                deck[i]   = deck[num];
                deck[num] = temp;
            }

            // As deck is passed by reference, we do not need to return it to the main program
            // The changes will have automatically been applied to the deck in the main program
        }
示例#3
0
        // POST api/<controller>
        public HttpResponseMessage Post(RandomizeModel model)
        {
            Random.Org.Random r = new Random.Org.Random();
            #if DEBUG || TEST
            r.UseLocalMode = false;
            #endif
            string[] value = model.list.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            List<List<string>> lists = new List<List<string>>();

            int listContainerSize = (int)Math.Round((double)value.Length / model.numLists);
            if (listContainerSize == 0)
                throw new InvalidOperationException("You cannot have more lists than items");

            for (int i = 0; i < model.numLists; i++)
            {
                lists.Add(new List<string>());
            }

            ShuffleList(r, value);
            SplitList(value, lists, listContainerSize);

            return ControllerContext.Request.CreateResponse<IEnumerable<IEnumerable<string>>>(HttpStatusCode.OK, lists);
        }
示例#4
0
        public void Live_Push_Monitoring()
        {
            // Arrange
            Random.Org.Random rand = new Random.Org.Random();
            var widgetKey = "<widget key here>";        // replace this value with your own
            var obj = new GeckoMonitoring()
            {
                Status = rand.Next(1, 2) % 2 == 1 ? MonitoringStatus.Up : MonitoringStatus.Down,
                Downtime = DateTime.Now.AddDays(rand.Next(1, 60)).Humanize(),
                ResponseTime = string.Format("{0} ms", rand.Next(1, 1000))
            };

            var push = new PushPayload<GeckoMonitoring>()
            {
                ApiKey = this.apiKey,
                Data = obj
            };
            var client = new GeckoConnect();

            // Act
            Assert.AreNotEqual("<api key here>", this.apiKey);
            Assert.AreNotEqual("<widget key here>", widgetKey);
            var result = client.Push<GeckoMonitoring>(push, widgetKey);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Success);
            Assert.IsTrue(string.IsNullOrWhiteSpace(result.Message));
        }