Inheritance: ViewModelBase
Ejemplo n.º 1
0
        public MainWindow()
        {
            this.InitializeComponent();

            this.viewModel = new CounterViewModel();
            this.Closing += this.viewModel.ViewClosing;
            this.Closed += this.viewModel.ViewClosed;

            this.DataContext = this.viewModel;
        }
        public void ClickingButton_IncrementsCurrentCountBy1()
        {
            //Arrange
            var vm = new CounterViewModel();

            //Act
            var before = vm.CurrentCount;

            vm.IncrementButtonClick();

            //Assert
            Assert.AreEqual(before + 1, vm.CurrentCount);
        }
Ejemplo n.º 3
0
 public HttpResponseMessage Post([FromBody] CounterViewModel cntVm)
 {
     if (!ModelState.IsValid || !_requestProcessor.Post(cntVm))
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
     else
     {
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, cntVm);
         response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = cntVm.Id }));
         return(response);
     }
 }
Ejemplo n.º 4
0
        public void ExecutingTheSaveCommandUpdatesTheChangesOnTheCounter()
        {
            var counter = new Counter {
                Value = 10, Name = "Name", Description = "Description"
            };
            var vm = new CounterViewModel(counter, _mockDatabaseHelper.Object, _mockDialogService.Object, _mockNavigationService.Object);

            vm.Name        = "New Name";
            vm.Description = "New Description";
            vm.SaveCommand.Execute(null);
            counter.Name.Should().Be("New Name");
            counter.Description.Should().Be("New Description");
        }
Ejemplo n.º 5
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         HttpStatusCode   httpStatusCode;
         CounterViewModel feedbackviewmodel = _requestProcessor.Delete(id, out httpStatusCode);
         return(Request.CreateResponse(HttpStatusCode.OK, feedbackviewmodel));
     }
     catch (DbUpdateConcurrencyException ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
     }
 }
Ejemplo n.º 6
0
        public void StartCountingTest()
        {
            var target         = new CounterViewModel();
            var countCompleted = new AutoResetEvent(false);

            target.CountCompleted += () => countCompleted.Set();

            target.CountTo = 5;
            target.StartCounting();

            Assert.IsTrue(countCompleted.WaitOne(1000));
            Assert.AreEqual(target.CountTo, target.CurrentCount, "Count did not complete");
        }
        public void BindCounterViewModel(CounterViewModel counterViewModel)
        {
            if (_counterViewModel != null)
            {
                _counterViewModel.PropertyChanged -= CounterViewModelOnPropertyChanged;
            }

            _counterViewModel = counterViewModel;
            _counterViewModel.PropertyChanged += CounterViewModelOnPropertyChanged;

            _name.Text        = counterViewModel.Name;
            _description.Text = counterViewModel.Description;
            _value.Text       = counterViewModel.Value;
        }
Ejemplo n.º 8
0
        public ActionResult Index(CounterViewModel mdl)
        {
            if (ModelState.IsValid)
            {
                if (mdl.Counter < 10)
                {
                    mdl.Counter = mdl.Counter + 1;
                    DataService.DataSrvc.StoreCounter(mdl);
                }

                return(RedirectToAction("Index"));
            }

            return(View());
        }
Ejemplo n.º 9
0
        public ActionResult Counter()
        {
            var lastrecord = _dbcontext.Counters.OrderByDescending(x => x.Count).FirstOrDefault();
            var result     = new CounterViewModel();

            if (lastrecord != null)
            {
                result.Count = lastrecord.Count.Value;
            }
            else
            {
                result.Count = 0;
            }
            return(View(result));
        }
        public void ResetTest()
        {
            var vm = new CounterViewModel();

            Assert.AreEqual("last value: ---", vm.Title.Value);
            Assert.AreEqual("0", vm.CounterValue.Value);
            vm.Increment.Execute();
            vm.Increment.Execute();
            vm.Increment.Execute();
            Assert.AreEqual("last value: ---", vm.Title.Value);
            Assert.AreEqual("3", vm.CounterValue.Value);
            vm.Reset.Execute();
            Task.Delay(2000).Wait();
            Assert.AreEqual("last value: 3", vm.Title.Value);
            Assert.AreEqual("0", vm.CounterValue.Value);
        }
        public void DecrementTest()
        {
            var vm = new CounterViewModel();

            Assert.AreEqual("0", vm.CounterValue.Value);
            vm.Decrement.Execute();
            Assert.AreEqual("-1", vm.CounterValue.Value);
            vm.Decrement.Execute();
            Assert.AreEqual("-2", vm.CounterValue.Value);
            vm.Decrement.Execute();
            Assert.AreEqual("-3", vm.CounterValue.Value);
            vm.Decrement.Execute();
            Assert.AreEqual("-4", vm.CounterValue.Value);
            vm.Decrement.Execute();
            Assert.AreEqual("-5", vm.CounterValue.Value);
        }
