public async Task OwnedCryptoWorksAsync() { var crypto = new OwnedCrypto(new Token("BTC"), _userId); crypto.Purchase(10, 2.1m, DateTimeOffset.UtcNow); var storage = CreateStorage(); await storage.Save(crypto, _userId); var loadedList = await storage.GetCryptos(_userId); Assert.NotEmpty(loadedList); var loaded = await storage.GetCrypto(crypto.State.Token, _userId); Assert.Equal(loaded.State.Quantity, crypto.State.Quantity); loaded.Purchase(5, 5, DateTime.UtcNow); await storage.Save(loaded, _userId); loaded = await storage.GetCrypto(loaded.State.Token, loaded.State.UserId); Assert.NotEqual(loaded.State.Quantity, crypto.State.Quantity); await storage.Delete(_userId); var afterDelete = await storage.GetCryptos(_userId); Assert.Empty(afterDelete); }
public void ExportCryptos() { var crypto = new OwnedCrypto("btc", Guid.NewGuid()); crypto.Purchase(quantity: 1.2m, dollarAmountSpent: 200, date: DateTimeOffset.UtcNow); crypto.Sell(quantity: 0.2m, dollarAmountReceived: 100, date: DateTimeOffset.UtcNow); var report = CSVExport.Generate(new[] { crypto }); Assert.Contains(CSVExport.CRYPTOS_HEADER, report); Assert.Contains("BTC", report); Assert.Contains("buy", report); Assert.Contains("sell", report); }
public void Btc_EndToEnd() { var btc = new OwnedCrypto( new Token("BTC"), System.Guid.NewGuid() ); btc.Purchase( quantity: 0.05437703m, dollarAmountSpent: 985.32m, date: System.DateTimeOffset.Parse("2017-12-19T15:05:38Z") ); Assert.Equal(0.05437703m, btc.State.Quantity); Assert.Equal(985.32m, btc.State.Cost); btc.Sell(0.004m, dollarAmountReceived: 74, DateTimeOffset.UtcNow, notes: null); Assert.Equal(0.05037703m, btc.State.Quantity); Assert.Equal(2, btc.State.Transactions.Count); Assert.Single(btc.State.PositionInstances); }