public void AddEditInvoiceCommand_Add_Mode_Cannot_Execute_When_Number_Exceeds_Length() { //Arrange _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object, _navigationServiceMock.Object) { IssueDate = new DateTime(2015, 5, 6), Number = "2fffffffffffffffffffffffffffffffffffffffffff/2015", SelectedPaymentMethod = PaymentMethod.Cash, SaleDate = new DateTime(2015, 5, 6), SelectedBuyer = _buyers.First(), SelectedSeller = CreateSeller(), PaymentPeriod = 30, PaymentDetailList = new ItemsChangeObservableCollection<PaymentDetail> { new PaymentDetail { Description = "Czynsz za lokal ul. Marsa 3 maj", MeasureUnit = "szt.", PricePerUnit = 34400, Quantity = 1 }, new PaymentDetail { Description = "Czynsz za lokal ul. wris 3 lipiec", MeasureUnit = "szt.", PricePerUnit = 3500, Quantity = 1 } }, }; Assert.IsFalse(_invoiceViewModel.AddEditInvoiceCommand.CanExecute(null)); }
public void When_ReplaceInvoice_Executed_Send_Message_To_Update_Status_Bar() { //Arrange var invoice = new Invoice(); _contextMock.Setup(m => m.Payments.FindInvoice(It.IsAny<Expression<Func<Invoice, bool>>>())) .Returns(invoice); _messageBoxMock.Setup(m => m.ShowDialogBox(It.IsAny<string>())).Returns(true); const string expectedStatus = "Faktura zastąpiona"; string receivedStatus = null; Messenger.Default.Register<StatusMessage>(this, MessengerToken.MainWindowVm, msg => { receivedStatus = msg.NewStatus; }); _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object, _navigationServiceMock.Object) { Mode = Mode.Add, IssueDate = new DateTime(2015, 5, 6), Number = "2/2015", SelectedPaymentMethod = PaymentMethod.Cash, SaleDate = new DateTime(2015, 5, 6), SelectedBuyer = _buyers.First(), SelectedSeller = _selectedSeller, PaymentPeriod = 30, PaymentDetailList = new ItemsChangeObservableCollection<PaymentDetail> { new PaymentDetail { Description = "Czynsz za lokal ul. Marsa 3 maj", MeasureUnit = "szt.", PricePerUnit = 34400, Quantity = 1 } } }; //Act _invoiceViewModel.AddEditInvoiceCommand.Execute(null); //Verify Assert.IsTrue(expectedStatus.Equals(receivedStatus)); }
public void When_Navigation_Parameter_Is_Int_Invoke_GetSeller() { //Arrange var seller = new Seller { ID = 1 }; _navigationServiceMock.SetupGet(m => m.Parameter).Returns(seller.ID); _contextMock.Setup(m => m.People.GetSeller(It.IsAny<int>())).Returns(seller); //Act _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object, _navigationServiceMock.Object); //Verify _contextMock.Verify(m=>m.People.GetSeller(It.IsAny<int>()),Times.Once); }
public void When_Navigation_Parameter_Is_Int_Initialize_With_Mode_Add() { //Arrange var seller = new Seller { ID = 1 }; _navigationServiceMock.SetupGet(m => m.Parameter).Returns(seller.ID); _contextMock.Setup(m => m.People.GetSeller(It.IsAny<int>())).Returns(seller); //Act _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object, _navigationServiceMock.Object); //Verify Assert.IsTrue(_invoiceViewModel.Mode == Mode.Add); }
public void When_MessageBoxService_ShowDialogBox_Returns_True_Invoke_Remove_With_Returned_Invoice() { //Arrange var invoice = new Invoice(); _contextMock.Setup(m => m.Payments.FindInvoice(It.IsAny<Expression<Func<Invoice, bool>>>())) .Returns(invoice); _messageBoxMock.Setup(m => m.ShowDialogBox(It.IsAny<string>())).Returns(true); _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object, _navigationServiceMock.Object) { Mode = Mode.Add, IssueDate = new DateTime(2015, 5, 6), Number = "2/2015", SelectedPaymentMethod = PaymentMethod.Cash, SaleDate = new DateTime(2015, 5, 6), SelectedBuyer = _buyers.First(), SelectedSeller = _selectedSeller, PaymentPeriod = 30, PaymentDetailList = new ItemsChangeObservableCollection<PaymentDetail> { new PaymentDetail { Description = "Czynsz za lokal ul. Marsa 3 maj", MeasureUnit = "szt.", PricePerUnit = 34400, Quantity = 1 } } }; //Act _invoiceViewModel.AddEditInvoiceCommand.Execute(null); //Verify _contextMock.Verify(m=>m.Payments.Remove(invoice),Times.Once); }
public void AddEditInvoiceCommand_Add_Mode_Cannot_Execute_When_PaymentDetailListViewModels_Has_No_Items() { //Arrange _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object, _navigationServiceMock.Object) { IssueDate = new DateTime(2015, 5, 6), Number = "2/2015", SelectedPaymentMethod = PaymentMethod.Cash, SaleDate = new DateTime(2015, 5, 6), SelectedBuyer = _buyers.First(), SelectedSeller = CreateSeller(), PaymentPeriod = 30, PaymentDetailList = new ItemsChangeObservableCollection<PaymentDetail>() }; Assert.IsFalse(_invoiceViewModel.AddEditInvoiceCommand.CanExecute(null)); }
public void When_Initialized_Invoke_GetBuyerListFromSeller() { //Arrange var seller = new Seller { ID = 1 }; _navigationServiceMock.SetupGet(m => m.Parameter).Returns(seller.ID); _contextMock.Setup(m => m.People.GetSeller(It.IsAny<int>())).Returns(seller); _selectedSeller.Buyers.Clear(); //Act _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object, _navigationServiceMock.Object); //Verify _contextMock.Verify(m => m.People.FindBuyers(It.IsAny<Expression<Func<Buyer, bool>>>()), Times.Once()); }
public void NavigateToInvoiceListCommand_When_Executed_Invokes_NavigateTo_With_InvoiceListKey_And_SelectedSeller() { //Arrange _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object, _navigationServiceMock.Object); //Act _invoiceViewModel.NavigateToInvoiceListCommand.Execute(null); //Verify _navigationServiceMock.Verify(m => m.NavigateTo(ViewModelLocator.InvoiceListKey,It.IsAny<Seller>()), Times.Once); }
public void ClearInvoiceCommand_When_Executed_Clear_Properties_In_Invoice() { //Arrange _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object, _navigationServiceMock.Object) { IssueDate = new DateTime(2015, 5, 6), Number = "2/2015", SelectedPaymentMethod = PaymentMethod.Cash, SaleDate = new DateTime(2015, 5, 6), SelectedBuyer = _buyers.First(), SelectedSeller = CreateSeller(), PaymentPeriod = 30, PaymentDetailList = new ItemsChangeObservableCollection<PaymentDetail> { new PaymentDetail { Description = "Czynsz za lokal ul. Marsa 3 maj", MeasureUnit = "szt.", PricePerUnit = 34400, Quantity = 1 }, new PaymentDetail { Description = "Czynsz za lokal ul. wris 3 lipiec", MeasureUnit = "szt.", PricePerUnit = 3500, Quantity = 1 }, }, }; //Act _invoiceViewModel.ClearInvoiceCommand.Execute(null); //Verify Assert.IsTrue(_invoiceViewModel.PaymentDetailList.Count == 0); Assert.IsTrue(_invoiceViewModel.IssueDate == DateTime.Today); Assert.IsTrue(_invoiceViewModel.SaleDate == DateTime.Today); Assert.IsTrue(_invoiceViewModel.SelectedBuyer==null); Assert.IsTrue(_invoiceViewModel.Mode==Mode.Add); }
public void AddEditInvoiceCommand_Mode_Edit_When_Executed_Send_Message_To_Update_Status_Bar() { //Arrange string receivedStatus = null; Messenger.Default.Register<StatusMessage>(this, MessengerToken.MainWindowVm, msg => { receivedStatus = msg.NewStatus; }); _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object,_navigationServiceMock.Object) { Mode = Mode.Edit, IssueDate = new DateTime(2015, 5, 6), Number = "2/2015", SelectedPaymentMethod = PaymentMethod.Cash, SaleDate = new DateTime(2015, 5, 6), SelectedBuyer = _buyers.First(), SelectedSeller = CreateSeller(), PaymentPeriod = 10, PaymentDetailList = new ItemsChangeObservableCollection<PaymentDetail> { new PaymentDetail { Description = "Czynsz za lokal ul. Marsa 3 maj", MeasureUnit = "szt.", PricePerUnit = 34400, Quantity = 1 }, new PaymentDetail { Description = "Czynsz za lokal ul. wris 3 lipiec", MeasureUnit = "szt.", PricePerUnit = 3500, Quantity = 1 } }, }; //Act _invoiceViewModel.AddEditInvoiceCommand.Execute(null); const string expectedStatus = "Faktura zmodyfikowana"; //Verify Assert.IsTrue(expectedStatus.Equals(receivedStatus)); }
public void AddEditInvoiceCommand_Mode_Add_When_Executed_Invoke_FindInvoice_To_Check_If_Seller_Has_Invoice_With_ThisNumber() { //Arrange _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object, _navigationServiceMock.Object) { Mode = Mode.Add, IssueDate = new DateTime(2015, 5, 6), Number = "2/2015", SelectedPaymentMethod = PaymentMethod.Cash, SaleDate = new DateTime(2015, 5, 6), SelectedBuyer = _buyers.First(), SelectedSeller = _selectedSeller, PaymentPeriod = 30, PaymentDetailList = new ItemsChangeObservableCollection<PaymentDetail> { new PaymentDetail { Description = "Czynsz za lokal ul. Marsa 3 maj", MeasureUnit = "szt.", PricePerUnit = 34400, Quantity = 1 } } }; //Act _invoiceViewModel.AddEditInvoiceCommand.Execute(null); //Verify _contextMock.Verify(m => m.Payments.FindInvoice(It.IsAny<Expression<Func<Invoice,bool>>>()), Times.Once); }
public void AddEditInvoiceCommand_Execute_Mode_Edit_Invokes_Complete() { //Arrange _invoiceViewModel = new InvoiceViewModel(_contextMock.Object, _messageBoxMock.Object,_navigationServiceMock.Object) { Mode = Mode.Edit, IssueDate = new DateTime(2015, 5, 6), Number = "2/2015", SelectedPaymentMethod = PaymentMethod.Cash, SaleDate = new DateTime(2015, 5, 6), SelectedBuyer = _buyers.First(), SelectedSeller = CreateSeller(), PaymentPeriod = 10, PaymentDetailList = new ItemsChangeObservableCollection<PaymentDetail> { new PaymentDetail { Description = "Czynsz za lokal ul. Marsa 3 maj", MeasureUnit = "szt.", PricePerUnit = 34400, Quantity = 1 }, new PaymentDetail { Description = "Czynsz za lokal ul. wris 3 lipiec", MeasureUnit = "szt.", PricePerUnit = 3500, Quantity = 1 } }, }; //Act _invoiceViewModel.AddEditInvoiceCommand.Execute(null); //Verify _contextMock.Verify(m => m.Complete(), Times.Once); }