Ejemplo n.º 1
0
        public void GetAllSwimmersByStroke()
        {
            var data = new List <Child>
            {
                new Child
                {
                    DateOfBirth = DateTime.Parse("Jan 1, 2005"),//16
                    Family      = new Family {
                        FamilyId = 2
                    },
                    Firstname    = "Ben",
                    Lastname     = "Smith",
                    Gender       = "M",
                    Permission   = true,
                    Participants = new List <Participant>()
                    {
                        new Participant {
                            Event = new Event
                            {
                                Stroke = "Backstroke"
                            }
                        }
                    }
                },
                new Child
                {
                    DateOfBirth = DateTime.Parse("Jan 1, 2007"),//14
                    Family      = new Family {
                        FamilyId = 2
                    },
                    Firstname  = "Jade",
                    Lastname   = "Potter",
                    Gender     = "F",
                    Permission = true
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Child> >();

            mockSet.As <IQueryable <Child> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Child> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Child> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Child> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <DatabaseEntities>();

            mockContext.Setup(m => m.Children).Returns(mockSet.Object);

            var mock = new Mock <UrlHelper>();

            mock.Setup(m => m.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("https://localhost:44366/api/");

            var controller = new ChildrenController(mockContext.Object)
            {
                Url = mock.Object
            };
            var result = controller.GetChildrenByStroke("Backstroke");

            Assert.AreEqual(1, result.Count);
        }
Ejemplo n.º 2
0
        public void deleteSwimmer()
        {
            var data = new List <Child>
            {
                new Child
                {
                    ChildrenId = 1,
                    Family     = new Family {
                        FamilyId = 2
                    },
                    Participants = null,
                    DateOfBirth  = DateTime.Parse("Jan 1, 2005"),//16
                    Firstname    = "Ben",
                    FamilyId     = 2,
                    Lastname     = "Smith",
                    Gender       = "M",
                    Permission   = true
                },
                new Child
                {
                    ChildrenId  = 2,
                    DateOfBirth = DateTime.Parse("Jan 1, 2007"),//14
                    Family      = new Family {
                        FamilyId = 2
                    },
                    Firstname  = "Jade",
                    Lastname   = "Potter",
                    Gender     = "F",
                    Permission = true
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Child> >();

            mockSet.As <IQueryable <Child> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Child> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Child> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Child> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <DatabaseEntities>();

            mockContext.Setup(m => m.Children).Returns(mockSet.Object);

            var mock = new Mock <UrlHelper>();

            mock.Setup(m => m.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("https://localhost:44366/api/");

            var controller = new ChildrenController(mockContext.Object)
            {
                Url = mock.Object
            };

            var result = controller.DeleteChild(2);

            Assert.IsNotNull(result);
        }
        public void New_ReturnsCorrectActionType_ViewResult()
        {
            //Arrange
            ChildrenController controller = new ChildrenController();

            //Act
            IActionResult view = controller.New();

            //Assert
            Assert.IsInstanceOfType(view, typeof(ViewResult));
        }
Ejemplo n.º 4
0
        public void Controller_Children_Create_Post()
        {
            // Arrange
            ChildrenController controller = new ChildrenController();

            // Act
            ViewResult result = controller.Create() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Ejemplo n.º 5
0
        public void Controller_Children_Index_Get()
        {
            // Arrange
            ChildrenController controller = new ChildrenController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }