public async Task Test_SearchInvoices_CustomerAndPriceOnly() { var searchArguments1 = new InvoiceSearchArgs { CustomerID = this.customer.ID, MinTotal = 100.0m, MaxTotal = 1805.7m // Maximale Summe = 1899.5 }; var invoiceModels1 = await this.invoiceRepository.Search(searchArguments1); Assert.AreEqual(1, invoiceModels1.Count()); var searchArguments2 = new InvoiceSearchArgs { CustomerID = this.customer.ID, MinTotal = 100.0m, MaxTotal = 1900.4m // Maximale Summe = 1899.5 }; var invoiceModels2 = await this.invoiceRepository.Search(searchArguments2); Assert.AreEqual(2, invoiceModels2.Count()); var searchArguments3 = new InvoiceSearchArgs { CustomerID = this.customer.ID, MinTotal = 1743.4m, MaxTotal = 2019.3m // Maximale Summe = 1899.5 }; var invoiceModels3 = await this.invoiceRepository.Search(searchArguments3); Assert.AreEqual(1, invoiceModels3.Count()); }
public async Task <IEnumerable <InvoiceModel> > Search(InvoiceSearchArgs invoiceSearchArgs) { if (invoiceSearchArgs.IsEmpty()) { throw new ArgumentNullException("invoiceSearchArgs", "At least one parameter needs to be not null"); } return(await this.invoiceRepository.Search(invoiceSearchArgs)); }
public async Task Test_SearchInvoices_CustomerOnly() { var searchArguments = new InvoiceSearchArgs { CustomerID = this.customer.ID }; var invoiceModels = await this.invoiceRepository.Search(searchArguments); Assert.AreEqual(2, invoiceModels.Count()); }
public async Task Test_SearchInvoices_CustomerAndDateOnly() { var searchArguments = new InvoiceSearchArgs { CustomerID = this.customer.ID, MinDate = DateTime.Now.AddDays(-1), MaxDate = DateTime.Now.AddDays(10) }; var invoiceModels = await this.invoiceRepository.Search(searchArguments); Assert.AreEqual(2, invoiceModels.Count()); }
public void Test_IsNotEmpty() { var args = new InvoiceSearchArgs { CustomerID = 1, MinDate = DateTime.Now, MaxDate = DateTime.Now, MinTotal = 0.0m, MaxTotal = 100.0m }; Assert.IsFalse(args.IsEmpty()); }
public async Task <IEnumerable <InvoiceModel> > Search(InvoiceSearchArgs invoiceSearchArgs) { var url = new StringBuilder(this.ConnectionString).Append("invoices?"); if (invoiceSearchArgs.CustomerID.HasValue) { url.AppendFormat("customerID={0}&", invoiceSearchArgs.CustomerID.Value); } if (invoiceSearchArgs.MinDate.HasValue) { var timestamp = (invoiceSearchArgs.MinDate.Value - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()).TotalSeconds; url.AppendFormat("startDate={0}&", timestamp); } if (invoiceSearchArgs.MaxDate.HasValue) { var timestamp = (invoiceSearchArgs.MaxDate.Value - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()).TotalSeconds; url.AppendFormat("endDate={0}&", timestamp); } if (invoiceSearchArgs.MinTotal.HasValue) { url.AppendFormat("minTotal={0}&", invoiceSearchArgs.MinTotal.Value); } if (invoiceSearchArgs.MaxTotal.HasValue) { url.AppendFormat("maxTotal={0}", invoiceSearchArgs.MaxTotal.Value); } var response = await this.request.Get(url.ToString()); switch (response.StatusCode) { case HttpStatusCode.OK: try { return(await response.Content.ReadAsObjectAsync <IEnumerable <InvoiceModel> >(this.jsonSettings)); } catch (JsonReaderException e) { throw new FaultyMessageException(inner: e); } default: throw new BadResponseException(response.StatusCode); } }
public async Task Test_SearchInvoices_AllArguments() { var searchArguments = new InvoiceSearchArgs { CustomerID = this.customer.ID, MinDate = DateTime.Now.AddDays(-1), MaxDate = DateTime.Now.AddDays(10), MinTotal = 100.0m, MaxTotal = 1805.7m // Maximale Summe = 1899.5 }; var invoiceModels = await this.invoiceRepository.Search(searchArguments); Assert.AreEqual(1, invoiceModels.Count()); }
public async Task <IEnumerable <InvoiceModel> > Search(InvoiceSearchArgs invoiceSearchArgs) { return(await Task.Run(() => { IEnumerable <InvoiceModel> invoices = MockData.Instance.Invoices; if (invoiceSearchArgs.CustomerID.HasValue) { invoices = invoices.Where(i => i.Customer.ID == invoiceSearchArgs.CustomerID.Value); } if (invoiceSearchArgs.MinDate.HasValue) { invoices = invoices.Where( i => DateTime.Compare(i.IssueDate.Date, invoiceSearchArgs.MinDate.Value.Date) >= 0 || DateTime.Compare(i.DueDate.Date, invoiceSearchArgs.MinDate.Value.Date) >= 0); } if (invoiceSearchArgs.MaxDate.HasValue) { invoices = invoices.Where( i => DateTime.Compare(i.IssueDate.Date, invoiceSearchArgs.MaxDate.Value.Date) <= 0 || DateTime.Compare(i.DueDate.Date, invoiceSearchArgs.MaxDate.Value.Date) <= 0); } if (invoiceSearchArgs.MinTotal.HasValue) { invoices = invoices.Where( i => Decimal.Compare(i.InvoiceItems.Sum(ii => ii.UnitPrice *ii.Amount * (ii.Tax + 1)), invoiceSearchArgs.MinTotal.Value) >= 0); } if (invoiceSearchArgs.MaxTotal.HasValue) { invoices = invoices.Where( i => Decimal.Compare(i.InvoiceItems.Sum(ii => ii.UnitPrice *ii.Amount * (ii.Tax + 1)), invoiceSearchArgs.MaxTotal.Value) <= 0); } return invoices; })); }
public SearchInvoicesViewModel(IUnityContainer container, IInvoiceService invoiceService) { this.invoiceService = invoiceService; this.SearchInvoicesCommand = new RelayCommand(this.onSearchInvoicesExecuted, this.onSearchInvoicesCanExecute); this.invoiceSearchArgs = new InvoiceSearchArgs(); this.invoiceSearchArgs.PropertyChanged += ((s, e) => this.SearchInvoicesCommand.RaiseCanExecuteChanged()); this.CustomerSearchBoxViewModel = container.Resolve <CustomerSearchBoxViewModel>(new ParameterOverrides { { "customerType", CustomerType.None } }); this.CustomerSearchBoxViewModel.PropertyChanged += CustomerSearchBoxViewModel_PropertyChanged; #if DEBUG if (ViewModelBase.IsInDesignModeStatic) { this.MinTotal = 0.0m; this.onSearchInvoicesExecuted(); } #endif }
public void Test_IsEmpty() { var args = new InvoiceSearchArgs(); Assert.IsTrue(args.IsEmpty()); }