Exemplo n.º 1
0
        public async Task Update_LineItem_price()
        {
            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(22.33m);

            var repository = new PurchaseTransactionRepository(fixture.context);

            var sut = await repository.GetPurchaseTransactionFullAsync(transactionId);

            Assert.NotNull(sut.LineItems);
            Assert.Single(sut.LineItems);
            Assert.Equal(22.33m, sut.LineItems.FirstOrDefault().Price.Amount);

            var lineItemId = sut.LineItems.FirstOrDefault().Id;

            var updatedLineItem = LineItemBuilder
                                  .LineItem(new Price(33.44m, Booking.Credit, "EUR", "€", CurrencySymbolPosition.end), lineItemId)
                                  .Build();

            await UpdateLineItem(transactionId, updatedLineItem);

            sut = await ReloadPurchaseTransaction(sut.Id);

            Assert.Single(sut.LineItems);
            Assert.Equal(33.44m, sut.LineItems.FirstOrDefault().Price.Amount);
        }
Exemplo n.º 2
0
        public async Task Update_LineItem_price()
        {
            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(22.33m);

            var repository = new PurchaseTransactionRepository(fixture.context);

            var sut = await repository.GetAsync(transactionId);

            Assert.NotNull(sut.LineItems);
            Assert.Single(sut.LineItems);
            Assert.Equal(22.33m, sut.LineItems.FirstOrDefault()?.Price.Amount);

            var lineItemId = sut.LineItems.FirstOrDefault()?.Id;

            // Get Product
            var prod = await ProductHelpers.CreateValidProduct();

            var updatedLineItem = LineItemBuilder
                                  .LineItem(new Price(33.44m), lineItemId)
                                  .WithProduct(prod)
                                  .Build();

            await UpdateLineItem(transactionId, updatedLineItem);

            sut = await ReloadPurchaseTransaction(sut.Id);

            Assert.Single(sut.LineItems);
            Assert.Equal(33.44m, sut.LineItems.FirstOrDefault()?.Price.Amount);
        }
Exemplo n.º 3
0
        public async Task Total_price_of_line_items_with_debit_item()
        {
            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(1.23m);

            var repository = new PurchaseTransactionRepository(fixture.context);

            Assert.True(await repository.ExistsAsync(transactionId));

            var sut = await repository.GetPurchaseTransactionFullAsync(transactionId);

            Assert.Single(sut.LineItems);

            var secondLineItem = LineItemBuilder.LineItem(new Price(2.54m, Booking.Credit, "EUR", "€", CurrencySymbolPosition.end))
                                 .Build();

            await UpdateLineItem(sut.Id, secondLineItem);

            var debitLineItem = LineItemBuilder.LineItem(new Price(1.54m, Booking.Debit, "EUR", "€", CurrencySymbolPosition.end))
                                .Build();

            await UpdateLineItem(sut.Id, debitLineItem);

            sut = await ReloadPurchaseTransaction(sut.Id);

            Assert.Equal(3, sut.LineItems.Count);
            Assert.Equal(2, sut.LineItems.Count(i => i.Price.Booking == Booking.Credit));
            Assert.Equal(1, sut.LineItems.Count(i => i.Price.Booking == Booking.Debit));

            var result = decimal.Parse(sut.TotalPrice.Substring(0, sut.TotalPrice.IndexOf(' ', StringComparison.Ordinal)));

            Assert.Equal(2.23m, result);
        }
Exemplo n.º 4
0
        public async Task Total_price_of_line_items()
        {
            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(1.23m);

            var repository = new PurchaseTransactionRepository(fixture.context);

            Assert.True(await repository.ExistsAsync(transactionId));

            var sut = await repository.GetAsync(transactionId);

            Assert.Single(sut.LineItems);

            // Get Product
            var prod = await ProductHelpers.CreateValidProduct();

            var secondLineItem = LineItemBuilder
                                 .LineItem(new Price(2.54m))
                                 .WithProduct(prod)
                                 .Build();

            await UpdateLineItem(sut.Id, secondLineItem);

            sut = await ReloadPurchaseTransaction(sut.Id);

            Assert.Equal(2, sut.LineItems.Count);
            var result = decimal.Parse(sut.TotalPrice.Substring(0, sut.TotalPrice.IndexOf(' ', StringComparison.Ordinal)));

            Assert.Equal(3.77m, result);
        }
