public void GetTarget_WithId1_ReturnsFirst_ElementsHaveSameId() { var data = new List <Target> { new Target { Id = 1, Name = "test1", IsActive = false }, new Target { Id = 1, Name = "test2", IsActive = false } }; var mockSet = new MoqDbSet <Target>(data); var mockContext = new MoqContext <Target>(mockSet, m => m.Targets); var service = new TargetsService(mockContext.Object); Assert.AreEqual("test1", service.GetTarget(1).Name); }
public void DeleteTarget_DeletesItem_InAllCases() { var data = new List <Target> { new Target { Id = 1, Name = "test1", IsActive = false } }; var mockSet = new MoqDbSet <Target>(data); var mockContext = new MoqContext <Target>(mockSet, m => m.Targets); var service = new TargetsService(mockContext.Object); var item = new Target { Id = 1, Name = "test1", IsActive = true }; service.DeleteTarget(item); mockContext.Verify(m => m.SetEntityStateDeleted(item), Times.Once); mockContext.Verify(m => m.SaveChanges(), Times.Once); }
public void UpdateTarget_DoesNotChangeItem_IfItemWithSameNameExists() { var data = new List <Target> { new Target { Id = 1, Name = "test1", IsActive = false } }; var mockSet = new MoqDbSet <Target>(data); var mockContext = new MoqContext <Target>(mockSet, m => m.Targets); var service = new TargetsService(mockContext.Object); var item = new Target { Id = 2, Name = "test1", IsActive = true }; service.UpdateTarget(item); mockContext.Verify(m => m.SaveChanges(), Times.Never); }
public void IsTargetExists_ReturnsFalse_IfSameNames_And_SameIds() { var data = new List <Target> { new Target { Id = 1, Name = "test1", IsActive = false } }; var mockSet = new MoqDbSet <Target>(data); var mockContext = new MoqContext <Target>(mockSet, m => m.Targets); var service = new TargetsService(mockContext.Object); var item = new Target { Id = 1, Name = "test1", IsActive = false }; Assert.AreEqual(false, service.IsTargetExists(item)); }
public void GetAllTargets_ReturnsThree_FromSetOfThree() { var data = new List <Target> { new Target { Id = 1, Name = "test1", IsActive = false }, new Target { Id = 2, Name = "test2", IsActive = false }, new Target { Id = 3, Name = "test3", IsActive = false } }; var mockSet = new MoqDbSet <Target>(data); mockSet.Setup(x => x.AsNoTracking()).Returns(mockSet.Object); var mockContext = new MoqContext <Target>(mockSet, m => m.Targets); var service = new TargetsService(mockContext.Object); var targets = service.GetAllTargets(); Assert.AreEqual(3, targets.Count()); }
public TargetsPage() { InitializeComponent(); HandleReceivedMessages(); NavigationPage.SetBackButtonTitle(this, ""); ShowUpcoming(); _targetService = new TargetsService(); TargetFooter.SetRewardLevelIcon(Global.GetrewardPoints()); }
public TargetsViewModel() { _targetService = new TargetsService(); if (CrossConnectivity.Current.IsConnected) { var allTargets = _targetService.GetTargetsTrial(); _currentTargets = allTargets.Where(e => e.TargetDate.Year >= DateTime.Now.Year && e.TargetDate.Month >= DateTime.Now.Month).Select(e => e).ToList(); NotifyPropertyChanged("CurrentTargets"); _previousTargets = allTargets.Where(e => e.TargetDate.Year <= DateTime.Now.Year && e.TargetDate.Month < DateTime.Now.Month).Select(e => e).ToList(); NotifyPropertyChanged("PreviousTargets"); } }
public void GetTarget_WithId2_ReturnsNull_ElementDoesNotExist() { var data = new List <Target> { new Target { Id = 1, Name = "test1", IsActive = false } }; var mockSet = new MoqDbSet <Target>(data); var mockContext = new MoqContext <Target>(mockSet, m => m.Targets); var service = new TargetsService(mockContext.Object); Assert.AreEqual(null, service.GetTarget(2)); }
public void CreateTarget_AddsTarget() { var item = new Target { Id = 1, Name = "test1", IsActive = false }; var mockSet = new MoqDbSet <Target>(); var mockContext = new MoqContext <Target>(mockSet, m => m.Targets); var service = new TargetsService(mockContext.Object); service.CreateTarget(item); mockContext.Verify(m => m.SetEntityStateAdded(It.IsAny <Target>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
public void GetTarget_WithId1_ReturnsNull_IfDbSetIsEmpty() { var data = new List <Target> { new Target { Id = 1, Name = "test1", IsActive = false } }; var mockSet = new MoqDbSet <Target>(data); var mockContext = new MoqContext <Target>(mockSet, m => m.Targets); var service = new TargetsService(mockContext.Object); Assert.AreEqual(1, service.GetTarget(1).Id); }