/// <summary>
        /// Maps the event definition into the the schedule view model.
        /// </summary>
        /// <param name="eventDefinition"></param>
        /// <returns></returns>
        public ScheduleViewModel Map(EventDefinition eventDefinition)
        {
            var times = GetTimes(eventDefinition);

            List<ScheduleSession> scheduleSessions =
                eventDefinition
                    .Sessions.Select(s =>
                                     new ScheduleSession
                                     {
                                         SessionId = s.SessionId,
                                         Title = s.Title,
                                         StartTime = DateTime.SpecifyKind(s.StartTime, DateTimeKind.Utc),
                                         Duration = s.Duration,
                                         RoomNumber = s.RoomNumber,
                                         Speaker = s.Speaker
                                     }).ToList();

            var scheduleEvent = new ScheduleEvent
                                    {
                                        EventDefinitionId = eventDefinition.EventDefinitionId,
                                        Rooms = eventDefinition.RoomNumber,
                                        Sessions = scheduleSessions
                                    };

            var viewModel = new ScheduleViewModel
            {
                EventDefinition = scheduleEvent,
                Times = times
            };
            return viewModel;
        }
        public void DeleteEventDefinition_NotFail_Test()
        {
            var expected = new EventDefinition() { Name = "EventName", EventDefinitionId = 1, OrganizerId = 1 };
            bool called = false;

            IEventDefinitionRepository eventDefinitionService = new StubIEventDefinitionRepository()
            {
                DeleteInt32 = (eventDefinitionId) =>
                {
                    Assert.AreEqual(expected.EventDefinitionId, eventDefinitionId);
                    called = true;
                },
                GetByIdInt32 = (id) =>
                {
                    Assert.IsTrue(id == 1);
                    return expected;
                }
            };

            using (ShimsContext.Create())
            {
                MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken();
                myeventToken.RegisteredUserIdGet = () => { return expected.OrganizerId; };
                ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; };

                var target = new EventDefinitionsController(eventDefinitionService);

                target.Delete(expected.EventDefinitionId);

                Assert.IsTrue(called);
            }
        }
        public void DeleteSession_UnauthorizedException_Test()
        {
            var expectedSession = new Session() { SessionId = 1, EventDefinitionId = 1 };

            var eventDefinition = new EventDefinition() { OrganizerId = 1 };
            IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository()
            {
                GetByIdInt32 = (id) =>
                {
                    Assert.AreEqual(expectedSession.EventDefinitionId, id);
                    return eventDefinition;
                }
            };

            ISessionRepository sessionRepository = new StubISessionRepository()
            {
                GetInt32 = (sessionId) =>
                {
                    Assert.AreEqual(expectedSession.SessionId, sessionId);
                    return expectedSession;
                }
            };

            using (ShimsContext.Create())
            {
                MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken();
                myeventToken.RegisteredUserIdGet = () => { return 10000; };
                ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; };

                var target = new SessionsController(sessionRepository, eventRepository);

                target.Delete(expectedSession.SessionId);
            }
        }
        public void DeleteEventDefinition_Deleted_NotFail_Test()
        {
            var context = new MyEventsContext();
            int organizerId = context.RegisteredUsers.FirstOrDefault().RegisteredUserId;

            var eventDef = new EventDefinition();
            eventDef.OrganizerId = organizerId;
            eventDef.Name = Guid.NewGuid().ToString();
            eventDef.Description = Guid.NewGuid().ToString();
            eventDef.Address = Guid.NewGuid().ToString();
            eventDef.City = Guid.NewGuid().ToString();
            eventDef.Tags = Guid.NewGuid().ToString();
            eventDef.TwitterAccount = Guid.NewGuid().ToString();
            eventDef.RoomNumber = 1;
            eventDef.Date = System.DateTime.Now;
            eventDef.StartTime = System.DateTime.Now;
            eventDef.TimeZoneOffset = 2;
            eventDef.EndTime = System.DateTime.Now.AddMinutes(1);
            eventDef.Likes = 0;
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            eventDef.Logo = encoding.GetBytes("sample");

            IEventDefinitionRepository target = new EventDefinitionRepository();
            target.Add(eventDef);

            var eventDefinition = context.EventDefinitions.FirstOrDefault();
            int expected = context.EventDefinitions.Count() - 1;

            target.Delete(eventDef.EventDefinitionId);

            int actual = context.EventDefinitions.Count();

            Assert.AreEqual(expected, actual);
        }
 /// <summary>
 /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
 /// </summary>
 /// <param name="eventDefinition"><see cref="MyEvents.Data.IEventDefinitionRepository"/></param>
 /// <returns><see cref="MyEvents.Data.IEventDefinitionRepository"/></returns>
 public int Add(EventDefinition eventDefinition)
 {
     using (var context = new MyEventsContext())
     {
         CheckAndFixTwitterAccount(eventDefinition);
         context.EventDefinitions.Add(eventDefinition);
         context.SaveChanges();
         return eventDefinition.EventDefinitionId;
     }
 }
        /// <summary>
        /// Maps the event definition into the the schedule view model.
        /// </summary>
        /// <param name="registeredUserId">Id user of the caller</param>
        /// <param name="eventDefinition"></param>
        /// <returns></returns>
        public Schedule Map(int registeredUserId, EventDefinition eventDefinition)
        {
            var times = GetTimes(eventDefinition);

            List<ScheduleSession> scheduleSessions =
                eventDefinition
                    .Sessions.Select(s => GetScheduleSession(registeredUserId, s)).ToList();

            return GetViewModel(eventDefinition, times, scheduleSessions); ;
        }
        public void DeleteEventDefinition_CallWebAPI_EventDeleted_NotFail_Test()
        {
            EventDefinition eventDef;
            int organizerId = 0;
            var manualResetEvent = new ManualResetEvent(false);
            var exceptionResult = default(Exception);

            // Get values to test
            using (var context = new MyEventsContext())
            {
                organizerId = context.RegisteredUsers.First().RegisteredUserId;

                // Create event to delete
                eventDef = new EventDefinition();
                eventDef.OrganizerId = organizerId;
                eventDef.Name = Guid.NewGuid().ToString();
                eventDef.Description = Guid.NewGuid().ToString();
                eventDef.Address = Guid.NewGuid().ToString();
                eventDef.City = Guid.NewGuid().ToString();
                eventDef.Tags = Guid.NewGuid().ToString();
                eventDef.TwitterAccount = Guid.NewGuid().ToString();
                eventDef.RoomNumber = 1;
                eventDef.Date = System.DateTime.Now;
                eventDef.StartTime = System.DateTime.Now;
                eventDef.EndTime = System.DateTime.Now.AddDays(1);
                eventDef.TimeZoneOffset = 2;
                eventDef.Likes = 0;
                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                eventDef.Logo = encoding.GetBytes("sample");
                context.EventDefinitions.Add(eventDef);
                context.SaveChanges();
            }

            string urlPrefix = testContextInstance.Properties[TestContext.AspNetDevelopmentServerPrefix + "webapiserver"].ToString();

            var service = new Client.MyEventsClient(urlPrefix);
            service.SetAccessToken(MyEventsToken.CreateToken(eventDef.OrganizerId));
            IAsyncResult ar = service.EventDefinitionService.GetEventDefinitionByIdAsync(eventDef.EventDefinitionId, (Client.EventDefinition getEvent) =>
            {
                IAsyncResult arUpdate = service.EventDefinitionService.DeleteEventDefinitionAsync(getEvent.EventDefinitionId, (HttpStatusCode statusCode) =>
                {
                    using (var context = new MyEventsContext())
                    {
                        var actual = context.EventDefinitions.FirstOrDefault(q => q.EventDefinitionId == eventDef.EventDefinitionId);
                        TestHelper.ValidateResult(null, actual, manualResetEvent, ref exceptionResult);
                    }
                });

            });

            TestHelper.WaitAll(manualResetEvent, ref exceptionResult);
        }
        private List<DateTime> GetTimes(EventDefinition eventDefinition)
        {
            var times = new List<DateTime>();

            DateTime currentTime = eventDefinition.StartTime;

            do
            {
                times.Add(DateTime.SpecifyKind(currentTime, DateTimeKind.Utc));
                currentTime = currentTime.AddHours(1);
            } while (currentTime < eventDefinition.EndTime);

            return times;
        }
