public void Add_Seller_To_Collection_When_Received_From_SellerVM()
        {
            //Arrange
            _sellerListViewModel = new SellerListViewModel(_contextMock.Object);

            const int sellerId = 2;

            var sellerToAdd = new Seller
            {
                ID = sellerId,
                FirstName = "Michał",
                LastName = "Rakel",
                BankName = "mBank",
                BankAccountNumber = "32 3245 5456 5435 3242 5456 1296",
                NIP = "3234326576",
                Address = new Address
                {
                    City = "Kraków",
                    StreetAddress = "ul. Kredki 5/8a",
                    ZipCode = "31-063"
                }
            };

            //Act
            Messenger.Default.Send(new MessageService(sellerToAdd, EntityState.Added), MessengerToken.SellerListVm);

            //Verify
            Assert.IsTrue(_sellerListViewModel.SellerList.Any(s => s.PersonId == sellerId));
        }
        public void Change_Seller_In_SellerLIst_When_Received_From_SellerVm_After_Editing()
        {
            //Arrange
            _sellerListViewModel = new SellerListViewModel(_contextMock.Object);

            Seller seller = _store.First();

            const string newFirstName = "jakisludek",
                         newLastName = "nazwiskoLudka";

            seller.FirstName = newFirstName;
            seller.LastName = newLastName;

            Messenger.Default.Send(new MessageService(seller, EntityState.Edited), MessengerToken.SellerListVm);

            var editedSeller = _sellerListViewModel.SellerList.First(s => s.PersonId == seller.ID);

            Assert.AreEqual(newFirstName, editedSeller.FirstName);
            Assert.AreEqual(newLastName, editedSeller.LastName);
        }
        public void DeleteSellerCommand_When_Executed_Invokes_DeleteSellerById()
        {
            //Arrange
            _sellerListViewModel = new SellerListViewModel(_contextMock.Object);

            var sellerToDelete = _personInformations.First(s => s.FirstName == "Michał");

            _sellerListViewModel.SelectedSeller = sellerToDelete;

            //Act
            _sellerListViewModel.DeleteSellerCommand.Execute(null);

            //Verify
            _contextMock.Verify(m => m.People.RemoveById(It.IsAny<int>()), Times.Once);
            Assert.IsNull(_sellerListViewModel.SelectedSeller);
        }
        public void DeleteSellerCommand_Cannot_Execute_When_Seller_Is_Not_Selected()
        {
            //Arrange
            _sellerListViewModel = new SellerListViewModel(_contextMock.Object);
            _sellerListViewModel.SelectedSeller = null;

            //Act and Verify
            Assert.IsFalse(_sellerListViewModel.DeleteSellerCommand.CanExecute(null));
        }
        public void When_SellerViewModel_Initailized_Invoke_GetBasicPeopleData()
        {
            //Arrange and Act
            _sellerListViewModel = new SellerListViewModel(_contextMock.Object);

            //Verify
            _contextMock.Verify(m => m.People.GetBasicSellersData(), Times.Once);
        }
        public void NavigateToInvoiceCommand_When_Executed_Invoke_NavigateTo_With_InvoiceKey_And_SelectedSellerID()
        {
            //Arrange
            _sellerListViewModel = new SellerListViewModel(_contextMock.Object, _navigationServiceMock.Object)
            {
                SelectedSeller = _personInformations.First()
            };

            //Act
            _sellerListViewModel.NavigatoToInvoiceCommand.Execute(null);

            //Verify
            _navigationServiceMock.Verify(m => m.NavigateTo(ViewModelLocator.InvoiceKey, It.IsAny<int>()), Times.Once);
        }
        public void RaisePropertyChanged_On_SelectedSeller_When_changed()
        {
            _sellerListViewModel = new SellerListViewModel(_contextMock.Object);

            _sellerListViewModel.ShouldNotifyOn(s => s.SelectedSeller)
                .When(s => s.SelectedSeller = _personInformations.First());
        }
        public void NavigateToInvoiceCommand_Cannot_Execute_When_SelectedSeller_Is_Null()
        {
            //Arrange
            _sellerListViewModel = new SellerListViewModel(_contextMock.Object) { SelectedSeller = null };

            //Act and Verify
            Assert.IsFalse(_sellerListViewModel.NavigatoToInvoiceCommand.CanExecute(null));
        }
        public void NavigateToEditSellerCommand_When_Executed_Invoke_FindSellerById()
        {
            //Arrange
            _sellerListViewModel = new SellerListViewModel(_contextMock.Object, _navigationServiceMock.Object)
            {
                SelectedSeller = _personInformations.First()
            };

            //Act
            _sellerListViewModel.NavigateToEditSellerCommand.Execute(null);

            //Verify
            _contextMock.Verify(m=>m.People.GetSeller(It.IsAny<int>()),Times.Once);
        }
        public void NavigateToAddSellerCommand_When_Executed_Invoke_NavigateTo_With_SellerKey()
        {
            //Arrange
            _sellerListViewModel = new SellerListViewModel(_contextMock.Object, _navigationServiceMock.Object);

            //Act
            _sellerListViewModel.NavigateToAddSellerCommand.Execute(null);

            //Verify
            _navigationServiceMock.Verify(m => m.NavigateTo(ViewModelLocator.SellerKey, null), Times.Once);
        }
        public void DeleteSellerCommand_When_Executed_Send_Message_To_Update_Status_Bar()
        {
            //Arrange
            string receivedStatus = null;
            const string expectedStatus = "Sprzedawca usunięty";

            Messenger.Default.Register<StatusMessage>(this, MessengerToken.MainWindowVm, message =>
            {
                receivedStatus = message.NewStatus;
            });

            _sellerListViewModel = new SellerListViewModel(_contextMock.Object);

            var sellerToDelete = _personInformations.First();

            _sellerListViewModel.SelectedSeller = sellerToDelete;

            //Act
            _sellerListViewModel.DeleteSellerCommand.Execute(null);

            //Verify
            Assert.IsTrue(expectedStatus.Equals(receivedStatus));
        }
        public void DeleteSellerCommand_When_Executed_Removes_Seller_From_SellerList()
        {
            //Arrange
            _sellerListViewModel = new SellerListViewModel(_contextMock.Object);

            var sellerToDelete = _personInformations.First();

            _sellerListViewModel.SelectedSeller = sellerToDelete;

            //Act
            _sellerListViewModel.DeleteSellerCommand.Execute(null);

            //Verify
            Assert.IsTrue(_sellerListViewModel.SellerList.Count == 0);
        }