Exemplo n.º 5
0
        public async Task Add_transaction_lineItem()
        {
            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction();

            var repository = new PurchaseTransactionRepository(fixture.context);

            Assert.True(await repository.ExistsAsync(transactionId));

            var sut = await repository.GetAsync(transactionId);

            Assert.Single(sut.LineItems);

            // Get Product
            var prod = await ProductHelpers.CreateValidProduct();

            var lineItem = LineItemBuilder
                           .LineItem(new Price(2.54m))
                           .WithProduct(prod)
                           .Build();

            await UpdateLineItem(sut.Id, lineItem);

            sut = await ReloadPurchaseTransaction(sut.Id);

            Assert.Equal(2, sut.LineItems.Count);
        }
Exemplo n.º 6
0
        public async static Task <PurchaseTransaction> ReloadPurchaseTransaction(PurchaseTransactionId id)
        {
            var connectionString = ConnectivityService.GetConnectionString("TEMP");
            var context          = new SplurgeStopDbContext(connectionString);
            var repository       = new PurchaseTransactionRepository(context);

            return(await repository.GetPurchaseTransactionFullAsync(id));
        }
Exemplo n.º 7
0
        public async Task FullPurchase_transaction_inserted_to_database()
        {
            PurchaseTransactionId transactionId = await CreateFullValidPurchaseTransaction();

            var repository = new PurchaseTransactionRepository(fixture.context);
            var sut        = await repository.GetAsync(transactionId);

            Assert.True(await repository.ExistsAsync(transactionId));
            Assert.Equal(DateTime.Now.Date, sut.PurchaseDate);
            Assert.NotNull(sut.Store);
            Assert.Single(sut.LineItems);
        }
Exemplo n.º 8
0
        public async Task Add_lineItem_with_notes()
        {
            var lineItem = LineItemBuilder.LineItem(new Price(1.00m, Booking.Credit, "EUR", "€", CurrencySymbolPosition.end))
                           .WithNotes("My Notes!")
                           .Build();
            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(1m, lineItem);

            var repository = new PurchaseTransactionRepository(fixture.context);
            var sut        = await repository.GetPurchaseTransactionFullAsync(transactionId);

            Assert.True(await repository.ExistsAsync(transactionId));
            Assert.Equal("My Notes!", sut.LineItems.FirstOrDefault().Notes);
        }
Exemplo n.º 9
0
        public async static Task UpdateStore(PurchaseTransactionId id, Store store)
        {
            var connectionString      = ConnectivityService.GetConnectionString("TEMP");
            var context               = new SplurgeStopDbContext(connectionString);
            var repository            = new PurchaseTransactionRepository(context);
            var unitOfWork            = new EfCoreUnitOfWork(context);
            var service               = new PurchaseTransactionService(repository, unitOfWork);
            var transactionController = new PurchaseTransactionController(service);

            var updateCommand = new transaction.Commands.SetPurchaseTransactionStore();

            updateCommand.Id      = id;
            updateCommand.StoreId = store.Id;

            await transactionController.Put(updateCommand);
        }
Exemplo n.º 10
0
        public static async Task UpdatePurchaseDate(PurchaseTransactionId id, DateTime date)
        {
            var connectionString      = ConnectivityService.GetConnectionString("TEMP");
            var context               = new SplurgeStopDbContext(connectionString);
            var repository            = new PurchaseTransactionRepository(context);
            var unitOfWork            = new EfCoreUnitOfWork(context);
            var service               = new PurchaseTransactionService(repository, unitOfWork);
            var transactionController = new PurchaseTransactionController(service);

            var updateCommand = new Commands.SetPurchaseTransactionDate
            {
                Id = id,
                TransactionDate = date
            };

            await transactionController.Put(updateCommand);
        }
Exemplo n.º 11
0
        public async Task Update_transaction_date()
        {
            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction();

            var repository = new PurchaseTransactionRepository(fixture.context);

            Assert.True(await repository.ExistsAsync(transactionId));

            var sut = await repository.LoadFullPurchaseTransactionAsync(transactionId);

            Assert.Equal(DateTime.Now.Date, sut.PurchaseDate);

            await UpdatePurchaseDate(sut.Id, DateTime.Now.AddDays(-1));

            await fixture.context.Entry(sut).ReloadAsync();

            Assert.Equal(DateTime.Now.AddDays(-1).Date, sut.PurchaseDate);
        }
