public void FeeModelReturnsCorrectOrderFeeForMakerLimitOrdersMinuteResolution() { var time = new DateTime(2018, 4, 10); var security = TestsHelpers.GetSecurity(); security.FeeModel = new GDAXFeeModel(); security.SetMarketPrice(new TradeBar { Symbol = security.Symbol, Close = 5000m, EndTime = time.AddSeconds(75) }); var orderFee = security.FeeModel.GetOrderFee(new OrderFeeParameters( security, new LimitOrder(security.Symbol, 1, 4999.99m, time) { OrderSubmissionData = new OrderSubmissionData(security.BidPrice, security.AskPrice, security.Price) })); Assert.AreEqual(0, orderFee.Value.Amount); Assert.AreEqual(Currencies.USD, orderFee.Value.Currency); orderFee = security.FeeModel.GetOrderFee(new OrderFeeParameters( security, new LimitOrder(security.Symbol, -1, 5000.01m, time) { OrderSubmissionData = new OrderSubmissionData(security.BidPrice, security.AskPrice, security.Price) })); Assert.AreEqual(0, orderFee.Value.Amount); Assert.AreEqual(Currencies.USD, orderFee.Value.Currency); }
public void CanUpdateOrderTest() { BrokerageMessageEvent message; Assert.AreEqual(false, _gdaxBrokerageModel.CanUpdateOrder(TestsHelpers.GetSecurity(), Mock.Of <Order>(), new UpdateOrderRequest(DateTime.UtcNow, 1, new UpdateOrderFields()), out message)); }
public async Task Create_WhenInvoiceAlreadyExists_DoesNotCreate() { //Arrange _repository .Setup(c => c.GetByIdentifier("INV-001")) .ReturnsAsync(new Invoice { Identifier = "INV-001" }); var sut = new CreateInvoiceValidator(_repository.Object); var request = new CreateInvoiceRequest { Identifier = "INV-001", Amount = 150.05m, User = TestsHelpers.CreateUser("1", Roles.Admin) }; //Act var result = await sut.ValidateAsync(request); //Assert result.IsValid.Should().BeFalse(); result.Errors.Should() .Contain(c => c.ErrorMessage == "The invoice cannot be created because another invoice with the same Identifier already exists."); }
public void CanOnlySubmitCryptoOrders(SecurityType securityType, bool isValidSecurityType) { BrokerageMessageEvent message; var order = new Mock <Order>(); order.Object.Quantity = 10.0m; Assert.AreEqual(isValidSecurityType, _gdaxBrokerageModel.CanSubmitOrder(TestsHelpers.GetSecurity(1.0m, securityType), order.Object, out message)); }
public void CanSubmitOrder_WhenQuantityIsLargeEnough(decimal orderQuantity, bool isValidOrderQuantity) { BrokerageMessageEvent message; var order = new Mock <Order>(); order.Object.Quantity = orderQuantity; Assert.AreEqual(isValidOrderQuantity, _gdaxBrokerageModel.CanSubmitOrder(TestsHelpers.GetSecurity(), order.Object, out message)); }
public void CanSubmit_CertainOrderTypes(OrderType orderType, int year, int month, int day, int hour, int minute, int second, bool isValidOrderType) { var utcTime = new DateTime(year, month, day, hour, minute, second); BrokerageMessageEvent message; var security = TestsHelpers.GetSecurity(); var order = Order.CreateOrder(new SubmitOrderRequest(orderType, SecurityType.Crypto, security.Symbol, 10.0m, 1.0m, 10.0m, utcTime, "Test Order")); Assert.AreEqual(isValidOrderType, _gdaxBrokerageModel.CanSubmitOrder(security, order, out message)); }
public void FeeModelReturnsCorrectOrderFeeForTakerMarketOrder() { var security = TestsHelpers.GetSecurity(); security.FeeModel = new GDAXFeeModel(); security.SetMarketPrice(new TradeBar { Symbol = security.Symbol, Close = 5000m }); var orderFee = security.FeeModel.GetOrderFee(new OrderFeeParameters( security, new MarketOrder(security.Symbol, 1, DateTime.MinValue))); Assert.AreEqual(15m, orderFee.Value.Amount); Assert.AreEqual(Currencies.USD, orderFee.Value.Currency); }
public async Task Create_WithUserType_ShouldNotCreatesAnInvoice() { //Arrange var request = new CreateInvoiceRequest { Identifier = "INV-001", Amount = 150.05m, User = TestsHelpers.CreateUser("1", Roles.User) }; //Act var result = await _sut.Authorize(request); //Assert result.Should().BeFalse(); }
public async Task Create_UsesRepositoryCreate() { //Arrange var request = new CreateInvoiceRequest { Identifier = "INV-001", Amount = 150.05m, User = TestsHelpers.CreateUser("1", Roles.Admin) }; //Act await _sut.Handle(request); //Assert _repository.Verify(c => c.Create(It.IsAny <Invoice>()), Times.Once); }
public async Task Update_UsesRepositoryUpdate() { //Arrange var request = new UpdateInvoiceRequest { InvoiceId = 1, Identifier = "INV-001-A", Amount = 160.05m, User = TestsHelpers.CreateUser("1", Roles.Admin) }; //Act await _sut.Handle(request); //Assert _repository.Verify(c => c.Update(), Times.Once); }
public void CanSubmitOrder_WhenBrokerageIdIsCorrect(bool isUpdate) { BrokerageMessageEvent message; var order = new Mock <Order>(); order.Object.Quantity = 10.0m; if (isUpdate) { order.Object.BrokerId = new List <string>() { "abc123" }; } Assert.AreEqual(!isUpdate, _gdaxBrokerageModel.CanSubmitOrder(TestsHelpers.GetSecurity(), order.Object, out message)); }
public async Task Create_WithAdminType_CreatesAnInvoice() { //Arrange var request = new CreateInvoiceRequest { Identifier = "INV-001", Amount = 150.05m, User = TestsHelpers.CreateUser("1", Roles.Admin) }; //Act var result = await _sut.Handle(request); //Assert result.ShouldBeSuccess(); result.result.Should().NotBeNull(); }
public async Task Update_WhenTheInvoiceDoesNotExists_ShouldNotUpdate() { //Arrange var request = new UpdateInvoiceRequest { InvoiceId = 2, Identifier = "INV-02", User = TestsHelpers.CreateUser("2", Roles.Admin) }; var sut = new UpdateInvoiceValidator(_repository.Object); //Act var result = await sut.ValidateAsync(request); //Assert result.IsValid.Should().BeFalse(); result.Errors.Should().Contain(c => c.ErrorCode == Result.NotPresent.StatusCode); }
public async Task Update_WhenUpdatingUserIsNotTheCreator_ShouldNotUpdate() { //Arrange var request = new UpdateInvoiceRequest { InvoiceId = 1, Identifier = "INV-001-A", Amount = 160.05m, User = TestsHelpers.CreateUser("2", Roles.Admin) }; var sut = new UpdateInvoiceAuthorization(_repository.Object); //Act var result = await sut.Authorize(request); //Assert result.Should().BeFalse(); }
public UpdateInvoiceTests() { _repository = new Mock <IInvoicesRepository>(); _repository.Setup(c => c.Get(1)) .ReturnsAsync(new Invoice { InvoiceId = 1, Identifier = "INV-001", Amount = 150.05m, UpdatedBy = TestsHelpers.CreateUser("1", Roles.Admin).GetIdentity() }); _repository.Setup(c => c.GetByIdentifier("INV-002")) .ReturnsAsync(new Invoice { InvoiceId = 2, Identifier = "INV-002" }); _sut = new UpdateInvoiceHandler(_repository.Object); }
public void Update_WhenIdentifierIsUsedByADifferentInvoice_ShouldNotUpdate() { //Arrange var sut = new UpdateInvoiceValidator(_repository.Object); var request = new UpdateInvoiceRequest { InvoiceId = 1, Identifier = "INV-002", User = TestsHelpers.CreateUser("1", Roles.Admin) }; //Act var result = sut.Validate(request); //Assert result.IsValid.Should().BeFalse(); result.Errors.Should().Contain(c => c.ErrorMessage == "The invoice cannot be updated " + "because another invoice with the new identifier already exists."); }
public void FeeModelReturnsCorrectOrderFeeForTakerLimitOrdersTickResolution() { var security = TestsHelpers.GetSecurity(resolution: Resolution.Tick); security.FeeModel = new GDAXFeeModel(); security.SetMarketPrice(new Tick { Symbol = security.Symbol, Value = 5000m }); var orderFee = security.FeeModel.GetOrderFee(new OrderFeeParameters( security, new LimitOrder(security.Symbol, 1, 5000.01m, DateTime.MinValue) { OrderSubmissionData = new OrderSubmissionData(security.BidPrice, security.AskPrice, security.Price) })); // marketable buy limit fill at 5000 Assert.AreEqual(15m, orderFee.Value.Amount); Assert.AreEqual(Currencies.USD, orderFee.Value.Currency); security.SetMarketPrice(new Tick { Symbol = security.Symbol, BidPrice = 5000m, AskPrice = 5000.01m, TickType = TickType.Quote }); orderFee = security.FeeModel.GetOrderFee(new OrderFeeParameters( security, new LimitOrder(security.Symbol, 1, 5000.01m, DateTime.MinValue) { OrderSubmissionData = new OrderSubmissionData(security.BidPrice, security.AskPrice, security.Price) })); // marketable buy limit fill at 5000.01 Assert.AreEqual(15.00003m, orderFee.Value.Amount); Assert.AreEqual(Currencies.USD, orderFee.Value.Currency); orderFee = security.FeeModel.GetOrderFee(new OrderFeeParameters( security, new LimitOrder(security.Symbol, -1, 5000m, DateTime.MinValue) { OrderSubmissionData = new OrderSubmissionData(security.BidPrice, security.AskPrice, security.Price) })); // marketable sell limit fill at 5000 Assert.AreEqual(15m, orderFee.Value.Amount); Assert.AreEqual(Currencies.USD, orderFee.Value.Currency); }
public async Task Create_ReturnsInvoice() { //Arrange var request = new CreateInvoiceRequest { Identifier = "INV-001", Amount = 150.05m, User = TestsHelpers.CreateUser("1", Roles.Admin) }; //Act var result = await _sut.Handle(request); //Assert var invoice = result.invoice; result.ShouldBeSuccess(); invoice.UpdatedBy.Should().Be("1"); invoice.Amount.Should().Be(request.Amount); invoice.Identifier.Should().Be(request.Identifier); }
public void GetLeverageTest() { Assert.AreEqual(1, _gdaxBrokerageModel.GetLeverage(TestsHelpers.GetSecurity())); }
public void GetBuyingPowerModelTest() { Assert.IsInstanceOf <CashBuyingPowerModel>(_gdaxBrokerageModel.GetBuyingPowerModel(TestsHelpers.GetSecurity())); }
public void GetFeeModelTest() { Assert.IsInstanceOf <GDAXFeeModel>(_gdaxBrokerageModel.GetFeeModel(TestsHelpers.GetSecurity())); }