예제 #1
0
        public async Task Cannot_Add_Duplicate_Sale_Transaction_Id()
        {
            // ARRANGE
            // Service provider/scope
            using IServiceScope scope = this.Fixture.Services.CreateScope();
            IServiceProvider services = scope.ServiceProvider;

            // Services
            ISaleService saleService = services.GetRequiredService <ISaleService>();

            // Data
            string saleTransactionId = Guid.NewGuid().ToString("N", null);

            // ACT
            // First sale
            SaleDetails sale1 = await saleService.AddSaleAsync(
                saleTransactionId,
                DateTime.UtcNow.Date,
                new Random().NextDouble() * 100,
                "Test duplicate sale 1").ConfigureAwait(false);

            // Duplicate sale
            Func <Task> task = async() => await saleService.AddSaleAsync(
                saleTransactionId,
                DateTime.UtcNow.Date,
                new Random().NextDouble() * 100,
                "Test duplicate sale 2").ConfigureAwait(false);

            // ASSERT
            await Assert.ThrowsAsync <SaleExceptions.AlreadyExists>(task);
        }
예제 #2
0
        public async Task Get_Get_Sale_By_Transaction_Id()
        {
            // ARRANGE
            // Service provider/scope
            using IServiceScope scope = this.Fixture.Services.CreateScope();
            IServiceProvider services = scope.ServiceProvider;

            // Services
            ISaleService saleService = services.GetRequiredService <ISaleService>();

            // Data
            string saleTransactionId = Guid.NewGuid().ToString("N", null);

            // ACT
            // Add sale
            SaleDetails addedSale = await saleService.AddSaleAsync(
                saleTransactionId,
                DateTime.UtcNow.Date,
                new Random().NextDouble() * 100,
                "Test sale").ConfigureAwait(false);

            // Lookup sale
            SaleDetails foundSale = await saleService.GetSaleAsync(saleTransactionId).ConfigureAwait(false);

            // ASSERT
            Assert.NotNull(foundSale);
            Assert.Equal(saleTransactionId, foundSale.TransactionId);
            Assert.Equal(addedSale.TransactionId, foundSale.TransactionId);
            Assert.Equal(addedSale.Date, foundSale.Date);
            Assert.Equal(addedSale.Amount, foundSale.Amount);
            Assert.Equal(addedSale.Notes, foundSale.Notes);
        }
예제 #3
0
        public async Task Can_Add_Sale()
        {
            // ARRANGE
            // Service provider/scope
            using IServiceScope scope = this.Fixture.Services.CreateScope();
            IServiceProvider services = scope.ServiceProvider;

            // Services
            ISaleService saleService = services.GetRequiredService <ISaleService>();

            // Data
            string   saleTransactionId = Guid.NewGuid().ToString("N", null);
            DateTime saleDate          = DateTime.UtcNow.Date;
            double   saleAmount        = new Random().NextDouble() * 100;
            string   saleNotes         = "Test sale";

            // ACT
            // Add sale
            SaleDetails sale = await saleService.AddSaleAsync(
                saleTransactionId,
                saleDate,
                saleAmount,
                saleNotes).ConfigureAwait(false);

            // ASSERT
            Assert.NotNull(sale);
            Assert.Equal(saleTransactionId, sale.TransactionId);
            Assert.Equal(saleDate, sale.Date);
            Assert.Equal(saleAmount, sale.Amount);
            Assert.Equal(saleNotes, sale.Notes);
        }
예제 #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            await saleService.AddSaleAsync(Sale);

            return(RedirectToPage("GetAllSales"));
        }
예제 #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Sale.SalesDate = DateTime.Now;
            await saleService.AddSaleAsync(Sale);

            return(RedirectToPage("GetAllSales"));
        }
예제 #6
0
        public async Task Cannot_Add_Future_Sale()
        {
            // ARRANGE
            // Service provider/scope
            using IServiceScope scope = this.Fixture.Services.CreateScope();
            IServiceProvider services = scope.ServiceProvider;

            // Services
            ISaleService saleService = services.GetRequiredService <ISaleService>();

            // ACT
            Func <Task> task = async() => await saleService.AddSaleAsync(
                Guid.NewGuid().ToString("N", null),
                DateTime.UtcNow.Date.AddDays(2),
                new Random().NextDouble() * 100,
                "Test future sale").ConfigureAwait(false);

            // ASSERT
            await Assert.ThrowsAsync <SaleExceptions.DateInvalid>(task);
        }