public void ExchangeService_CanConstructClient()
        {
            var InvalidData = new ExchangeExternalServiceData()
            {
                PublicKey  = "test",
                PairedDate = DateTime.Now,
            };
            var externalServiceData = new ExternalServiceData()
            {
                Type = ExchangeService.ExchangeServiceType,
                Name = "something"
            };

            externalServiceData.Set(InvalidData);

            var exchangeService = GetExternalService(externalServiceData);

            Assert.ThrowsAny <Exception>(() => exchangeService.ConstructClient());


            var validData = new ExchangeExternalServiceData()
            {
                PublicKey    = "test",
                PairedDate   = DateTime.Now,
                ExchangeName = "Binance",
                PrivateKey   = "aa"
            };

            externalServiceData.Set(validData);

            Assert.NotNull(exchangeService.ConstructClient());
        }
Esempio n. 2
0
    public void ActionThrowsExceptionAssignableToStaticType()
    {
        void a()
        {
            throw new InvalidOperationException("Operation is invalid.");
        }

        Action            action = a;
        ArgumentException ae;

        // MSTest does not support this case.

        // NUnit
        Assert.That(a, Throws.InstanceOf <ArgumentException>(), () => "Some context");
        // Some context
        //  Expected: instance of <System.ArgumentException>
        //  But was: <System.InvalidOperationException>

        // XUnit
        ae = XUnitAssert.ThrowsAny <ArgumentException>(action);
        // Assert.Throws() Failure
        // Expected: typeof(System.ArgumentException)
        // Actual:  typeof(System.InvalidOperationException): Operation is invalid.
        // ---- System.InvalidOperationException: Operation is invalid.

        // Fluent
        ae = action.Should().Throw <ArgumentException>("SOME REASONS").Which;
        // Expected a <System.ArgumentException> to be thrown because SOME REASONS, but found a <System.InvalidOperationException>: System.InvalidOperationException with message "Operation is invalid."
        // at...

        // Shouldly
        ae = action.ShouldThrow <ArgumentException>("Some context");
        // `action()`
        //   should throw
        // System.ArgumentException
        //   but threw
        // System.InvalidOperationException
        //
        // Additional Info:
        //  Some context ---> System.InvalidOperationException: Operation is invalid.
    }