public void UpdateDateAsString()
        {
            var requestDialog = new RequestDialogViewModel(Application, 2014, 6, o => { });

            requestDialog.DateProperty.Value = requestDialog.DateProperty.Value + TimeSpan.FromDays(1);
            Assert.That(requestDialog.DateAsString, Is.EqualTo(string.Format(Properties.Resources.RequestDayOfMonthFormat, new DateTime(2014, 6, 2))));
        }
        public void Validates(double value, bool isValid)
        {
            var requestDialog = new RequestDialogViewModel(Application, 2014, 6, d => { });
            requestDialog.ValueProperty.Value = value;

            Assert.That(requestDialog.CreateRequestCommand.IsEnabled, Is.EqualTo(isValid));
            Assert.That(requestDialog.ValueProperty.IsValid, Is.EqualTo(isValid));
        }
        public void CreateRequestCommandCallsAction()
        {
            var action = Substitute.For<Action<RequestDialogViewModel>>();
            var requestDialog = new RequestDialogViewModel(Application, 2014, 6, action);

            requestDialog.CreateRequestCommand.Execute(null);
            action.Received(1).Invoke(requestDialog);
        }
        private void OnAddRequestCommand()
        {
            var viewModel = new RequestDialogViewModel(Application, Year, Month, OnCreateRequest)
            {
                Caption = Properties.Resources.RequestDialogCaptionCreate
            };

            Application.WindowManager.ShowDialog(viewModel);
        }
        public void ChangeValueUpdatesCalculatedValue()
        {
            var requestDialog = new RequestDialogViewModel(Application, 2014, 6, o => { });
            requestDialog.RequestKind.Value = RequestKind.Expenditure;
            requestDialog.ValueProperty.Value = 2;
            requestDialog.ValueProperty.Value = 20;

            Assert.That(requestDialog.CalculateValue, Is.EqualTo(-20.0));
        }
 public void InitialState(int year, int month)
 {
     var requestDialog = new RequestDialogViewModel(Application, year, month, d => { });
     Assert.That(requestDialog.FirstPossibleDate, Is.EqualTo(new DateTime(year, month, 1)));
     Assert.That(requestDialog.LastPossibleDate, Is.EqualTo(new DateTime(year, month, DateTime.DaysInMonth(year, month))));
     Assert.That(requestDialog.DateProperty.Value, Is.EqualTo(new DateTime(year, month, 1)));
     Assert.That(requestDialog.CreateRequestCommand.IsEnabled, Is.False);
     Assert.That(requestDialog.DateAsString, Is.EqualTo(string.Format(Properties.Resources.RequestDayOfMonthFormat, new DateTime(year, month, 1))));
     Assert.That(requestDialog.ValueProperty.Value, Is.EqualTo(0.0d));
 }
        private void OnEditRequestCommand()
        {
            var currentRequest = Requests.Value;

            var viewModel = new RequestDialogViewModel(Application, currentRequest.EntityId, OnEditRequest)
            {
                Caption = Properties.Resources.RequestDialogCaptionEdit
            };

            Application.WindowManager.ShowDialog(viewModel);
        }
        private void OnCreateRequest(RequestDialogViewModel requestDialog)
        {
            var requestEntityId = Application.Repository.CreateRequest(new RequestEntityData
            {
                Date                 = requestDialog.DateProperty.Value,
                Description          = requestDialog.DescriptionProperty.Value,
                Value                = requestDialog.CalculateValue,
                CategoryPersistentId = requestDialog.Categories.Value != null ? requestDialog.Categories.Value.EntityId : null
            });

            var requestViewModel = new RequestViewModel(Application, requestEntityId);

            requestViewModel.Refresh();
            Requests.AddValue(requestViewModel);
            UpdateSaldoForCurrentMonth();
        }
        private void OnEditRequest(RequestDialogViewModel requestDialog)
        {
            var currentRequestEntityId = Requests.Value.EntityId;
            var requestEntityData      = new RequestEntityData
            {
                Date                 = requestDialog.DateProperty.Value,
                Description          = requestDialog.DescriptionProperty.Value,
                Value                = requestDialog.CalculateValue,
                CategoryPersistentId = requestDialog.Categories.Value != null ? requestDialog.Categories.Value.EntityId : null
            };

            Application.Repository.UpdateRequest(currentRequestEntityId, requestEntityData);

            Requests.Value.Refresh();
            UpdateSaldoForCurrentMonth();
        }
        private void OnEditRequestCommand()
        {
            var currentRequest = Requests.Value;

            var viewModel = new RequestDialogViewModel(Application, currentRequest.EntityId, OnEditRequest)
            {
                Caption = Properties.Resources.RequestDialogCaptionEdit
            };
            Application.WindowManager.ShowDialog(viewModel);
        }
        private void OnEditRequest(RequestDialogViewModel requestDialog)
        {
            var currentRequestEntityId = Requests.Value.EntityId;
            var requestEntityData = new RequestEntityData
            {
                Date = requestDialog.DateProperty.Value,
                Description = requestDialog.DescriptionProperty.Value,
                Value = requestDialog.CalculateValue,
                CategoryPersistentId = requestDialog.Categories.Value != null ? requestDialog.Categories.Value.EntityId : null
            };
            Application.Repository.UpdateRequest(currentRequestEntityId, requestEntityData);

            Requests.Value.Refresh();
            UpdateSaldoForCurrentMonth();
        }
        private void OnCreateRequest(RequestDialogViewModel requestDialog)
        {
            var requestEntityId = Application.Repository.CreateRequest(new RequestEntityData
            {
                Date = requestDialog.DateProperty.Value,
                Description = requestDialog.DescriptionProperty.Value,
                Value = requestDialog.CalculateValue,
                CategoryPersistentId = requestDialog.Categories.Value != null ? requestDialog.Categories.Value.EntityId : null
            });

            var requestViewModel = new RequestViewModel(Application, requestEntityId);
            requestViewModel.Refresh();
            Requests.AddValue(requestViewModel);
            UpdateSaldoForCurrentMonth();
        }
 private void OnAddRequestCommand()
 {
     var viewModel = new RequestDialogViewModel(Application, Year, Month, OnCreateRequest)
     {
         Caption = Properties.Resources.RequestDialogCaptionCreate
     };
     Application.WindowManager.ShowDialog(viewModel);
 }