public void GigController_Should_Contain_Index_Method_Which_Accepts_GigID_And_Returns_A_Gig()
        {
            MockRepository mocks = new MockRepository();

            Guid gigId = Guid.NewGuid();
            Gig gig = new Gig();
            gig.ID = gigId;

            //Mock the GigManager
            IGigManager gigManager = mocks.DynamicMock<IGigManager>();
            GigController gigController = new GigController();
            gigController.GigManager = gigManager;

            Expect.Call(gigManager.GetByID(gigId))
                .Constraints(Is.Equal(gigId))
                .Repeat.Once()
                .Return(gig);

            mocks.ReplayAll();

            ViewResult result = (ViewResult)gigController.Index(gigId);
            Gig returnedData = (Gig)(result.ViewData.Model);

            mocks.VerifyAll();

            Assert.IsNotNull(returnedData);
            Assert.AreEqual(gig.ID, returnedData.ID);
        }
        public void GetById_Calls_GigDAO_Method_GetById_Once_And_Returns_A_Gig()
        {
            MockRepository mocks = new MockRepository();

            Guid gigId = Guid.NewGuid();
            Gig gig = new Gig();
            gig.ID = gigId;

            IGigDAO gigDAO = mocks.DynamicMock<IGigDAO>();
            GigManager gigManager = new GigManager();
            gigManager.GigDAO = gigDAO;

            Expect.Call(gigDAO.GetById(gigId))
               .Constraints(Is.Equal(gigId))
               .Repeat.Once()
               .Return(gig);

            mocks.ReplayAll();

            Gig result = gigManager.GetByID(gigId);

            mocks.VerifyAll();

            Assert.AreEqual(gig.ID, result.ID);
        }
Beispiel #3
0
        public void CanAddGig()
        {
            Guid gigId = new Guid();
            string gigName = "Seizures first gig";
            string gigDescription = "Seizures play their first gig in Manchester!";
            DateTime startDate = new DateTime();
            DateTime endDate = new DateTime();
            string gigTicketPrice = "£6";

            Guid actId = new Guid();
            string actName = "Seizures";

            Act act = new Act();
            act.ID = actId;
            act.Name = actName;

            Gig gig             = new Gig();
            gig.ID              = gigId;
            gig.Name            = gigName;
            gig.Description     = gigDescription;
            gig.StartDate       = startDate;
            gig.EndDate         = endDate;
            gig.TicketPrice     = gigTicketPrice;
            gig.Acts.Add(act);

            Assert.That(gig.ID,
               Is.EqualTo(gigId));
            Assert.That(gig.Name,
                Is.EqualTo(gigName));
            Assert.That(gig.Description,
                Is.EqualTo(gigDescription));
            Assert.That(gig.StartDate,
                Is.EqualTo(startDate));
            Assert.That(gig.EndDate,
                Is.EqualTo(endDate));
            Assert.That(gig.TicketPrice,
                Is.EqualTo(gigTicketPrice));
            Assert.That(gig.Acts.Count,
                Is.EqualTo(1));
        }
        private IList<Gig> CreateListOfGigs(int numGigs, DateTime startDate)
        {
            IList<Gig> gigs = new List<Gig>();

            for (int i = 0; i < numGigs; i++)
            {
                Guid gigId = Guid.NewGuid();
                Gig gig = new Gig();
                gig.ID = gigId;
                gig.StartDate = startDate;
                gigs.Add(gig);
            }

            return gigs;
        }
Beispiel #5
0
 public string ViewGigUrl(Gig gig)
 {
     return UrlHelper.RouteUrl(Routes.GIG, new { gigId = gig.ID });
 }