Ejemplo n.º 12
0
        public async Task <ActionResult <int> > UpdateCounter(CounterViewModel counter)
        {
            var response = await _service.UpdateCounter(counter);

            if (response.Status == ServiceResponseStatus.NotFound)
            {
                return(NotFound(response.Result));
            }

            if (response.Status == ServiceResponseStatus.Ok && response.Result is int result)
            {
                return(result);
            }

            return(BadRequest(response.Result));
        }
Ejemplo n.º 13
0
        public ActionResult Counter(CounterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            model.Count += 1;

            _dbcontext.Counters.Add(new Counter
            {
                Count = model.Count
            });
            _dbcontext.SaveChanges();

            return(RedirectToAction("Counter"));
        }
Ejemplo n.º 14
0
        public void Get_CounterControllerGetCounter_Counter1Equal0()
        {
            //arrange
            Counter counter = new Counter()
            {
                CounterID = 1,
                Name      = "Name 1",
                Counter1  = 0
            };

            _counterRepositoryMock.Setup(x => x.GetCounterByID(1)).Returns(counter);

            //act
            CounterViewModel viewModel = _counterController.Get();

            //assert
            Assert.IsTrue(viewModel.Counter1 == 0);
        }
Ejemplo n.º 15
0
        public ActionResult Index()
        {
            int number;

            if (Request.Cookies["number"] != null)
            {
                number = int.Parse(Request.Cookies["number"].Value);
            }
            else
            {
                number = 1;
            }
            Response.Cookies.Add(new HttpCookie("number", $"{number + 1}"));
            CounterViewModel viewModel = new CounterViewModel();

            viewModel.Number = number;
            return(View(viewModel));
        }
Ejemplo n.º 16
0
        public void Get_CounterControllerAddWithID_Add1ToCounterEquals1()
        {
            //arrange
            Counter counter = new Counter()
            {
                CounterID = 1,
                Name      = "Name 1",
                Counter1  = 1
            };

            _counterRepositoryMock.Setup(x => x.GetCounterByID(1)).Returns(counter);
            _counterRepositoryMock.Setup(x => x.AddToCounterByID(1, 1)).Returns(counter);

            //act
            CounterViewModel viewModel = _counterController.Get(1);

            //assert
            Assert.IsTrue(viewModel.Counter1 == 1);
        }
Ejemplo n.º 17
0
        public void CancelCountingTest()
        {
            var target        = new CounterViewModel();
            var countStarted  = new AutoResetEvent(false);
            var countCanceled = new AutoResetEvent(false);

            target.CountStarted  += () => countStarted.Set();
            target.CountCanceled += () => countCanceled.Set();

            target.CountTo = 5;
            target.StartCounting();

            Assert.IsTrue(countStarted.WaitOne(1000));

            target.CancelCounting();

            Assert.IsTrue(countCanceled.WaitOne(1000));
            Assert.AreNotEqual(target.CountTo, target.CurrentCount, "Count finished - did not cancel");
        }
Ejemplo n.º 18
0
        public PartialViewResult AllCategories()
        {
            List <CounterViewModel> CmList = new List <CounterViewModel>();

            List <CategoryDTO> catList = CategoryUIService.TumListe();

            foreach (CategoryDTO item in catList)
            {
                CounterViewModel cm = new CounterViewModel()
                {
                    KategoriAdi            = item.NameCategoryDto,
                    KategoridekiPostSayisi = item.PostDtoList.Count(),
                    CatId           = item.CategoryDtoId,
                    KategoriSeoLink = item.SeoCategoryDTO,
                    CatDesc         = item.DescriptionCategoryDto
                };
                CmList.Add(cm);
            }
            return(PartialView(CmList));
        }
Ejemplo n.º 19
0
        public void StatusTest()
        {
            var target         = new CounterViewModel();
            var countStarted   = new AutoResetEvent(false);
            var countCompleted = new AutoResetEvent(false);

            target.CountStarted   += () => countStarted.Set();
            target.CountCompleted += () => countCompleted.Set();
            var expected = new[]
            {
                "Count Started",
                "Count is 1",
                "Count Completed"
            };
            var actual = new string[3];
            var index  = 0;
            var propertyChangedNotified = false;

            target.PropertyChanged += (o, e) =>
            {
                if (e.PropertyName == "Status")
                {
                    actual[index] = ((CounterViewModel)o).Status;
                    Assert.AreEqual(expected[index], actual[index]);
                    index++;
                    propertyChangedNotified = true;
                }
            };

            Assert.AreEqual("Ready!", target.Status);

            target.CountTo = 1;
            target.StartCounting();

            Assert.IsTrue(countCompleted.WaitOne(1000));

            // Verify that the PropertyChanged event was fired
            Assert.IsTrue(propertyChangedNotified);
            Assert.AreEqual(3, index);
        }
