Beispiel #1
0
        public async Task ShouldGetElementWithHighestWeight()
        {
            // Arrange
            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($items:[String!]!, $weights:[Float!]!) {
  random {
    weighted(items:$items, weights:$weights)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    Items,
                    Weights
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().BeNull();
            var random = ParseResponse(response);

            random.Weighted.Should().Be("three");
        }
Beispiel #2
0
        public async Task ShouldFailWithoutWeights()
        {
            // Arrange
            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($items:[String!]!) {
  random {
    weighted(items:$items)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    Items
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().NotBeNull();
            response.Errors.Should().Contain(error => error.Message.Contains("weights") && error.Message.Contains("required"));
        }
        public async Task ShouldFailWithoutItems()
        {
            // Arrange
            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($count:Int!) {
  random {
    enumerationElements(count:$count)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    count = 1
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().NotBeNull();
            response.Errors.Should().Contain(error => error.Message.Contains("items") && error.Message.Contains("required"));
        }
Beispiel #4
0
        public async Task ShouldGetEvenNumber()
        {
            // Arrange
            int minValue = (int)RandomNumber(int.MinValue, 1000);
            int maxValue = (int)RandomNumber(1001, int.MaxValue);

            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($minValue:Int, $maxValue:Int) {
  random {
    even(min:$minValue, max:$maxValue)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    minValue,
                    maxValue
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().BeNull();
            var random = ParseResponse(response);

            (random.Even % 2).Should().Be(0);
        }
        public async Task ShouldGetCorrectCount()
        {
            // Arrange
            const short count = 2;

            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($count:Int!, $items:[String!]!) {
  random {
    enumerationElements(count:$count, items:$items)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    count,
                    items = Items
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().BeNull();
            var random = ParseResponse(response);

            random.EnumerationElements.Count().Should().Equals(count);
        }
        public async Task ShouldGetElementsFromItems()
        {
            // Arrange
            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($count:Int!, $items:[String!]!) {
  random {
    enumerationElements(count:$count, items:$items)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    count = Items.Count() - 2,
                    items = Items
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().BeNull();
            var random = ParseResponse(response);

            random.EnumerationElements.Should().NotBeEmpty();
            random.EnumerationElements.Should().BeSubsetOf(Items);
        }
Beispiel #7
0
        public async Task ShouldGetOddNumbers()
        {
            // Arrange
            int minValue = (int)RandomNumber(int.MinValue, 1000);
            int maxValue = (int)RandomNumber(1001, int.MaxValue);

            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($count:Int!, $minValue:Int, $maxValue:Int) {
  random {
    odds(count:$count, min:$minValue, max:$maxValue)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    count = TEST_COUNT,
                    minValue,
                    maxValue
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().BeNull();
            var random = ParseResponse(response);

            random.Odds.Should().OnlyContain(value => value % 2 != 0);
        }
        public async Task ShouldFailWithCountHigherThanItemsCount()
        {
            // Arrange
            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($count:Int!, $items:[String!]!) {
  random {
    enumerationElements(count:$count, items:$items)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    count = Items.Count() + 1,
                    items = Items
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().NotBeNull();
            response.Errors.Should().Contain(error => error.Message.Contains("ArgumentOutOfRangeException"));
        }
Beispiel #9
0
        public async Task IsItPossibleToCreateNewUser()
        {
            var user = new Eager.User()
            {
                Username = "******",
                Password = "******",
                Email    = "*****@*****.**"
            };
            var content = new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json");

            var userBadData = new Eager.User()
            {
                Username = "",
                Password = "******",
                Email    = "post@user"
            };
            var contentBadData = new StringContent(JsonConvert.SerializeObject(userBadData), Encoding.UTF8, "application/json");

            var unauthResponse = await DefaultClient.PostAsync("api/Users", content);

            Assert.Equal(HttpStatusCode.Unauthorized, unauthResponse.StatusCode);

            var badResponse = await AuthorizedClient.PostAsync("api/Users", contentBadData);

            Assert.Equal(HttpStatusCode.BadRequest, badResponse.StatusCode);

            var response = await AuthorizedClient.PostAsync("api/Users", content);

            var responseContent = await response.Content.ReadAsStringAsync();

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
        }
Beispiel #10
0
        public async Task ShouldGetCorrectUpperCase(bool upperCase)
        {
            // Arrange
            //string query = BuildQuery($"hash(upperCase:{upperCase.ToString().ToLower()})");

            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($upperCase:Boolean) {
  random {
    hash(upperCase:$upperCase)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    upperCase
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().BeNull();
            var random = ParseResponse(response);

            random.Hash.ToCharArray().Where(value => char.IsLetter(value)).Should().OnlyContain(value => upperCase ? char.IsUpper(value) : char.IsLower(value));
        }
Beispiel #11
0
        public async Task ShouldGetCorrectLength()
        {
            // Arrange
            short length = (short)RandomNumber(0, short.MaxValue);

            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($length:Int) {
  random {
    hash(length:$length)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    length
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().BeNull();
            var random = ParseResponse(response);

            random.Hash.Length.Should().Be(length);
        }
Beispiel #12
0
        public async Task ShouldGetNullForEmptyItems()
        {
            // Arrange
            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($items:[String!]!) {
  random {
    enumerationElement(items:$items)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    items = new int[0]
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().BeNull();
            var random = ParseResponse(response);

            random.EnumerationElement.Should().BeNull();
        }
Beispiel #13
0
        public async Task ShouldSwitchMinAndMaxCharWhenInverted()
        {
            // Arrange
            char minValue = (char)RandomNumber('m', 'z');
            char maxValue = (char)RandomNumber('a', 'i');

            var request = new GraphQLRequest
            {
                Query         = @"
query myQuery($count:Int!, $minValue:String, $maxValue:String) {
  random {
    strings(count:$count, minChar:$minValue, maxChar:$maxValue)
  }
}",
                OperationName = "myQuery",
                Variables     = new
                {
                    count = TEST_COUNT,
                    minValue,
                    maxValue
                }
            };

            // Act
            var response = await AuthorizedClient.SendQueryAsync(request);

            // Assert
            response.Errors.Should().BeNull();
            var random = ParseResponse(response);

            random.Strings.Select(value => value.ToCharArray().Should().OnlyContain(@char => @char >= maxValue && @char <= minValue));
        }