Exemplo n.º 12
0
        public static async Task <PurchaseTransactionId> CreateFullValidPurchaseTransaction()
        {
            var connectionString = ConnectivityService.GetConnectionString("TEMP");
            var context          = new SplurgeStopDbContext(connectionString);
            var repository       = new PurchaseTransactionRepository(context);
            var unitOfWork       = new EfCoreUnitOfWork(context);
            var service          = new PurchaseTransactionService(repository, unitOfWork);

            var command = new Commands.CreateFull
            {
                Id = null,
                TransactionDate = DateTime.Now
            };

            // Add Store
            var store = await StoreHelpers.CreateValidStore();

            command.StoreId = store.Id;

            // Get Product
            var prod = await ProductHelpers.CreateValidProduct();

            // Add one LineItem
            var newLineItem = new LineItemStripped
            {
                Booking                = Booking.Credit,
                Price                  = "1.23",
                CurrencyCode           = "EUR",
                CurrencySymbol         = "€",
                CurrencySymbolPosition = CurrencySymbolPosition.End,
                Notes                  = "New notes",
                ProductId              = prod.Id
            };

            command.LineItems = new List <LineItemStripped>
            {
                newLineItem
            };

            var transactionController = new PurchaseTransactionController(service);
            await transactionController.Post(command);

            return(command.Id);
        }
Exemplo n.º 13
0
        public static async Task <PurchaseTransactionId> CreateValidPurchaseTransaction(decimal price     = 1.00m,
                                                                                        LineItem lineItem = null)
        {
            var connectionString = ConnectivityService.GetConnectionString("TEMP");
            var context          = new SplurgeStopDbContext(connectionString);
            var repository       = new PurchaseTransactionRepository(context);
            var unitOfWork       = new EfCoreUnitOfWork(context);
            var service          = new PurchaseTransactionService(repository, unitOfWork);

            var command = new Commands.CreateFull();

            command.Id = null;
            command.TransactionDate = DateTime.Now;

            // Add Store
            var store = await StoreHelpers.CreateValidStore();

            command.StoreId = store.Id;

            // Get Product
            var prod = await ProductHelpers.CreateValidProduct();

            // Add one LineItem
            command.LineItems = new List <LineItemStripped>
            {
                new LineItemStripped
                {
                    Price                  = price.ToString(CultureInfo.InvariantCulture),
                    CurrencyCode           = "EUR",
                    CurrencySymbol         = "€",
                    CurrencySymbolPosition = CurrencySymbolPosition.End,
                    Booking                = Booking.Credit,
                    Notes                  = lineItem?.Notes,
                    ProductId              = prod.Id
                }
            };

            // Create PurchaseTransaction
            var transactionController = new PurchaseTransactionController(service);
            await transactionController.Post(command);

            return(command.Id);
        }
Exemplo n.º 14
0
        public async static Task <PurchaseTransactionId> CreateValidPurchaseTransaction(decimal price     = 1.00m,
                                                                                        LineItem lineItem = null)
        {
            var connectionString = ConnectivityService.GetConnectionString("TEMP");
            var context          = new SplurgeStopDbContext(connectionString);
            var repository       = new PurchaseTransactionRepository(context);
            var unitOfWork       = new EfCoreUnitOfWork(context);
            var service          = new PurchaseTransactionService(repository, unitOfWork);

            var command = new transaction.Commands.Create();

            command.Id = null;

            // Create PurchaseTransaction
            var transactionController = new PurchaseTransactionController(service);
            var result = await transactionController.Post(command);

            // Add PurchaseDate
            await UpdatePurchaseDate(result.Value.Id, DateTime.Now);

            var purchaseTransaction = await repository.GetPurchaseTransactionFullAsync(result.Value.Id);

            // Add Store
            var store = await CreateValidStore();

            await UpdateStore(purchaseTransaction.Id, store);

            // Add one LineItem
            var updateLineItemCommand = new transaction.Commands.SetPurchaseTransactionLineItem();

            updateLineItemCommand.Id                     = purchaseTransaction.Id;
            updateLineItemCommand.Price                  = price;
            updateLineItemCommand.Currency               = "EUR";
            updateLineItemCommand.CurrencySymbol         = "€";
            updateLineItemCommand.Booking                = Booking.Credit;
            updateLineItemCommand.CurrencySymbolPosition = CurrencySymbolPosition.end;
            updateLineItemCommand.Notes                  = lineItem?.Notes;

            await transactionController.Put(updateLineItemCommand);

            return(command.Id);
        }
