Beispiel #1
0
    public void Asserts_Equal()
    {
        // Arrange
        var value = Rnd.Str;

        // Act
        var action = () => FluentQueryHelper.AssertEqual(value, value);

        // Assert
        action();
    }
Beispiel #2
0
    public void Inspector_Throws_FluentQueryHelperException__Catches_And_Rethrows()
    {
        // Arrange
        var collection = new[] { Rnd.Lng };
        var inspectors = new Action <long>[] { _ => throw new EqualTypeException() };

        // Act
        var action = () => FluentQueryHelper.AssertCollection(collection, inspectors);

        // Assert
        Assert.Throws <EqualTypeException>(action);
    }
Beispiel #3
0
    public void Inspector_Throws_Exception__Catches_And_Throws_As_CollectionException()
    {
        // Arrange
        var collection = new[] { Rnd.Lng };
        var inspectors = new Action <long>[] { _ => throw new InvalidOperationException() };

        // Act
        var action = () => FluentQueryHelper.AssertCollection(collection, inspectors);

        // Assert
        Assert.Throws <CollectionException>(action);
    }
Beispiel #4
0
    public void Not_Expression__Throws_PropertyExpressionException()
    {
        // Arrange

        // Act
        var action = () => FluentQueryHelper.AssertPropertyExpression <Test, string>(Rnd.Str, Rnd.Str);

        // Assert
        var ex = Assert.Throws <PropertyExpressionException>(action);

        Assert.Equal($"Expected a property expression but received '{typeof(string)}'.", ex.Message);
    }
Beispiel #5
0
    public async Task Asserts_ExecuteAsync()
    {
        // Arrange
        var fluent = Create();
        await fluent.ExecuteAsync(x => x.Id);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertExecute <TestEntity, TestId>(c, x => x.Id, false);

        // Assert
        fluent.AssertCalls(action);
    }
Beispiel #6
0
    public async Task Incorrect_Method__Throws_MethodNameException()
    {
        // Arrange
        var fluent = Create();
        await fluent.CountAsync();

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertExecute <TestEntity, TestId>(c, x => x.Id, true);

        // Assert
        Assert.Throws <MethodNameException>(() => fluent.AssertCalls(action));
    }
Beispiel #7
0
    public async Task Incorrect_Generic_Argument__Throws_GenericArgumentException()
    {
        // Arrange
        var fluent = Create();
        await fluent.ExecuteAsync(x => x.Id);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertExecute <TestEntity, string>(c, nameof(TestEntity.Id), false);

        // Assert
        Assert.Throws <GenericArgumentException>(() => fluent.AssertCalls(action));
    }
Beispiel #8
0
    public async Task Not_Property_Expression__Throws_PropertyExpressionException()
    {
        // Arrange
        var fluent = Create();
        await fluent.ExecuteAsync <TestId>(nameof(TestEntity.Id));

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertExecute <TestEntity, TestId>(c, x => x.Id, false);

        // Assert
        Assert.Throws <PropertyExpressionException>(() => fluent.AssertCalls(action));
    }
Beispiel #9
0
    public void Collection_And_Inspectors_Different_Lengths__Throws_CollectionException()
    {
        // Arrange
        var collection = Enumerable.Repeat(Rnd.Str, Rnd.Int).ToArray();
        var inspectors = Enumerable.Repeat((string _) => { }, Rnd.Int).ToArray();

        // Act
        var action = () => FluentQueryHelper.AssertCollection(collection, inspectors);

        // Assert
        Assert.Throws <CollectionException>(action);
    }
Beispiel #10
0
    public void Asserts_Equal()
    {
        // Arrange
        var expected = nameof(Test.Foo);
        Expression <Func <Test, string> > actual = x => x.Foo;

        // Act
        var action = () => FluentQueryHelper.AssertPropertyExpression <Test, string>(expected, actual);

        // Assert
        action();
    }
Beispiel #11
0
    public void Asserts_Equal()
    {
        // Arrange
        var value = Rnd.Str;
        var v0    = new { value };
        var v1    = new { value };

        // Act
        var action = () => FluentQueryHelper.AssertEqualJson(v0, v1);

        // Assert
        action();
    }
