public async Task LoopClansFromSpecificLocation(string locationName)
        {
            // Arrange
            var count    = 0;
            var location = _locations[locationName];
            var query    = new QueryClans
            {
                Limit      = 200,
                LocationId = location.Id
            };

            // Act
            do
            {
                var clans = (ClanList)await _coc.Clans.SearchClansAsync(query);

                foreach (var clan in clans)
                {
                    Assert.AreEqual(locationName, clan.Location?.Name);
                    Trace.WriteLine(clan.Dump());
                }

                count += clans.Count;
            } while (query.MoveToNextItems());

            // Assert
            Trace.WriteLine($"{locationName}: {count}");
            Assert.IsTrue(count != 0);
        }
Exemple #2
0
        public Task <QueryResult <ClanList> > SearchClansAsync(QueryClans query)
        {
            var request = new AutoValidatedRequest
            {
                QueryClans = query,
                Uri        = "/clans"
            };

            return(_gameData.QueryAsync <ClanList>(request));
        }
Exemple #3
0
        public void QueryClansWithLocationIdSet()
        {
            // Arrange
            var query = new QueryClans
            {
                LocationId = 42
            };

            // Act
            var queryString = query.ToString();

            // Assert
            Assert.AreEqual("?locationid=42", queryString);
        }
Exemple #4
0
        public void QueryClansWithWarFrequencySet()
        {
            // Arrange
            var query = new QueryClans
            {
                WarFrequency = WarFrequency.LessThanOncePerWeek
            };

            // Act
            var queryString = query.ToString();

            // Assert
            Assert.AreEqual("?warfrequency=lessThanOncePerWeek", queryString);
        }
        /// <summary>
        /// Search all clans by name and/or filtering the results using various criteria.
        /// </summary>
        public async Task SearchClans()
        {
            var query = new QueryClans
            {
                Name         = "Phoenix",
                MinMembers   = 40,
                MinClanLevel = 5,
                Limit        = 10
            };

            var coc   = new ClashOfClansClient(token);
            var clans = (ClanList)await coc.Clans.SearchClansAsync(query);

            foreach (var clan in clans)
            {
                Console.WriteLine($"{clan.Tag}/{clan.Name} has {clan.Members} members and is level {clan.ClanLevel} clan");
            }
        }
Exemple #6
0
        public void QueryClansWithLocationIdAndLimitSet()
        {
            // Arrange
            var query = new QueryClans
            {
                LocationId = 42,
                Limit      = 10
            };

            // Act
            var queryString = query.ToString();

            // Assert
            Assert.AreEqual('?', queryString[0]);
            Assert.IsTrue(queryString.Contains("&"));
            Assert.IsTrue(queryString.Contains("locationid=42"));
            Assert.IsTrue(queryString.Contains("limit=10"));
        }
        public async Task SearchClans()
        {
            // Arrange
            var limit = 10;
            var name  = "Phoenix";
            var query = new QueryClans
            {
                Name         = name,
                Limit        = limit,
                WarFrequency = WarFrequency.Never
            };

            // Act
            var searchResult = await _coc.Clans.SearchClansAsync(query);

            // Assert
            Assert.IsNotNull(searchResult);
            Assert.AreEqual(limit, searchResult.Items.Count);
            Assert.IsTrue(searchResult.Items.All(c => c.Name.Contains(name, StringComparison.OrdinalIgnoreCase)));
        }
        public async Task SearchClansWithQueryLimitProducesMovablePagingMarkers()
        {
            // Arrange
            var query = new QueryClans
            {
                MinMembers = 40,
                Limit      = 1
            };

            // Act / Assert
            await _coc.Clans.SearchClansAsync(query);

            Assert.IsFalse(query.MoveToPreviousItems(), "After initial query there should be no previous items!");
            Assert.IsTrue(query.MoveToNextItems());

            await _coc.Clans.SearchClansAsync(query);

            Assert.IsTrue(query.MoveToPreviousItems());
            Assert.IsTrue(query.MoveToNextItems());
        }
Exemple #9
0
        public void SetThreeCharactersLongName()
        {
            // Arrange
            var request = new AutoValidatedRequest();
            var query   = new QueryClans
            {
                Name = "abc"
            };

            try
            {
                // Act
                request.QueryClans = query;
            }
            catch (Exception)
            {
                // Assert
                Assert.Fail();
            }
        }
Exemple #10
0
        public void SetMultipleLabelIdsWithInvalidSeparatorThrows()
        {
            // Arrange
            var request = new AutoValidatedRequest();
            var query   = new QueryClans
            {
                LabelIds = "56000000, 56000001, 56000002"
            };

            try
            {
                // Act
                request.QueryClans = query;

                // Assert
                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                Trace.WriteLine(ex);
            }
        }
Exemple #11
0
        public void SetValidLabelIds()
        {
            // Arrange
            var request = new AutoValidatedRequest();
            var query   = new QueryClans
            {
                LabelIds = "56000000"
            };

            try
            {
                // Act
                request.QueryClans = query;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);

                // Assert
                Assert.Fail();
            }
        }
Exemple #12
0
        public void SetAfterAndBeforeForQueryClansThrows()
        {
            // Arrange
            var request = new AutoValidatedRequest();
            var query   = new QueryClans
            {
                After  = "after",
                Before = "before"
            };

            try
            {
                request.QueryClans = query;

                // Assert
                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                Trace.WriteLine(ex);
            }
        }
Exemple #13
0
        public void SetTooShortNameThrowsException()
        {
            // Arrange
            var request = new AutoValidatedRequest();
            var query   = new QueryClans
            {
                Name = "ab"
            };

            try
            {
                // Act
                request.QueryClans = query;

                // Assert
                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                Trace.WriteLine(ex);
            }
        }