Esempio n. 9
0
        public ActionResult Create(MyEventsIdentity identity, EditEventViewModel viewModel)
        {
            SetLogo(viewModel, ModelState);

            if (!ModelState.IsValid)
                return View(viewModel);

            var eventDefinition = new EventDefinition();
            MapViewModelToEventDefinition(viewModel, eventDefinition);
            eventDefinition.OrganizerId = identity.UserId;
            _eventsRepository.Add(eventDefinition);

            ResetLogo();
            return RedirectToAction("Index", "Home");
        }
        private static Schedule GetViewModel(EventDefinition eventDefinition, List<DateTime> times, List<ScheduleSession> scheduleSessions)
        {
            var scheduleEvent = new ScheduleEvent
            {
                EventDefinitionId = eventDefinition.EventDefinitionId,
                Rooms = eventDefinition.RoomNumber,
                Sessions = scheduleSessions
            };

            var viewModel = new Schedule
            {
                EventDefinition = scheduleEvent,
                Times = times
            };
            return viewModel;
        }
        public void DeleteSession_NotFail_Test()
        {
            bool called = false;
            var expectedSession = new Session() { SessionId = 1, EventDefinitionId = 1 };

            var eventDefinition = new EventDefinition() { OrganizerId = 1 };
            IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository()
            {
                GetByIdInt32 = (id) =>
                {
                    Assert.AreEqual(expectedSession.EventDefinitionId, id);
                    return eventDefinition;
                }
            };

            ISessionRepository sessionRepository = new StubISessionRepository()
            {
                DeleteInt32 = sessionId =>
                {
                    Assert.AreEqual(expectedSession.SessionId, sessionId);
                    called = true;
                },
                GetInt32 = (sessionId) =>
                {
                    Assert.AreEqual(expectedSession.SessionId, sessionId);
                    return expectedSession;
                }
            };

            using (ShimsContext.Create())
            {
                MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken();
                myeventToken.RegisteredUserIdGet = () => { return eventDefinition.OrganizerId; };
                ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; };
                var target = new SessionsController(sessionRepository, eventRepository);

                target.Delete(expectedSession.SessionId);

                Assert.IsTrue(called);
            }
        }
        public void DeleteEventDefinition_UnauthorizedException_Test()
        {
            var expected = new EventDefinition() { Name = "EventName", EventDefinitionId = 1, OrganizerId = 1 };
            IEventDefinitionRepository eventDefinitionService = new StubIEventDefinitionRepository()
            {
                GetByIdInt32 = ( id) =>
                {
                    Assert.IsTrue(id == 1);
                    return expected;
                }
            };
            using (ShimsContext.Create())
            {
                MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken();
                myeventToken.RegisteredUserIdGet = () => { return 10; };
                ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; };

                var target = new EventDefinitionsController(eventDefinitionService);

                target.Delete(expected.EventDefinitionId);
            }
        }
