コード例 #1
0
        public void GetMeetsWithVenueName()
        {
            //Setup
            var listOfMeets = new List <Meet>
            {
                new Meet()
                {
                    MeetDate   = DateTime.Now,
                    MeetName   = "Test Meet 1",
                    MeetId     = 1,
                    MeetVenue  = "Test Venue 1",
                    PoolLength = "11"
                },
                new Meet()
                {
                    MeetDate   = DateTime.Now,
                    MeetName   = "Test Meet 2",
                    MeetId     = 2,
                    MeetVenue  = "Test Venue 1",
                    PoolLength = "21"
                }
            };
            var mockMeetsRepo = new Mock <IMeetRepo>();

            mockMeetsRepo.Setup(MMR => MMR.GetMeets("Test Venue 1")).Returns(listOfMeets);
            var sut = new MeetsController(mockMeetsRepo.Object);

            //Action
            var res = sut.GetMeets("Test Venue 1");

            //Assert
            res.Should().BeOfType <OkNegotiatedContentResult <List <Meet> > >();
            res.As <OkNegotiatedContentResult <List <Meet> > >().Content.Should().BeEquivalentTo(listOfMeets);
        }
コード例 #2
0
        public void GetMeetsFormattedByStartAndEndDateReturnsMeetsWithinStartAndEndDate()
        {
            //Setup
            var listOfMeets = new List <Meet>
            {
                new Meet()
                {
                    MeetDate   = new DateTime(2019, 04, 14),
                    MeetName   = "Test Meet 1",
                    MeetId     = 1,
                    MeetVenue  = "Test Venue 1",
                    PoolLength = "11"
                },
                new Meet()
                {
                    MeetDate   = new DateTime(2019, 04, 13),
                    MeetName   = "Test Meet 2",
                    MeetId     = 2,
                    MeetVenue  = "Test Venue 1",
                    PoolLength = "21"
                }
            };
            var mockMeetsRepo = new Mock <IMeetRepo>();

            mockMeetsRepo.Setup(MMR => MMR.GetMeets(new DateTime(2019, 04, 12), new DateTime(2019, 04, 15))).Returns(listOfMeets);
            var sut = new MeetsController(mockMeetsRepo.Object);

            //Action
            var res = sut.GetMeetsFormatted(new DateTime(2019, 04, 12), new DateTime(2019, 04, 15));

            //Assert
            res.Should().BeOfType <OkNegotiatedContentResult <List <string> > >();
            res.As <OkNegotiatedContentResult <List <string> > >().Content.Should().BeEquivalentTo(FormatMeets(listOfMeets));
        }
コード例 #3
0
        public void ReturnSpecificMeet_NotFound()
        {
            var controller = new MeetsController(new FakeMeetRepository(false));

            IHttpActionResult actionResult = controller.GetMeet(-1);

            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
コード例 #4
0
        public void ReturnSpecificMeet_Ok()
        {
            var controller = new MeetsController(new FakeMeetRepository());

            IHttpActionResult actionResult = controller.GetMeet(3);

            Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <Meet>));
        }
コード例 #5
0
        public void GetMeets()
        {
            var controller = new MeetsController(new FakeMeetRepository());

            var result = controller.GetMeets();

            Assert.IsInstanceOfType(result, typeof(List <Meet>));
        }
コード例 #6
0
        public void PostMeet_Invalid()
        {
            var controller = new MeetsController(new FakeMeetRepository());

            controller.ModelState.AddModelError("Date", "Date format could not be parsed");

            MeetViewModel m = new MeetViewModel
            {
                DateString = ""
            };

            Assert.IsInstanceOfType(controller.PostMeet(m), typeof(InvalidModelStateResult));
        }
コード例 #7
0
        public void AddMeetInvalidSwimmingLengthResultsInBadRequest()
        {
            //Setup
            var mockMeetRepo = new Mock <IMeetRepo>();
            var meet         = new AddMeetModel();
            var sut          = new MeetsController(mockMeetRepo.Object);

            //Action
            var res = sut.AddMeet(meet);

            //assert
            res.Should().BeOfType <BadRequestErrorMessageResult>();
            res.As <BadRequestErrorMessageResult>().Message.Should().Be("Pool Length must match the neutral file format code");
        }
コード例 #8
0
        public void PostMeet_Valid()
        {
            var controller = new MeetsController(new FakeMeetRepository());

            MeetViewModel m = new MeetViewModel
            {
                Name       = "Unit Test Meet",
                Venue      = "Unit Test Venue",
                PoolLength = "150m",
                DateString = "21 September 2021"
            };

            Assert.IsInstanceOfType(controller.PostMeet(m), typeof(CreatedAtRouteNegotiatedContentResult <Meet>));
        }
コード例 #9
0
        public void AddMeetInvalidModelLengthResultsInInvalidModelStateResult()
        {
            //Setup
            var mockMeetRepo = new Mock <IMeetRepo>();
            var meet         = new AddMeetModel();
            var sut          = new MeetsController(mockMeetRepo.Object);

            sut.ModelState.AddModelError("MeetVenue", "Meet venue is required");

            //Action
            var res = sut.AddMeet(meet);

            //assert
            res.Should().BeOfType <InvalidModelStateResult>();
            res.As <InvalidModelStateResult>().ModelState.IsValid.Should().BeFalse();
        }
コード例 #10
0
        public void UpdateMeetInvalidModelReturnsInvalidModelStateResult()
        {
            //Setup
            var mockMeetsRepo = new Mock <IMeetRepo>();
            var meet          = new Meet();
            var sut           = new MeetsController(mockMeetsRepo.Object);

            sut.ModelState.AddModelError("MeetName", "MeetName is required");

            //action
            var res = sut.UpdateMeet(meet);

            //assert
            res.Should().BeOfType <InvalidModelStateResult>();
            res.As <InvalidModelStateResult>().ModelState.IsValid.Should().BeFalse();
        }
