public void GetByIdReturnsInvoice()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfDeletableEntityRepository <Invoice>(new ApplicationDbContext(options.Options));

            var invoiceOne = new Invoice {
                Number = "43254325235", Date = DateTime.UtcNow, FuelType = "Бензин", CurrentLiters = 10, UserId = "341414153", CarId = "72804eudajhkhfvs-dasfa", Location = "София", Price = 2.09m, Quantity = 25.21, TotalPrice = 2.09m * 25.21m
            };
            var invoiceTwo = new Invoice {
                Number = "11254325235", Date = DateTime.UtcNow, FuelType = "Бензин", CurrentLiters = 25, UserId = "331414153", CarId = "72804eudajhkhfvs-dasfa", Location = "София", Price = 2.07m, Quantity = 45.21, TotalPrice = 2.09m * 25.21m
            };

            repository.AddAsync(invoiceOne);
            repository.AddAsync(invoiceTwo);
            repository.SaveChangesAsync();

            var invoicesService = new InvoicesService(repository);

            var invoice = invoicesService.GetById(invoiceOne.Id);

            Assert.Equal(invoiceOne.Number, invoice.Number);
            Assert.Equal(invoiceOne.Date, invoice.Date);
            Assert.Equal(invoiceOne.FuelType, invoice.FuelType);
            Assert.Equal(invoiceOne.CurrentLiters, invoice.CurrentLiters);
            Assert.Equal(invoiceOne.UserId, invoice.UserId);
            Assert.Equal(invoiceOne.CarId, invoice.CarId);
            Assert.Equal(invoiceOne.Location, invoice.Location);
            Assert.Equal(invoiceOne.Price, invoice.Price);
            Assert.Equal(invoiceOne.TotalPrice, invoice.TotalPrice);
        }
        public async Task InvoicesEditTest()
        {
            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb2");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);

            var service = new InvoicesService(dbContext);

            var invoice = new InvoicesCreateViewModel
            {
                Number     = "123",
                IssueDate  = DateTime.UtcNow.Date,
                Value      = 200,
                Maturity   = DateTime.UtcNow.Date.AddDays(30),
                PeriodFrom = DateTime.UtcNow.Date.AddMonths(-3),
                PeriodTo   = DateTime.UtcNow.Date.AddMonths(-2),
            };
            await service.CreateAsync(invoice);

            var edited = new InvoicesEditViewModel
            {
                Number     = "1234",
                IssueDate  = DateTime.UtcNow.Date,
                Value      = 201,
                Maturity   = DateTime.UtcNow.Date.AddDays(15),
                PeriodFrom = DateTime.UtcNow.Date.AddMonths(-4),
                PeriodTo   = DateTime.UtcNow.Date.AddMonths(-3),
            };

            var result = service.EditAsync(edited);

            Assert.NotNull(result);
        }
        public void IsNumberExistReturnsFalseWhenDoesNotExist()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfDeletableEntityRepository <Invoice>(new ApplicationDbContext(options.Options));

            var invoiceOne = new Invoice {
                Number = "43254325235", Date = DateTime.UtcNow, FuelType = "Бензин", CurrentLiters = 10, UserId = "341414153", CarId = "72804eudajhkhfvs-dasfa", Location = "София", Price = 2.09m, Quantity = 25.21, TotalPrice = 2.09m * 25.21m
            };
            var invoiceTwo = new Invoice {
                Number = "11254325235", Date = DateTime.UtcNow, FuelType = "Бензин", CurrentLiters = 25, UserId = "331414153", CarId = "72804eudajhkhfvs-dasfa", Location = "София", Price = 2.07m, Quantity = 45.21, TotalPrice = 2.09m * 25.21m
            };

            repository.AddAsync(invoiceOne);
            repository.AddAsync(invoiceTwo);
            repository.SaveChangesAsync();

            var invoicesService = new InvoicesService(repository);
            var currentNumber   = "74982403234";

            var exists = invoicesService.IsNumberExist(currentNumber);

            Assert.False(exists);
        }
        public async Task EditAsyncUpdatesCarInfo()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfDeletableEntityRepository <Invoice>(new ApplicationDbContext(options.Options));

            var invoicesService = new InvoicesService(repository);

            var invoiceOne = new Invoice {
                Number = "43254325235", Date = DateTime.UtcNow, FuelType = "Бензин", CurrentLiters = 10, UserId = "341414153", CarId = "72804eudajhkhfvs-dasfa", Location = "София", Price = 2.09m, Quantity = 25.21, TotalPrice = 2.09m * 25.21m
            };
            var invoiceTwo = new Invoice {
                Number = "11254325235", Date = DateTime.UtcNow, FuelType = "Бензин", CurrentLiters = 25, UserId = "331414153", CarId = "72804eudajhkhfvs-dasfa", Location = "София", Price = 2.07m, Quantity = 45.21, TotalPrice = 2.09m * 25.21m
            };
            await repository.AddAsync(invoiceOne);

            await repository.AddAsync(invoiceTwo);

            await repository.SaveChangesAsync();

            invoiceOne.Number     = "123456789";
            invoiceOne.Price      = 2.12m;
            invoiceOne.TotalPrice = invoiceOne.Price * (decimal)invoiceOne.Quantity;

            await invoicesService.EditAsync(invoiceOne);

            var invoice = repository.AllAsNoTracking().FirstOrDefault(i => i.Id == invoiceOne.Id);

            Assert.Equal(invoiceOne.Number, invoice.Number);
            Assert.Equal(invoiceOne.Price, invoice.Price);
            Assert.Equal(invoiceOne.TotalPrice, invoice.TotalPrice);
        }
        public void GetInvoiceNumberById()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfDeletableEntityRepository <Invoice>(new ApplicationDbContext(options.Options));

            var invoiceOne = new Invoice {
                Number = "43254325235", Date = DateTime.UtcNow, FuelType = "Бензин", CurrentLiters = 10, UserId = "341414153", CarId = "72804eudajhkhfvs-dasfa", Location = "София", Price = 2.09m, Quantity = 25.21, TotalPrice = 2.09m * 25.21m
            };
            var invoiceTwo = new Invoice {
                Number = "11254325235", Date = DateTime.UtcNow, FuelType = "Бензин", CurrentLiters = 25, UserId = "331414153", CarId = "72804eudajhkhfvs-dasfa", Location = "София", Price = 2.07m, Quantity = 45.21, TotalPrice = 2.09m * 25.21m
            };

            repository.AddAsync(invoiceOne);
            repository.AddAsync(invoiceTwo);
            repository.SaveChangesAsync();

            var invoicesService = new InvoicesService(repository);

            AutoMapperConfig.RegisterMappings(typeof(InvoiceDetailsViewModel).Assembly);
            var invoiceNumber = invoicesService.GetInvoiceNumberById(invoiceTwo.Id);

            Assert.Equal(invoiceTwo.Number, invoiceNumber);
        }
        public async Task GetAllAsyncShouldReturnAllInvoices()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var invoicesService = new InvoicesService(dbContext);

            dbContext.Invoices.AddRange(new List <Invoice>
            {
                new Invoice {
                    InvoiceNumber = "9630000001"
                },
                new Invoice {
                    InvoiceNumber = "9630000002"
                },
                new Invoice {
                    InvoiceNumber = "9630000003"
                },
                new Invoice {
                    InvoiceNumber = "9630000004"
                },
                new Invoice {
                    InvoiceNumber = "9630000005"
                },
            });

            await dbContext.SaveChangesAsync();

            var invoices = await invoicesService.GetAllAsync();

            Assert.Equal(5, invoices.Count());
        }