Esempio n. 13
0
        private void MapViewModelToEventDefinition(EditEventViewModel viewModel, EventDefinition eventDefinition)
        {
            eventDefinition.Address = viewModel.Address;
            eventDefinition.City = viewModel.City;
            eventDefinition.Date = viewModel.Date;
            eventDefinition.Description = viewModel.Description;
            eventDefinition.EndTime = viewModel.EndTime.ToUniversalTime();
            eventDefinition.EventDefinitionId = viewModel.EventDefinitionId;
            eventDefinition.Latitude = viewModel.Latitude;
            eventDefinition.Longitude = viewModel.Longitude;
            eventDefinition.Name = viewModel.Name;
            eventDefinition.RoomNumber = viewModel.RoomNumber;
            eventDefinition.StartTime = viewModel.StartTime.ToUniversalTime();
            eventDefinition.Tags = viewModel.Tags;
            eventDefinition.TimeZoneOffset = viewModel.TimeZoneOffset;
            eventDefinition.TwitterAccount = viewModel.TwitterAccount;
            eventDefinition.ZipCode = viewModel.ZipCode;

            if (viewModel.IsLogoSetted)
                eventDefinition.Logo = viewModel.Logo;
        }
Esempio n. 14
0
 private void MapEventDefinitionToViewModel(EventDefinition eventDefinition, EditEventViewModel viewModel)
 {
     viewModel.Address = eventDefinition.Address;
     viewModel.City = eventDefinition.City;
     viewModel.Date = eventDefinition.Date;
     viewModel.Description = eventDefinition.Description;
     viewModel.EndTime = eventDefinition.EndTime;
     viewModel.EventDefinitionId = eventDefinition.EventDefinitionId;
     viewModel.Latitude = eventDefinition.Latitude;
     viewModel.Longitude = eventDefinition.Longitude;
     viewModel.Name = eventDefinition.Name;
     viewModel.RoomNumber = eventDefinition.RoomNumber;
     viewModel.StartTime = eventDefinition.StartTime;
     viewModel.Tags = eventDefinition.Tags;
     viewModel.TimeZoneOffset = eventDefinition.TimeZoneOffset;
     viewModel.TwitterAccount = eventDefinition.TwitterAccount;
     viewModel.ZipCode = eventDefinition.ZipCode;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public void Create(MyEventsContext context)
        {
            _startTime = new System.DateTime(2012, 11, 12, 9, 0, 0);

            var eventDefinition = new EventDefinition()
                                      {
                                          Name = "Visual Studio 2012 Global Launch (Seattle & On-Line)",
                                          Description =
                                              "Microsoft Visual Studio 2012 and the Microsoft .NET Framework 4.5 mark the next generation of developer tools from Microsoft. " +
                                              "Designed to address the latest needs of developers, Visual Studio delivers key innovations to address emerging requirements around Application Lifecycle Management (ALM). With Visual Studio 2012 and the .NET Framework 4.5," +
                                              "Microsoft delivers tooling and framework support for the latest innovations in application architecture, development, and deployment. The .NET Framework 4.5 contains numerous improvements that make it easier to develop powerful " +
                                              "and compelling applications. Attend this webcast to learn how Visual Studio 2012 and the .NET Framework 4.5 provide developers with the tooling support and the platform support needed to create amazing solutions. We also explore the core capabilities of these new technologies.",
                                          Address = "Bell Harbor Conference Center, 2211 Alaskan Way, Seattle, WA",
                                          City = "Seattle",
                                          Tags = "Visual Studio 2012",
                                          TwitterAccount = "@visualstudio",
                                          RoomNumber = 3,
                                          Date = _startTime.Date,
                                          StartTime = _startTime,
                                          EndTime = _startTime.AddHours(8).AddMinutes(30),
                                          TimeZoneOffset = 2,
                                          Logo = CommonInitializer.LoadFile("FakeImages\\usa-seattle.png"),
                                          Latitude = 47.6113f,
                                          Longitude = -122.3489f,
                                          MapImage = CommonInitializer.LoadFile("FakeImages\\map.png"),
                                          Sessions = this.Sessions
                                      };

            //(CDLTLL) Assign the existing default organizer or add it
            var existsOrganizer = context.RegisteredUsers.Any(ru => ru.FacebookId == CommonInitializer.FakeUserFacebookId);
            if (existsOrganizer)
            {
                RegisteredUser existingOrganizer = context.RegisteredUsers.Single(ru => ru.FacebookId == CommonInitializer.FakeUserFacebookId);
                eventDefinition.OrganizerId = existingOrganizer.RegisteredUserId;
            }
            else
            {
                eventDefinition.Organizer = this.Organizer;
            }
            //

            eventDefinition.RoomPoints = CommonInitializer.GetRoomPoints(eventDefinition.RoomNumber);
            context.EventDefinitions.Add(eventDefinition);
            context.SaveChanges();
        }
        public void PutEventDefinition_UnauthorizedException_Test()
        {
            var expected = new EventDefinition() { Name = "EventName", EventDefinitionId = 1, OrganizerId = 1 };
            IEventDefinitionRepository eventDefinitionService = new StubIEventDefinitionRepository();
            using (ShimsContext.Create())
            {
                MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken();
                myeventToken.RegisteredUserIdGet = () => { return 10000; };
                ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; };

                var target = new EventDefinitionsController(eventDefinitionService);

                target.Put(expected);
            }
        }
        /// <summary>
        /// <see cref="MyEvents.Data.IEventDefinitionRepository"/>
        /// </summary>
        /// <param name="eventDefinition"><see cref="MyEvents.Data.IEventDefinitionRepository"/></param>
        public void Update(EventDefinition eventDefinition)
        {
            using (var context = new MyEventsContext())
            {
                var eventDefinitionToUpdate = context.EventDefinitions
                    .FirstOrDefault(q => q.EventDefinitionId == eventDefinition.EventDefinitionId);

                eventDefinitionToUpdate.EventDefinitionId = eventDefinition.EventDefinitionId;
                eventDefinitionToUpdate.OrganizerId = eventDefinition.OrganizerId;
                eventDefinitionToUpdate.Name = eventDefinition.Name;
                eventDefinitionToUpdate.Description = eventDefinition.Description;
                eventDefinitionToUpdate.Address = eventDefinition.Address;
                eventDefinitionToUpdate.ZipCode = eventDefinition.ZipCode;
                eventDefinitionToUpdate.City = eventDefinition.City;
                eventDefinitionToUpdate.Tags = eventDefinition.Tags;
                eventDefinitionToUpdate.TwitterAccount = eventDefinition.TwitterAccount;
                eventDefinitionToUpdate.TimeZoneOffset = eventDefinition.TimeZoneOffset;
                eventDefinitionToUpdate.RoomNumber = eventDefinition.RoomNumber;
                eventDefinitionToUpdate.Date = eventDefinition.Date;

                // Be sure that the starttime and endtime is in the same day of the event
                eventDefinitionToUpdate.StartTime
                    = new DateTime(eventDefinition.Date.Year, eventDefinition.Date.Month, eventDefinition.Date.Day, eventDefinition.StartTime.Hour, eventDefinition.StartTime.Minute, 0);

                eventDefinitionToUpdate.EndTime
                    = new DateTime(eventDefinition.Date.Year, eventDefinition.Date.Month, eventDefinition.Date.Day, eventDefinition.EndTime.Hour, eventDefinition.EndTime.Minute, 0);

                eventDefinitionToUpdate.Likes = eventDefinition.Likes;
                eventDefinitionToUpdate.Logo = eventDefinition.Logo;
                eventDefinitionToUpdate.Latitude = eventDefinition.Latitude;
                eventDefinitionToUpdate.Longitude = eventDefinition.Longitude;

                CheckAndFixTwitterAccount(eventDefinitionToUpdate);
                context.SaveChanges();

                // After update eventdefinition we have to clean the room number of the sessions to be sure that all room numbers exist
                CleanRooms(eventDefinition.EventDefinitionId, eventDefinition.RoomNumber);
            }
        }
        public void GetEventDefinitionById_GetResult_NotFail_Test()
        {
            var expected = new EventDefinition() { Name = "EventName" };
            bool called = false;
            int expectedEventDefinitionId = 10;

            IEventDefinitionRepository eventDefinitionService = new StubIEventDefinitionRepository()
            {
                GetByIdWithUserInfoInt32Int32 = (userId, eventDefinitionId) =>
                {
                    Assert.AreEqual(expectedEventDefinitionId, eventDefinitionId);
                    called = true;
                    return expected;
                }
            };

            using (ShimsContext.Create())
            {
                MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken();
                myeventToken.RegisteredUserIdGet = () => { return 0; };
                ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; };

                var target = new EventDefinitionsController(eventDefinitionService);

                EventDefinition actual = target.GetEventDefinitionById(expectedEventDefinitionId);

                Assert.IsTrue(called);
                Assert.AreEqual(expected.Name, actual.Name);
            }
        }
        public void PutSessionPeriod_NotFail_Test()
        {
            int expectedSessionId = 5;
            int duration = 10;
            DateTime startTime = DateTime.Now;
            bool getCalled = false;
            bool updateCalled = false;
            var expectedSession = new Session() { SessionId = expectedSessionId, EventDefinitionId = 1 };
            var eventDefinition = new EventDefinition() { OrganizerId = 1 };

            IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository()
            {
                GetByIdInt32 = (id) =>
                {
                    Assert.AreEqual(expectedSession.EventDefinitionId, id);
                    return eventDefinition;
                }
            };

            ISessionRepository sessionRepository = new StubISessionRepository()

            {
                GetInt32 = (sessionId) =>
                {
                    Assert.AreEqual(expectedSessionId, sessionId);
                    getCalled = true;
                    return expectedSession;
                },
                UpdateSession = session =>
                {
                    Assert.AreEqual(expectedSessionId, session.SessionId);
                    Assert.AreEqual(duration, session.Duration);
                    updateCalled = true;
                }
            };

            using (ShimsContext.Create())
            {
                MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken();
                myeventToken.RegisteredUserIdGet = () => { return eventDefinition.OrganizerId; };
                ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; };

                var target = new SessionsController(sessionRepository, eventRepository);

                target.PutSessionPeriod(expectedSessionId, startTime.ToString(), duration);

                Assert.IsTrue(getCalled);
                Assert.IsTrue(updateCalled);
            }
        }
 private void CheckAndFixTwitterAccount(EventDefinition eventDefinition)
 {
     if (!eventDefinition.TwitterAccount.StartsWith("@"))
         eventDefinition.TwitterAccount = string.Format("@{0}", eventDefinition.TwitterAccount);
 }
        public void PutSessionPeriod_UnauthorizedException_Test()
        {
            int expectedSessionId = 5;
            int duration = 10;
            DateTime startTime = DateTime.Now;
            var expectedSession = new Session() { SessionId = expectedSessionId, EventDefinitionId = 1 };
            var eventDefinition = new EventDefinition() { OrganizerId = 1 };

            IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository()
            {
                GetByIdInt32 = (id) =>
                {
                    Assert.AreEqual(expectedSession.EventDefinitionId, id);
                    return eventDefinition;
                }
            };

            ISessionRepository sessionRepository = new StubISessionRepository()

            {
                GetInt32 = (sessionId) =>
                {
                    Assert.AreEqual(expectedSessionId, sessionId);
                    return expectedSession;
                }
            };

            using (ShimsContext.Create())
            {
                MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken();
                myeventToken.RegisteredUserIdGet = () => { return 1000; };
                ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; };

                var target = new SessionsController(sessionRepository, eventRepository);

                target.PutSessionPeriod(expectedSessionId, startTime.ToString(), duration);
            }
        }
 private void ValidateEventAuthorization(MyEventsIdentity identity, EventDefinition eventDefinition)
 {
     if (identity.UserId != eventDefinition.OrganizerId)
         throw new UnauthorizedAccessException();
 }
        public void PutRoomImage_NotFail_Test()
        {
            bool called = false;
            var expected = new List<RoomPoint>()
            { new RoomPoint() { EventDefinitionId = 10 }
                , new RoomPoint() { EventDefinitionId = 10 }
                , new RoomPoint() { EventDefinitionId = 10 }};
            EventDefinition expectedEvent = new EventDefinition() { EventDefinitionId = 10 , OrganizerId = 10};

            IEventDefinitionRepository eventDefinitionService = new StubIEventDefinitionRepository()
            {
                UpdateRoomImageEventDefinition = (eventDefinition) =>
                {
                    Assert.AreEqual(expectedEvent.EventDefinitionId, eventDefinition.EventDefinitionId);
                    Assert.IsNull(expectedEvent.MapImage);
                    called = true;
                },
                GetByIdInt32 = (id) =>
                {
                    Assert.IsTrue(id == expectedEvent.EventDefinitionId);
                    return expectedEvent;
                }
            };

            using (ShimsContext.Create())
            {
                MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken();
                myeventToken.RegisteredUserIdGet = () => { return expectedEvent.OrganizerId; };
                ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; };

                var target = new RoomPointsController(eventDefinitionService);

                target.PutRoomImage(expectedEvent);

                Assert.IsTrue(called);
            }
        }
        public void PostEventDefinition_UnauthorizedException_Test()
        {
            var expected = new EventDefinition() { Name = "EventName", EventDefinitionId = 1, OrganizerId = 1 };
            bool called = false;

            IEventDefinitionRepository eventDefinitionService = new StubIEventDefinitionRepository();
            using (ShimsContext.Create())
            {
                MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken();
                myeventToken.RegisteredUserIdGet = () => { return 10; }; // It´s not authorized!
                ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; };

                var target = new EventDefinitionsController(eventDefinitionService);

                int actualId = target.Post(expected);

                Assert.IsTrue(called);
                Assert.AreEqual(expected.EventDefinitionId, actualId);
            }
        }
        /// <summary>
        /// <see cref="MyEvents.Data.ISessionRepository"/>
        /// </summary>
        /// <param name="eventDefinition"><see cref="MyEvents.Data.ISessionRepository"/></param>
        public void UpdateRoomImage(EventDefinition eventDefinition)
        {
            using (var context = new MyEventsContext())
            {
                var eventDefinitionToUpdate = context.EventDefinitions
                    .FirstOrDefault(q => q.EventDefinitionId == eventDefinition.EventDefinitionId);

                eventDefinitionToUpdate.EventDefinitionId = eventDefinition.EventDefinitionId;
                eventDefinitionToUpdate.MapImage = eventDefinition.MapImage;

                context.SaveChanges();

            }
        }
        public void PutRoomImage_UnauthorizedException_Test()
        {
            var expected = new List<RoomPoint>()
            { new RoomPoint() { EventDefinitionId = 10 }
                , new RoomPoint() { EventDefinitionId = 10 }
                , new RoomPoint() { EventDefinitionId = 10 }};
            EventDefinition expectedEvent = new EventDefinition() { EventDefinitionId = 10, OrganizerId = 10 };

            IEventDefinitionRepository eventDefinitionService = new StubIEventDefinitionRepository()
            {
                GetByIdInt32 = (id) =>
                {
                    Assert.IsTrue(id == expectedEvent.EventDefinitionId);
                    return expectedEvent;
                }
            };

            using (ShimsContext.Create())
            {
                MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken();
                myeventToken.RegisteredUserIdGet = () => { return 10000; };
                ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; };

                var target = new RoomPointsController(eventDefinitionService);

                target.PutRoomImage(expectedEvent);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public void Create(MyEventsContext context)
        {
            _startTime = new System.DateTime(2012, 12, 5, 9, 0, 0);

            var eventDefinition = new EventDefinition()
            {
                Name = "Visual Studio 2012 - Mexico Launch Event",
                Description =
                    "Discover how Visual Studio 2012 allows you to collaborate better and be more agile. See how it helps you turn big ideas into more compelling apps. Experience how it integrates best practices that accelerate development and deployment.  You’ll enjoy several sessions which will take Visual Studio, Team Foundation Server, and Test Professional through their paces to show off what’s possible with this incredible release!",
                Address = "Av. Vasco de Quiroga 1700, Del Álvaro Obregón, Mexico D.F. 01210, MEXICO",
                City = "Mexico D.F.",
                Tags = "Visual Studio 2012, .NET 4.5, Windows 8, Architecture",
                TwitterAccount = "@visualstudio",
                RoomNumber = 2,
                Date = _startTime.Date,
                StartTime = _startTime,
                EndTime = _startTime.AddHours(8).AddMinutes(30),
                TimeZoneOffset = 2,
                Logo = CommonInitializer.LoadFile("FakeImages\\mexico.png"),
                Latitude = 19.3664f,
                Longitude = -99.2645f,
                MapImage = CommonInitializer.LoadFile("FakeImages\\map.png"),
                Sessions = this.Sessions
            };

            //Assign the existing default organizer or add it
            var existsOrganizer = context.RegisteredUsers.Any(ru => ru.FacebookId == CommonInitializer.FakeUserFacebookId);
            if (existsOrganizer)
            {
                RegisteredUser existingOrganizer = context.RegisteredUsers.Single(ru => ru.FacebookId == CommonInitializer.FakeUserFacebookId);
                eventDefinition.OrganizerId = existingOrganizer.RegisteredUserId;
            }
            else
            {
                eventDefinition.Organizer = this.Organizer;
            }

            eventDefinition.RoomPoints = CommonInitializer.GetRoomPoints(eventDefinition.RoomNumber);
            context.EventDefinitions.Add(eventDefinition);
            context.SaveChanges();
        }
Esempio n. 28
0
        public void PutRoomImage(EventDefinition eventDefinition)
        {
            ValidateEventAuthorization(eventDefinition.EventDefinitionId);

            _eventDefinitionRepository.UpdateRoomImage(eventDefinition);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public void Create(MyEventsContext context)
        {
            _startTime = new System.DateTime(2012, 12, 14, 9, 0, 0);

            var eventDefinition = new EventDefinition()
            {
                Name = "Visual Studio 2012 - Atlanta Launch Event",
                Description =
                    "Discover how Visual Studio 2012 allows you to collaborate better and be more agile. See how it helps you turn big ideas into more compelling apps. Experience how it integrates best practices that accelerate development and deployment.  You’ll enjoy several sessions which will take Visual Studio, Team Foundation Server, and Test Professional through their paces to show off what’s possible with this incredible release!",
                Address = "1125 Sanctuary Pkwy., Alpharetta, GA 30009",
                City = "Atlanta",
                Tags = "Visual Studio 2012, SharePoint",
                TwitterAccount = "@visualstudio",
                RoomNumber = 2,
                Date = _startTime.Date,
                StartTime = _startTime,
                EndTime = _startTime.AddHours(8).AddMinutes(30),
                TimeZoneOffset = 2,
                Logo = CommonInitializer.LoadFile("FakeImages\\usa-atlanta.png"),
                Latitude = 34.0478f,
                Longitude = -84.3120f,
                MapImage = CommonInitializer.LoadFile("FakeImages\\map.png"),
                Sessions = this.Sessions
            };

            //Assign the existing default organizer or add it
            var existsOrganizer = context.RegisteredUsers.Any(ru => ru.FacebookId == CommonInitializer.FakeUserFacebookId);
            if (existsOrganizer)
            {
                RegisteredUser existingOrganizer = context.RegisteredUsers.Single(ru => ru.FacebookId == CommonInitializer.FakeUserFacebookId);
                eventDefinition.OrganizerId = existingOrganizer.RegisteredUserId;
            }
            else
            {
                eventDefinition.Organizer = this.Organizer;
            }

            eventDefinition.RoomPoints = CommonInitializer.GetRoomPoints(eventDefinition.RoomNumber);
            context.EventDefinitions.Add(eventDefinition);
            context.SaveChanges();
        }
        public void Put(EventDefinition eventDefinition)
        {
            if (eventDefinition == null)
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));

            var token = MyEventsToken.GetTokenFromHeader();
            if (token.RegisteredUserId != eventDefinition.OrganizerId)
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));

            _eventDefinitionRepository.Update(eventDefinition);
        }