public void PersistData_LoadStream_CanReadSaveStream()
        {
            // Arrange
            string streamName = "EventStream1";

            var cashDeskStream = new CashDesk.Server.CashDeskEventStream()
            {
                StreamName = "EventStream1"
            };

            var dataEventsPersistence = new DataEventsPersistenceMock();

            cashDeskStream.AddTransaction(new Server.Entities.CashDeskTransaction(
                                              new DateTime(2021, 05, 05), "HAMMER", "Test", 20.12m, "1"));

            var dataPersistence = new PersistData <CashDesk.Server.CashDeskEventStream>(dataEventsPersistence);

            // Act
            dataPersistence.Save <DataCashDeskTransactionAddedEvent, CashDeskTransactionAddedEvent>(cashDeskStream);
            var result = dataPersistence.Load(streamName);

            // Assert
            Assert.Equal(streamName, result.StreamName);
            Assert.Equal(20.12m, result.CashDeskBalance["1"]);
        }
Esempio n. 2
0
        public void PersistData_Load()
        {
            // Arrange
            string streamName = "EntityStream1";
            string eventType  = typeof(DataCashDeskTransactionAddedEvent).AssemblyQualifiedName;

            var changes = new List <DataCashDeskTransactionAddedEvent>()
            {
                new DataCashDeskTransactionAddedEvent()
                {
                    EventType   = eventType,
                    Transaction = new Server.Entities.CashDeskTransaction(new DateTime(2021, 02, 05), "HAMMER", "Claw Hammer", 20.43m, "1")
                },
                new DataCashDeskTransactionAddedEvent()
                {
                    EventType   = eventType,
                    Transaction = new Server.Entities.CashDeskTransaction(new DateTime(2021, 02, 05), "NAIL2_5", "2.5mm NAILS (100)", 0.94m, "1")
                },
                new DataCashDeskTransactionAddedEvent()
                {
                    EventType   = eventType,
                    Transaction = new Server.Entities.CashDeskTransaction(new DateTime(2021, 02, 05), "NAIL1_8", "1.8mm NAILS (250)", 2.01m, "1")
                }
            };
            var cashDeskReturnStream = new CashDesk.Server.CashDeskEventStream()
            {
                Changes    = changes.Select(a => (object)a).ToList(),
                StreamName = streamName
            };
            var returnStreamSerialised = JsonConvert.SerializeObject(cashDeskReturnStream);

            var dataEventsPersistence = Substitute.For <DataPersistence.IDataEventsPersistence>();

            dataEventsPersistence.Read(Arg.Is <string>(streamName)).Returns(new[] { returnStreamSerialised });

            var dataPersistence = new PersistData <CashDesk.Server.CashDeskEventStream>(dataEventsPersistence);

            // Act
            var result = dataPersistence.Load(streamName);

            // Assert
            Assert.Equal(streamName, result.StreamName);
            Assert.Equal(23.38m, result.CashDeskBalance["1"]);
        }
        static void Main(string[] args)
        {
            _cashDeskEventStream = _persistData.Load("Stream1");

            while (true)
            {
                Console.WriteLine("1 - Add till transaction");
                Console.WriteLine("2 - View till balance");
                Console.WriteLine("3 - View all till balances");
                Console.WriteLine("4 - View all transactions");
                Console.WriteLine("5 - Exit");

                var key = Console.ReadKey();

                switch (key.Key)
                {
                case ConsoleKey.D1:
                    AddTransactionDialog();
                    break;

                case ConsoleKey.D2:
                    GetBalanceForTillDialog();
                    break;

                case ConsoleKey.D3:
                    GetBalanceForAllTillsDialog();
                    break;

                case ConsoleKey.D4:
                    GetTransactionHistory();
                    break;

                default:
                    _persistData.Save <DataCashDeskTransactionAddedEvent, CashDeskTransactionAddedEvent>(_cashDeskEventStream);
                    return;
                }
            }
        }
Esempio n. 4
0
 void OnEnable()
 {
     instance.Load();
 }