示例#7
0
        public async Task GenerateInvoiceAsync_InvoiceNotExist_ReturnInvoice()
        {
            string   customer    = "testUser";
            decimal  amount      = 100M;
            DateTime releaseDate = DateTime.Now;

            var context      = MockStatefulServiceContextFactory.Default;
            var stateManager = new MockReliableStateManager();
            var actorFactory = new Mock <IActorFactory>();
            var invoiceActor = new Mock <IInvoiceActor>();

            actorFactory.Setup(f => f.Create <IInvoiceActor>(It.IsAny <ActorId>(), It.Is <Uri>(u => u.AbsoluteUri == UriConstants.InvoiceActorUri), null))
            .Returns(invoiceActor.Object);

            invoiceActor.Setup(i => i.CreateAsync(customer, amount, releaseDate, UriConstants.UserActorUri, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(InvoiceActorError.Ok));


            var  yearKey = releaseDate.Year.ToString();
            uint currentInvoiceNumber = 10;

            await SetInvoiceNumberInDictionaryAsync(stateManager, yearKey, currentInvoiceNumber);

            var service = new InvoicesService(context, stateManager, actorFactory.Object, null);

            var actual = await service.GenerateInvoiceAsync(customer, amount, releaseDate, null, default(CancellationToken));

            Assert.IsNotNull(actual);
            Assert.AreEqual(actual.Customer, customer);
            Assert.AreEqual(actual.Amount, amount);

            uint?newInvoiceNumber = await GetInvoiceNumberInDictionaryAsync(stateManager, yearKey);

            Assert.AreEqual(currentInvoiceNumber + 1, newInvoiceNumber.Value);
        }
 public TransactionsServiceExample()
 {
     _transactionsService = new TransactionsService();
     _customersService    = new CustomersService();
     _creditCardsService  = new CreditCardsService();
     _invoicesService     = new InvoicesService();
     _itemsService        = new ItemsService();
 }
示例#9
0
        public void Delete_HasRents_ShouldThrowInvalidCountException()
        {
            var first        = Invoices.First();
            var incomingBook = first.IncomingBooks.First();

            Rents.Add(new Rent(incomingBook.Book, Subscribers.First(), Books.Single(x => x.Id == incomingBook.Book.Id).Count)
            {
                Id = _random.Next(int.MaxValue)
            });

            Assert.Throws <InvoiceCountException>(async() => await InvoicesService.Delete(first.Id));
        }
        public void InvoicesAllTest()
        {
            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb0");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);

            var service = new InvoicesService(dbContext);

            var result = service.AllAsync();

            Assert.NotNull(result);
        }
示例#11
0
        public async Task GenerateInvoiceAsync_AmountNegative_ThrowException()
        {
            var context      = MockStatefulServiceContextFactory.Default;
            var stateManager = new MockReliableStateManager();

            var service = new InvoicesService(context, stateManager);

            string   customer    = "testUser";
            decimal  amount      = -1M;
            DateTime releaseDate = DateTime.Now;

            var actual = await service.GenerateInvoiceAsync(customer, amount, releaseDate, null, default(CancellationToken));
        }
        public async Task GetViewModelAsync_ShouldThrow_NotImplemetedException()
        {
            var invoiceService = new InvoicesService();
            var inputModel     = new InvoiceInputModel()
            {
                Name = "Firma Frma", Price = 800
            };

            Action act = () => invoiceService.GetViewModelAsync(inputModel);

            act
            .Should()
            .ThrowExactly <InvalidOperationException>()
            .WithMessage("Not impelmented");
        }
        public async Task CreateAsyncAddsCar()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository     = new EfDeletableEntityRepository <Invoice>(new ApplicationDbContext(options.Options));
            var carsRepository = new EfDeletableEntityRepository <Car>(new ApplicationDbContext(options.Options));

            var carOne = new Car {
                Model = "Форд Фиеста", LicensePlate = "CO1212KA", CompanyId = "72804eudajhkhfvs-dasfa", FuelType = PatniListi.Data.Models.Enums.Fuel.Дизел, TankCapacity = 55, AverageConsumption = 4, InitialFuel = 10, StartKilometers = 234987
            };
            await carsRepository.AddAsync(carOne);

            var carTwo = new Car {
                Model = "Форд Фиеста", LicensePlate = "CO4312KA", CompanyId = "72804eud-3464-hfvs-dasfa", FuelType = PatniListi.Data.Models.Enums.Fuel.Бензин, TankCapacity = 55, AverageConsumption = 6, InitialFuel = 10, StartKilometers = 230444
            };
            await carsRepository.AddAsync(carTwo);

            var carThree = new Car {
                Model = "Форд Фиеста 8", LicensePlate = "CO9812KA", CompanyId = "72804eudajhkhfvs-dasfa", FuelType = PatniListi.Data.Models.Enums.Fuel.Дизел, TankCapacity = 55, AverageConsumption = 5, InitialFuel = 10, StartKilometers = 234957
            };
            await carsRepository.AddAsync(carThree);

            await carsRepository.SaveChangesAsync();

            var invoicesService = new InvoicesService(repository);

            var invoiceOne = new Invoice {
                Number = "43254325235", Date = DateTime.UtcNow, FuelType = "Бензин", CurrentLiters = 10, UserId = "341414153", CarId = "72804eudajhkhfvs-dasfa", Location = "София", Price = 2.09m, Quantity = 25.21, TotalPrice = 2.09m * 25.21m
            };
            var invoiceTwo = new Invoice {
                Number = "11254325235", Date = DateTime.UtcNow, FuelType = "Бензин", CurrentLiters = 25, UserId = "331414153", CarId = "72804eudajhkhfvs-dasfa", Location = "София", Price = 2.07m, Quantity = 45.21, TotalPrice = 2.09m * 25.21m
            };
            var invoiceThree = new Invoice {
                Number = "43258825235", Date = DateTime.UtcNow, FuelType = "Бензин", CurrentLiters = 20, UserId = "221414153", CarId = "72804eud-3464-hfvs-dasfa", Location = "Варна", Price = 2.06m, Quantity = 22.21, TotalPrice = 2.06m * 22.21m
            };

            await invoicesService.CreateAsync(invoiceOne);

            await invoicesService.CreateAsync(invoiceTwo);

            await invoicesService.CreateAsync(invoiceThree);

            var cars = repository.AllAsNoTracking().ToList().Count();

            Assert.Equal(3, cars);
        }
        public async Task CreateRentInvoiceAsyncNullRentShouldNotCreateInvoice()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var invoicesService = new InvoicesService(dbContext);

            Rent rent = null;

            await invoicesService.CreateRentInvoiceAsync(rent);

            var invoices = await dbContext.Invoices.ToListAsync();

            Assert.Empty(invoices);
        }