Beispiel #12
0
    public void Asserts_Sort(SortOrder input)
    {
        // Arrange
        var fluent = Create();

        fluent.Sort(x => x.Id, input);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertSort <TestEntity, TestId>(c, x => x.Id, input);

        // Assert
        fluent.AssertCalls(action);
    }
Beispiel #13
0
    public void Incorrect_Method__Throws_MethodNameException()
    {
        // Arrange
        var fluent = Create();

        fluent.Maximum(Rnd.ULng);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertWhereNotIn <TestEntity, long>(c, x => x.Bar, new[] { Rnd.Lng, Rnd.Lng });

        // Assert
        Assert.Throws <MethodNameException>(() => fluent.AssertCalls(action));
    }
Beispiel #14
0
    public void Incorrect_Generic_Argument__Throws_GenericArgumentException(SortOrder input)
    {
        // Arrange
        var fluent = Create();

        fluent.Sort(x => x.Id, input);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertSort <TestEntity, string>(c, nameof(TestEntity.Id), input);

        // Assert
        Assert.Throws <GenericArgumentException>(() => fluent.AssertCalls(action));
    }
Beispiel #15
0
    public void Incorrect_Method__Throws_MethodNameException(SortOrder input)
    {
        // Arrange
        var fluent = Create();

        fluent.Skip(Rnd.ULng);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertSort <TestEntity, TestId>(c, x => x.Id, input);

        // Assert
        Assert.Throws <MethodNameException>(() => fluent.AssertCalls(action));
    }
Beispiel #16
0
    public void Incorrect_Type__Throws_EqualTypeException()
    {
        // Arrange
        var value = Rnd.Lng;

        // Act
        var action = () => FluentQueryHelper.AssertEqualType(value, value.ToString());

        // Assert
        var ex = Assert.Throws <EqualTypeException>(action);

        Assert.Equal($"Expected type '{typeof(long)}' but value was type '{typeof(string)}'.", ex.Message);
    }
Beispiel #17
0
    public async Task Asserts_ExecuteAsync__With_Transaction()
    {
        // Arrange
        var fluent      = Create();
        var transaction = Substitute.For <IDbTransaction>();
        await fluent.ExecuteAsync(x => x.Id, transaction);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertExecute <TestEntity, TestId>(c, x => x.Id, true);

        // Assert
        fluent.AssertCalls(action);
    }
Beispiel #18
0
    public void Asserts_WhereNotIn()
    {
        // Arrange
        var fluent = Create();
        var values = new[] { Rnd.Str, Rnd.Str };

        fluent.WhereNotIn(x => x.Foo, values);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertWhereNotIn <TestEntity, string>(c, x => x.Foo, values);

        // Assert
        fluent.AssertCalls(action);
    }
Beispiel #19
0
    public void Incorrect_Generic_Argument__Throws_GenericArgumentException()
    {
        // Arrange
        var fluent = Create();
        var values = new[] { Rnd.Str, Rnd.Str };

        fluent.WhereNotIn(x => x.Foo, values);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertWhereNotIn <TestEntity, long>(c, x => x.Bar, new[] { Rnd.Lng, Rnd.Lng });

        // Assert
        Assert.Throws <GenericArgumentException>(() => fluent.AssertCalls(action));
    }
Beispiel #20
0
    public void Values_Not_Equal__Throws_EqualTypeException()
    {
        // Arrange
        var fluent = Create();
        var values = new[] { Rnd.Str, Rnd.Str };

        fluent.WhereNotIn(x => x.Foo, values);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertWhereNotIn <TestEntity, string>(c, x => x.Foo, new[] { Rnd.Str, Rnd.Str });

        // Assert
        Assert.Throws <EqualTypeException>(() => fluent.AssertCalls(action));
    }
Beispiel #21
0
    public void Not_Equal__Throws_EqualTypeException()
    {
        // Arrange
        var v0 = Rnd.Str;
        var v1 = Rnd.Str;

        // Act
        var action = () => FluentQueryHelper.AssertEqual(v0, v1);

        // Assert
        var ex = Assert.Throws <EqualTypeException>(action);

        Assert.Equal($"Expected '{v0}' but value was '{v1}'.", ex.Message);
    }