Exemplo n.º 15
0
        public async Task Add_lineItem_with_notes()
        {
            var brand       = Brand.Create(Guid.NewGuid(), "brand");
            var productType = ProductType.Create(Guid.NewGuid(), "product type");
            var size        = Size.Create(Guid.NewGuid(), "your size");

            var product  = Product.Create(Guid.NewGuid(), "product", brand, productType, size);
            var lineItem = LineItemBuilder.LineItem(new Price(1.00m))
                           .WithNotes("My Notes!")
                           .WithProduct(product)
                           .Build();

            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(1m, lineItem);

            var repository = new PurchaseTransactionRepository(fixture.context);
            var sut        = await repository.GetAsync(transactionId);

            Assert.True(await repository.ExistsAsync(transactionId));
            Assert.Equal("My Notes!", sut.LineItems.FirstOrDefault()?.Notes);
        }
Exemplo n.º 16
0
        public async static Task <PurchaseTransactionId> CreateFullValidPurchaseTransaction()
        {
            var connectionString = ConnectivityService.GetConnectionString("TEMP");
            var context          = new SplurgeStopDbContext(connectionString);
            var repository       = new PurchaseTransactionRepository(context);
            var unitOfWork       = new EfCoreUnitOfWork(context);
            var service          = new PurchaseTransactionService(repository, unitOfWork);

            var command = new transaction.Commands.CreateFull();

            command.Id = null;

            // Add PurchaseDate
            command.TransactionDate = DateTime.Now;

            // Add Store
            var store = await CreateValidStore();

            command.StoreId = store.Id;

            // Add one LineItem
            var newLineItem = new LineItemStripped
            {
                Booking                = Booking.Credit,
                Price                  = 1.23m,
                CurrencyCode           = "EUR",
                CurrencySymbol         = "€",
                CurrencySymbolPosition = CurrencySymbolPosition.end,
                Notes                  = "New notes"
            };

            command.LineItems = new List <LineItemStripped>();
            command.LineItems.Add(newLineItem);

            var transactionController = new PurchaseTransactionController(service);
            var result = await transactionController.Post(command);

            return(command.Id);
        }
Exemplo n.º 17
0
        public async static Task UpdateLineItem(PurchaseTransactionId id, LineItem lineItem)
        {
            var connectionString      = ConnectivityService.GetConnectionString("TEMP");
            var context               = new SplurgeStopDbContext(connectionString);
            var repository            = new PurchaseTransactionRepository(context);
            var unitOfWork            = new EfCoreUnitOfWork(context);
            var service               = new PurchaseTransactionService(repository, unitOfWork);
            var transactionController = new PurchaseTransactionController(service);

            var updateCommand = new transaction.Commands.SetPurchaseTransactionLineItem();

            updateCommand.Id                     = id;
            updateCommand.LineItemId             = lineItem.Id;
            updateCommand.Price                  = lineItem.Price.Amount;
            updateCommand.Currency               = lineItem.Price.Currency.CurrencyCode;
            updateCommand.CurrencySymbol         = lineItem.Price.Currency.CurrencySymbol;
            updateCommand.Booking                = lineItem.Price.Booking;
            updateCommand.CurrencySymbolPosition = lineItem.Price.Currency.PositionRelativeToPrice;
            updateCommand.Notes                  = lineItem?.Notes;

            await transactionController.Put(updateCommand);
        }
Exemplo n.º 18
0
        public async Task Change_Store()
        {
            var purchaseTransactionId = await CreateValidPurchaseTransaction();

            var repository = new PurchaseTransactionRepository(fixture.context);

            var sut = await repository.GetAsync(purchaseTransactionId);

            Assert.True(await repository.ExistsAsync(purchaseTransactionId));

            Assert.NotNull(sut);

            var newStore = await StoreHelpers.CreateValidStore();

            await UpdateStore(sut.Id, newStore);

            sut = await repository.LoadFullPurchaseTransactionAsync(sut.Id);

            await fixture.context.Entry(sut).ReloadAsync();

            Assert.Equal(newStore.Id, sut.Store.Id);
        }
Exemplo n.º 19
0
        public async Task Add_transaction_lineItem()
        {
            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction();

            var repository = new PurchaseTransactionRepository(fixture.context);

            Assert.True(await repository.ExistsAsync(transactionId));

            var sut = await repository.GetPurchaseTransactionFullAsync(transactionId);

            Assert.Single(sut.LineItems);

            var lineItem = LineItemBuilder
                           .LineItem(new Price(2.54m, Booking.Credit, "EUR", "€", CurrencySymbolPosition.end))
                           .Build();

            await UpdateLineItem(sut.Id, lineItem);

            sut = await ReloadPurchaseTransaction(sut.Id);

            Assert.Equal(2, sut.LineItems.Count);
        }