示例#15
0
 // GET: api/Invoices
 public IEnumerable <Invoice> Get()
 {
     return(InvoicesService.GetInvoices());
     //System.Configuration.Configuration rootWebConfig1 =
     //    System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
     //if (rootWebConfig1.AppSettings.Settings.Count > 0)
     //{
     //    System.Configuration.KeyValueConfigurationElement customSetting =
     //        rootWebConfig1.AppSettings.Settings["customsetting1"];
     //    if (customSetting != null)
     //        Console.WriteLine("customsetting1 application string = \"{0}\"",
     //            customSetting.Value);
     //    else
     //        Console.WriteLine("No customsetting1 application string");
     //}
     //return new List<Invoice>();
 }
示例#16
0
        public async Task Create_ShouldCreated()
        {
            var clrViaCsharpOldCount       = Books.Single(x => x.Id == DefaultData.Books.ClrVia.Id).Count;
            var jsPocketGuideOldCount      = Books.Single(x => x.Id == DefaultData.Books.JsPocketGuide.Id).Count;
            var jsForProfessionalsOldCount = Books.Single(x => x.Id == DefaultData.Books.JsForProfessionals.Id).Count;


            var dto = new InvoiceDto()
            {
                Date          = DateTime.Now,
                IncomingBooks = new List <IncomingBookDto>()
                {
                    new IncomingBookDto()
                    {
                        Book  = Mapper.Map <BookDto>(DefaultData.Books.ClrVia),
                        Count = 50
                    },
                    new IncomingBookDto()
                    {
                        Book  = Mapper.Map <BookDto>(DefaultData.Books.JsPocketGuide),
                        Count = 100
                    },
                    new IncomingBookDto()
                    {
                        Book  = Mapper.Map <BookDto>(DefaultData.Books.JsForProfessionals),
                        Count = 150
                    }
                }
            };
            await InvoicesService.Create(dto);

            var createdInvoice = Invoices.Last();

            Assert.That(createdInvoice, Is.Not.Null);
            Assert.That(createdInvoice.IncomingBooks.Count, Is.EqualTo(dto.IncomingBooks.Count));

            Assert.That(Books.Single(x => x.Id == DefaultData.Books.ClrVia.Id).Count,
                        Is.EqualTo(clrViaCsharpOldCount + dto.IncomingBooks.Single(x => x.Book.Id == DefaultData.Books.ClrVia.Id).Count));
            Assert.That(Books.Single(x => x.Id == DefaultData.Books.JsPocketGuide.Id).Count,
                        Is.EqualTo(jsPocketGuideOldCount + dto.IncomingBooks.Single(x => x.Book.Id == DefaultData.Books.JsPocketGuide.Id).Count));
            Assert.That(Books.Single(x => x.Id == DefaultData.Books.JsForProfessionals.Id).Count,
                        Is.EqualTo(jsForProfessionalsOldCount + dto.IncomingBooks.Single(x => x.Book.Id == DefaultData.Books.JsForProfessionals.Id).Count));
        }
        public async Task CreateRentInvoiceAsyncShouldCreateInvoice()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var invoicesService = new InvoicesService(dbContext);

            var rent = new Rent()
            {
                Recipient  = "Gosho Goshev",
                TotalPrice = 350,
            };

            await invoicesService.CreateRentInvoiceAsync(rent);

            var invoices = await dbContext.Invoices.ToListAsync();

            Assert.Single(invoices);
        }
        public void GetAll_ShouldReturn_ListOfInvoiceDtos()
        {
            // Arrange
            mockInvoicesRepo.Setup(i => i.GetAll()).Returns(new List <Invoice>());
            InvoicesService invoicesService = new InvoicesService(connString, mockInvoicesRepo.Object, new Dictionary <string, string>());

            List <InvoiceDto> invoiceDtos = null;

            try
            {
                // Act
                invoiceDtos = (List <InvoiceDto>)invoicesService.GetAll();
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsNotNull(invoiceDtos, errorMessage);
        }
        public void RemoveByUser_ShouldReturn_Success()
        {
            // Arrange
            string userId = "";

            mockInvoicesRepo.Setup(i => i.DeleteByUserId(userId));
            InvoicesService invoicesService = new InvoicesService(connString, mockInvoicesRepo.Object, new Dictionary <string, string>());

            try
            {
                // Act
                invoicesService.RemoveByUser(userId);
                operationSucceded = true;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsTrue(operationSucceded, errorMessage);
        }
        public async Task GetInvoiceByIdAsyncShouldReturnInvoice()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var invoicesService = new InvoicesService(dbContext);

            var invoiceNumber = "9630000001";

            dbContext.Invoices.AddRange(new List <Invoice>
            {
                new Invoice {
                    InvoiceNumber = invoiceNumber
                },
                new Invoice {
                    InvoiceNumber = "9630000002"
                },
                new Invoice {
                    InvoiceNumber = "9630000003"
                },
                new Invoice {
                    InvoiceNumber = "9630000004"
                },
                new Invoice {
                    InvoiceNumber = "9630000005"
                },
            });

            await dbContext.SaveChangesAsync();

            var invoiceId = dbContext.Invoices.FirstOrDefault(x => x.InvoiceNumber == invoiceNumber).Id;

            var invoice = await invoicesService.GetInvoiceByIdAsync(invoiceId);

            Assert.Equal(invoiceNumber, invoice.InvoiceNumber);
        }
        public void GetById_ShouldReturn_InvoiceDto()
        {
            // Arrange
            int invoiceId = 1;

            mockInvoicesRepo.Setup(i => i.GetById(invoiceId)).Returns(new Invoice());
            InvoicesService invoicesService = new InvoicesService(connString, mockInvoicesRepo.Object, new Dictionary <string, string>());

            InvoiceDto invoiceDto = null;

            try
            {
                // Act
                invoiceDto = invoicesService.GetById(invoiceId);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsNotNull(invoiceDto, errorMessage);
        }
示例#22
0
        public async Task Delete_ShouldDelete()
        {
            var first         = Invoices.First();
            var booksOldCount = first.IncomingBooks.Select(incomingBook => Books.Single(x => x.Id == incomingBook.Book.Id)).ToDictionary(book => book.Id, book => book.Count);

            foreach (KeyValuePair <long, int> pair in booksOldCount)
            {
                var rents = Rents.Where(x => x.Book.Id == pair.Key).ToList();
                foreach (var rent in rents)
                {
                    Rents.Remove(rent);
                }
            }


            await InvoicesService.Delete(first.Id);

            foreach (var incomingBook in first.IncomingBooks)
            {
                var book          = Books.Single(x => x.Id == incomingBook.Book.Id);
                var expectedCount = booksOldCount[book.Id] - incomingBook.Count;
                Assert.That(book.Count, Is.EqualTo(expectedCount));
            }
        }
示例#23
0
        public async Task CreateAsyncWorksCorrectlyForReccurentOrders()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var servicesRepository  = new EfDeletableEntityRepository <Service>(dbContext);
            var servicesServiceMock = new Mock <IServicesService>();

            servicesServiceMock.Setup(s => s.GetServicePrice(1)).Returns(100);

            var repository = new EfDeletableEntityRepository <Invoice>(dbContext);

            var service = new InvoicesService(repository, servicesServiceMock.Object);
            await service.CreateAsync(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, ServiceFrequency.Monthly, 1, 1);

            var result = dbContext.Invoices.FirstOrDefault();

            var expectedNetAmount    = 95;
            var expectedTotalAmoount = 114;

            Assert.Equal(expectedNetAmount, result.NetAmount);
            Assert.Equal(expectedTotalAmoount, result.TotalAmount);
        }
示例#24
0
 public InvoiceLogic(InvoicesService invoicesService) => _invoicesService = invoicesService;
示例#25
0
 public InvoicesController(InvoicesService invoices)
 {
     this.invoices = invoices;
 }
示例#26
0
 // GET: api/Invoices/5
 public Invoice Get(string id)
 {
     return(InvoicesService.GetInvoice(id));
 }
示例#27
0
        public async Task GetAll_ShouldReturnValid()
        {
            var invoices = await InvoicesService.GetAll();

            Assert.That(invoices.Count(), Is.EqualTo(Invoices.Count));
        }
示例#28
0
        public async Task GetByClientIdWorksCorrectly(string beforeDate, string afterDate, bool orderedByDateDesc, InvoiceStatus status, List <InvoiceServiceModel> expected)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var servicesRepository  = new EfDeletableEntityRepository <Service>(dbContext);
            var servicesServiceMock = new Mock <IServicesService>();

            var repository = new EfDeletableEntityRepository <Invoice>(dbContext);

            var service = new InvoicesService(repository, servicesServiceMock.Object);

            var clientId = Guid.NewGuid().ToString();
            var before   = DateTime.ParseExact(beforeDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            var after    = DateTime.ParseExact(afterDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);

            var invoice1 = new Invoice()
            {
                ClientId  = "1",
                CreatedOn = new DateTime(2020, 4, 15),
                Status    = InvoiceStatus.Paid,
            };

            var invoice2 = new Invoice()
            {
                ClientId  = "1",
                CreatedOn = new DateTime(2020, 4, 27),
                Status    = InvoiceStatus.Paid,
            };

            var invoice3 = new Invoice()
            {
                ClientId  = "1",
                CreatedOn = new DateTime(2020, 4, 27),
                Status    = InvoiceStatus.Pending,
            };

            var invoice4 = new Invoice()
            {
                ClientId  = "1",
                CreatedOn = new DateTime(2020, 4, 27),
                Status    = InvoiceStatus.Cancelled,
            };

            var invoice5 = new Invoice()
            {
                ClientId  = Guid.NewGuid().ToString(),
                CreatedOn = new DateTime(2020, 1, 27),
                Status    = InvoiceStatus.Cancelled,
            };

            dbContext.Add(invoice1);
            dbContext.Add(invoice2);
            dbContext.Add(invoice3);
            dbContext.Add(invoice4);
            dbContext.Add(invoice5);
            await dbContext.SaveChangesAsync();

            var services     = service.GetByClientId <InvoiceServiceModel>("1", before, after, orderedByDateDesc, status).ToList();
            var expectedList = expected.ToList();

            Assert.Equal(expectedList.Count, services.Count);

            for (int i = 0; i < services.Count; i++)
            {
                Assert.Equal(expectedList[i].CreatedOn, services[i].CreatedOn);
                Assert.Equal(expectedList[i].Status, services[i].Status);
            }
        }