Beispiel #22
0
    public void Not_Equal__Throws_PropertyExpressionException()
    {
        // Arrange
        var expected = nameof(Test.Bar);
        Expression <Func <Test, string> > actual = x => x.Foo;

        // Act
        var action = () => FluentQueryHelper.AssertPropertyExpression <Test, string>(expected, actual);

        // Assert
        var ex = Assert.Throws <PropertyExpressionException>(action);

        Assert.Equal($"Expected property with name '{expected}' but received '{nameof(Test.Foo)}'.", ex.Message);
    }
Beispiel #23
0
    public void Same_Property_Names__Different_Values__Throws_EqualJsonException()
    {
        // Arrange
        var v0 = new { v0 = Rnd.Str };
        var v1 = new { v1 = Rnd.Str };

        // Act
        var action = () => FluentQueryHelper.AssertEqualJson(v0, v1);

        // Assert
        var ex = Assert.Throws <EqualJsonException>(action);

        Assert.Equal($"Expected '{v0}' but value was '{v1}'.", ex.Message);
    }
Beispiel #24
0
    public void Clause_Not_Equal_Throws_EqualTypeException()
    {
        // Arrange
        var fluent     = Create();
        var parameters = new { value = Rnd.Guid };

        fluent.Where(Rnd.Str, parameters);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertWhere(c, Rnd.Str, parameters);

        // Assert
        Assert.Throws <EqualTypeException>(() => fluent.AssertCalls(action));
    }
Beispiel #25
0
    public void Parameters_Not_Equal__Throws_EqualJsonException()
    {
        // Arrange
        var fluent = Create();
        var clause = Rnd.Str;

        fluent.Where(clause, new { value = Rnd.Lng });

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertWhere(c, clause, new { value = Rnd.Lng });

        // Assert
        Assert.Throws <EqualJsonException>(() => fluent.AssertCalls(action));
    }
Beispiel #26
0
    public void With_Property_Expression__Asserts_Where()
    {
        // Arrange
        var fluent  = Create();
        var compare = Compare.Like;
        var value   = Rnd.Str;

        fluent.Where(x => x.Foo, compare, value);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertWhere <TestEntity, string>(c, x => x.Foo, compare, value);

        // Assert
        fluent.AssertCalls(action);
    }
Beispiel #27
0
    public void Incorrect_Method__Throws_MethodNameException()
    {
        // Arrange
        var fluent = Create();

        fluent.Maximum(Rnd.ULng);

        // Act
        var a0 = (ICall c) => FluentQueryHelper.AssertWhere <TestEntity, string>(c, x => x.Foo, Compare.Equal, Rnd.Str);
        var a1 = (ICall c) => FluentQueryHelper.AssertWhere(c, Rnd.Str, Rnd.Str);

        // Assert
        Assert.Throws <MethodNameException>(() => fluent.AssertCalls(a0));
        Assert.Throws <MethodNameException>(() => fluent.AssertCalls(a1));
    }
Beispiel #28
0
    public void With_Clause__Asserts_Where()
    {
        // Arrange
        var fluent     = Create();
        var clause     = Rnd.Str;
        var parameters = new { value = Rnd.Lng };

        fluent.Where(clause, parameters);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertWhere(c, clause, parameters);

        // Assert
        fluent.AssertCalls(action);
    }
Beispiel #29
0
    public void With_Nullable_Value__Asserts_Where()
    {
        // Arrange
        var  fluent  = Create();
        var  compare = Compare.NotEqual;
        long?value   = Rnd.Lng;

        fluent.Where(x => x.Nll, compare, value);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertWhere <TestEntity, long?>(c, x => x.Nll, compare, value);

        // Assert
        fluent.AssertCalls(action);
    }
Beispiel #30
0
    public void No_Generic_Argument__Throws_GenericArgumentException()
    {
        // Arrange
        var fluent  = Create();
        var compare = Compare.Like;
        var value   = Rnd.Str;

        fluent.Where(nameof(TestEntity.Foo), compare, value);

        // Act
        var action = (ICall c) => FluentQueryHelper.AssertWhere <TestEntity, string>(c, x => x.Foo, compare, value);

        // Assert
        Assert.Throws <GenericArgumentException>(() => fluent.AssertCalls(action));
    }