コード例 #11
0
        public void UpdateMeetPoolLengthNotValidReturnsBadRequest()
        {
            //Setup
            var mockMeetsRepo = new Mock <IMeetRepo>();
            var meet          = new Meet()
            {
                PoolLength = "1000"
            };
            var sut = new MeetsController(mockMeetsRepo.Object);


            //action
            var res = sut.UpdateMeet(meet);

            //assert
            res.Should().BeOfType <BadRequestErrorMessageResult>();
            res.As <BadRequestErrorMessageResult>().Message.Should().Be("Pool Length must match the neutral file format code");
        }
コード例 #12
0
        private bool CreateMeet(Meet newMeet)
        {
            MeetsController meetController = new MeetsController();

            var response = meetController.AddMeet(newMeet);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                // Success!
                MessageBox.Show(newMeet.MeetName + " successfully added", "Success",
                                MessageBoxButton.OK, MessageBoxImage.None);
                return(true);
            }
            else
            {
                MessageBox.Show("Failed to add " + newMeet.MeetName + ": "
                                + response.StatusCode.ToString(), "Failure",
                                MessageBoxButton.OK, MessageBoxImage.None);
                return(false);
            }
        }
コード例 #13
0
        public void UpdateMeetValidMeetAndDbSuccessfulReturnsOk()
        {
            //Setup
            var mockMeetsRepo = new Mock <IMeetRepo>();
            var meet          = new Meet()
            {
                MeetDate   = new DateTime(),
                MeetName   = "Test Meet",
                MeetId     = 1,
                MeetVenue  = "Test Venue",
                PoolLength = "11"
            };

            mockMeetsRepo.Setup(MMR => MMR.UpdateMeet(meet)).Returns(true);
            var sut = new MeetsController(mockMeetsRepo.Object);

            //Action
            var res = sut.UpdateMeet(meet);

            //Assert
            res.Should().BeOfType <OkResult>();
        }
コード例 #14
0
        public void AddMeetValidMeetAndSuccessfulAddToDbReturnsOk()
        {
            //Setup
            var mockMeetRepo = new Mock <IMeetRepo>();

            var meet = new AddMeetModel()
            {
                MeetDate   = new DateTime(),
                MeetName   = "Test Meet Name",
                MeetVenue  = "Test Meet Venue",
                PoolLength = "11"
            };

            mockMeetRepo.Setup(mMR => mMR.AddMeet(meet)).Returns(true);
            var sut = new MeetsController(mockMeetRepo.Object);

            //Action
            var res = sut.AddMeet(meet);

            //assert
            res.Should().BeOfType <OkResult>();
        }
コード例 #15
0
        private bool EditMeet(Meet meet)
        {
            bool            success  = false;
            MeetsController mc       = new MeetsController();
            var             response = mc.EditMeet(meet);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                // Success!
                MessageBox.Show("Edit succeeded", "Success",
                                MessageBoxButton.OK, MessageBoxImage.None);
                success = true;
            }
            else
            {
                MessageBox.Show("Edit failed" +
                                response.StatusCode.ToString(), "Failure",
                                MessageBoxButton.OK, MessageBoxImage.None);
            }

            return(success);
        }
コード例 #16
0
        private bool DeleteMeet(Meet meet)
        {
            bool            success  = false;
            MeetsController mc       = new MeetsController();
            var             response = mc.DeleteMeet(meet);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                // Success!
                MessageBox.Show(meet.MeetName + " successfully deleted", "Success",
                                MessageBoxButton.OK, MessageBoxImage.None);
                success = true;
            }
            else
            {
                MessageBox.Show("Deletion failed: " +
                                response.StatusCode.ToString(), "Failure",
                                MessageBoxButton.OK, MessageBoxImage.None);
            }

            return(success);
        }
コード例 #17
0
        public void AddMeetValidMeetAndUnSuccessfulAddToDbReturnsBadRequestErrorMessage()
        {
            //Setup
            var mockMeetRepo = new Mock <IMeetRepo>();

            var meet = new AddMeetModel()
            {
                MeetDate   = new DateTime(),
                MeetName   = "Test Meet Name",
                MeetVenue  = "Test Meet Venue",
                PoolLength = "11"
            };

            mockMeetRepo.Setup(mMR => mMR.AddMeet(meet)).Returns(false);
            var sut = new MeetsController(mockMeetRepo.Object);

            //Action
            var res = sut.AddMeet(meet);

            //assert
            res.Should().BeOfType <BadRequestErrorMessageResult>();
            res.As <BadRequestErrorMessageResult>().Message.Should().Be("Not able to add meet to db");
        }
コード例 #18
0
        public void UpdateMeetValidMeetAndDbUnSuccessfulReturnsBadRequest()
        {
            //Setup
            var mockMeetsRepo = new Mock <IMeetRepo>();
            var meet          = new Meet()
            {
                MeetDate   = new DateTime(),
                MeetName   = "Test Meet",
                MeetId     = 1,
                MeetVenue  = "Test Venue",
                PoolLength = "11"
            };

            mockMeetsRepo.Setup(MMR => MMR.UpdateMeet(meet)).Returns(false);
            var sut = new MeetsController(mockMeetsRepo.Object);

            //Action
            var res = sut.UpdateMeet(meet);

            //Assert
            res.Should().BeOfType <BadRequestErrorMessageResult>();
            res.As <BadRequestErrorMessageResult>().Message.Should().Be("Meet failed to be updated");
        }