Ejemplo n.º 20
0
        public void CanStartCountingTest()
        {
            var target         = new CounterViewModel();
            var countStarted   = new AutoResetEvent(false);
            var countCompleted = new AutoResetEvent(false);

            target.CountStarted   += () => countStarted.Set();
            target.CountCompleted += () => countCompleted.Set();

            Assert.IsTrue(target.CanStartCounting(), "Start command is not enabled");

            target.CountTo = 5;
            target.StartCounting();

            Assert.IsTrue(countStarted.WaitOne(1000));

            Assert.IsFalse(target.CanStartCounting(), "Start command is not disabled");

            Assert.IsTrue(countCompleted.WaitOne(1000));

            Assert.IsTrue(target.CanStartCounting(), "Start command is not enabled");
        }
Ejemplo n.º 21
0
        public IActionResult Index(CounterAction action, CounterViewModel model)
        {
            this.ValidateCounter(model);
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            switch (action)
            {
            case CounterAction.Increase:
                model.Actions.Add(action);
                model.CurrentCount++;
                this.ModelState.Remove("CurrentCount");
                return(this.View(model));

            case CounterAction.Finish:
                return(this.View("Result", model));

            default:
                throw new ArgumentOutOfRangeException(nameof(action), action, null);
            }
        }
Ejemplo n.º 22
0
        public async Task <ServiceResponse> UpdateCounter(CounterViewModel model)
        {
            _logger.LogInformation(@$ "{_serviceName} Update {nameof(Counter)}", model);
            _context.Entry(model).State = EntityState.Modified;
            _logger.LogInformation(@$ "{_serviceName} Update {nameof(Counter)} complete", model);

            var resultUpdate = await _context.SaveChangesAsync();

            if (resultUpdate == 1)
            {
                return(new ServiceResponse()
                {
                    Status = ServiceResponseStatus.Ok,
                    Result = resultUpdate
                });
            }

            return(new ServiceResponse()
            {
                Status = ServiceResponseStatus.NotFound,
                Result = $"Update {nameof(Counter)} id={model.Id} not found"
            });
        }
Ejemplo n.º 23
0
        public void IsCountingTest()
        {
            var target         = new CounterViewModel();
            var countStarted   = new AutoResetEvent(false);
            var countCompleted = new AutoResetEvent(false);

            target.CountStarted   += () => countStarted.Set();
            target.CountCompleted += () => countCompleted.Set();
            var actual                  = new bool[2];
            var actualIndex             = 0;
            var propertyChangedNotified = false;

            target.PropertyChanged += (o, e) =>
            {
                if (e.PropertyName == "IsCounting")
                {
                    actual[actualIndex] = ((CounterViewModel)o).IsCounting;
                    actualIndex++;
                    propertyChangedNotified = true;
                }
            };

            const int expected = 1;

            target.CountTo = expected;
            target.StartCounting();

            Assert.IsTrue(countStarted.WaitOne(1000));
            // IsCounting will be updated twice, true at start, then false when done
            Assert.IsTrue(actual[0]);

            Assert.IsTrue(countCompleted.WaitOne(1000));
            Assert.IsFalse(actual[1]);

            // Verify that the PropertyChanged event was fired
            Assert.IsTrue(propertyChangedNotified);
        }
 public CounterView()
 {
     ViewModel = new CounterViewModel();
 }
 public void Bind(CounterViewModel viewModel)
 {
 }
Ejemplo n.º 26
0
 public CounterPage()
 {
     InitializeComponent();
     BindingContext = new CounterViewModel();
 }
Ejemplo n.º 27
0
 public void SetUp()
 {
     mockCountersService = new Mock <ICountersService>();
     viewModel           = new CounterViewModel(mockCountersService.Object);
     viewModel.ShouldAlwaysRaiseInpcOnUserInterfaceThread(false);
 }
Ejemplo n.º 28
0
        public IActionResult Index()
        {
            var model = new CounterViewModel();

            return(this.View(model));
        }
Ejemplo n.º 29
0
        public ActionResult Index()
        {
            CounterViewModel counterModel = DataService.DataSrvc.GetCounter();;

            return(View(counterModel));
        }
Ejemplo n.º 30
0
 public void UpdateCounterIndicators(int id, [FromBody] CounterViewModel cntVm)
 {
     _counter.UpdateCounterIndicators(id, cntVm);
 }
Ejemplo n.º 31
0
 public void AddCounter([FromBody] CounterViewModel cntVm)
 {
     _counter.AddCounter(cntVm);
 }