Beispiel #6
0
 public string EditGigUrl(Gig gig)
 {
     return UrlHelper.RouteUrl(Routes.GIG_EDIT, new { id = gig.ID });
 }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            HttpRequestBase request = controllerContext.HttpContext.Request;

            Gig gig = null;
            if (bindingContext.Model == null)
            {
                gig = new Gig();
                gig.ID = Guid.NewGuid();
            }
            else
            {
                gig = (Gig)bindingContext.Model;
            }

            gig.Name = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "Name");
            gig.Description = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "Description");

            int day = ModelBinderHelpers.GetValueAndUpdateModelState<int>(bindingContext, "day");
            int month = ModelBinderHelpers.GetValueAndUpdateModelState<int>(bindingContext, "month");
            int year = ModelBinderHelpers.GetValueAndUpdateModelState<int>(bindingContext, "year");
            int hour = ModelBinderHelpers.GetValueAndUpdateModelState<int>(bindingContext, "hour"); ;
            int minute = ModelBinderHelpers.GetValueAndUpdateModelState<int>(bindingContext, "minute");

            if (ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "amPm") == "pm")
            {
                hour = hour + 12;
            }

            DateTime startDateTime = new DateTime(year, month, day,hour,minute,0);
            gig.Created = DateTime.Now;
            gig.StartDate = startDateTime;

            Guid? venueId = ModelBinderHelpers.GetValueAndUpdateModelState<Guid?>(bindingContext, "SelectedVenue");

            Venue venue = null;
            string venueName = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "VenueName");

            if (venueId.HasValue && venueId.Value != Guid.Empty && venueName != string.Empty)
            {
                //The use has filled in both the venueName and selected a venue DOH!
                //Show an error message
                bindingContext.ModelState.AddModelBinderValidationError("SelectedVenue", ModelBinderValidationStateKeys.CANNOT_SPECIFY_VENUE_ID_AND_VENUE_NAME);

            }
            else if (venueId.HasValue && venueId.Value!=Guid.Empty)
            {
                venue = VenueManager.GetByID(venueId.Value);
                gig.Venue = venue;
            }
            else if (venueName!=string.Empty)
            {
                venue = new Venue();
                venue.ID = Guid.NewGuid();
                venue.Name = venueName;
                //Set to Manchester by default.
                //This will have to change before we open up to different cities
                venue.Town = TownManager.GetByID(new Guid("0D5A3A81-53C1-48B0-B176-A419ACBB2EE8"));
                gig.Venue = venue;

            }

            //Artist Ids
            string[] bandNames = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "ActNames").Split(new char[] { ',' });
            string[] bandIds = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "ArtistIds").Split(new char[] { ';' });

            gig.Acts = new List<Act>();
            Guid currentID;
            Artist currentArtist;
            bool exists = false;

            //Add the Artists that were explicitly selected to the acts collection
            foreach(string id in bandIds){

                if (ListenTo.Shared.Utility.Is.GUID(id))
                {
                    currentID = new Guid(id);

                    exists = ((List < Act > )gig.Acts).Exists(delegate(Act a)
                    {
                        return a.Artist.ID == currentID;
                    });

                    if(!exists) {
                        currentArtist = ArtistManager.GetByID(currentID);

                        //Ensure that the bandNames and bandIds are synchronised....
                        if (bandNames.Contains<string>(currentArtist.Name))
                        {
                            AddActToGig(gig, currentArtist,null);
                        }
                    }
                }
            }

            //Add the unknown bands to the acts collection
            foreach (string bandName in bandNames)
            {

                if (bandName!= null && bandName != string.Empty && bandName.Trim().Length!=0)
                {
                    exists = ((List<Act>)gig.Acts).Exists(delegate(Act a)
                    {
                        return a.Name == bandName;
                    });

                    if (!exists)
                    {
                        AddActToGig(gig, null, bandName);
                    }
                }
            }

            string ticketPrice = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "ticketPrice");
            gig.TicketPrice = ticketPrice;

            OwnershipHelpers.SetOwner((IOwnableDO)gig, controllerContext.HttpContext.User);

            return gig;
        }
        private void AddActToGig(Gig gig, Artist artist, string name)
        {
            Act currentAct = new Act();
            currentAct.ID = Guid.NewGuid();
            currentAct.GigId = gig.ID;
            if (artist!=null)
            {
                currentAct.Name = artist.Name;
                currentAct.Artist = artist;
            }
            else
            {
                currentAct.Name = name;
            }

            gig.Acts.Add(currentAct);
        }
Beispiel #9
0
        private void PrepareViewDataForEditAction(Gig gig)
        {
            SelectList days = SelectListHelper.CreateDays(1, 31, 1, gig.StartDate.Day);
            ViewData["days"] = days;

            SelectList months = SelectListHelper.CreateMonths(1, 12, 1, gig.StartDate.Month);
            ViewData["months"] = months;

            int minYear = DateTime.Now.Year - 50;
            if (gig.StartDate.Year < minYear) { minYear = gig.StartDate.Year; }

            SelectList years = SelectListHelper.CreateYears(minYear, DateTime.Now.Year + 10, 1, gig.StartDate.Year);
            ViewData["years"] = years;

            int hour = gig.StartDate.Hour;
            bool isPm = false;
            if (hour > 12)
            {
                hour = 12;
                isPm = true;
            }

            SelectList hours = SelectListHelper.CreateHours(1, 12, 1, hour);
            ViewData["hours"] = hours;

            int minute = (int)Math.Round(gig.StartDate.Minute / 5.0) * 5;

            SelectList minutes = SelectListHelper.CreateHours(0, 55, 5, minute);
            ViewData["minutes"] = minutes;

            SelectList amPm = SelectListHelper.CreateAmPm(isPm);
            ViewData["amPm"] = amPm;

            PrepareBandViewDataForAddAndEditActions(gig);

            Guid? venueId = null;
            if (gig.Venue != null)
            {
                venueId = gig.Venue.ID;
            }

            PrepareVenues(venueId);
        }
Beispiel #10
0
        private void PrepareBandViewDataForAddAndEditActions(Gig gig)
        {
            string bandNames = "";
            string bandIds = "";
            foreach (Act act in gig.Acts)
            {
                bandNames += act.Name.Trim() + ", ";
                if (act.Artist != null)
                {
                    bandIds += act.Artist.ID + ";";
                }
            }

            ViewData["ActNames"] = bandNames;
            ViewData["ArtistIds"] = bandIds;
        }
Beispiel #11
0
 public static string EditGigUrl(this HtmlHelper helper, Gig gig)
 {
     return IOCHelper.GetRouteHelpers().EditGigUrl(gig);
 }
 public RedirectToRouteResult RedirectToGig(Gig gig)
 {
     return RedirectToRoute(Routes.GIG, new { gigId = gig.ID });
 }