예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
        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());
        }
예제 #6
0
 public TargetsPage()
 {
     InitializeComponent();
     HandleReceivedMessages();
     NavigationPage.SetBackButtonTitle(this, "");
     ShowUpcoming();
     _targetService = new TargetsService();
     TargetFooter.SetRewardLevelIcon(Global.GetrewardPoints());
 }
예제 #7
0
 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");
     }
 }
예제 #8
0
        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));
        }
예제 #9
0
        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());
        }
예제 #10
0
        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);
        }