public void Add_Registration_With_Defaults()
        {
            //arrange
            var newEvent = new Event
            {
                Title = "Sample Event",
                Description = "Sample Event Description",
                StartDateTime = DateTime.Now,
                EndDateTime = DateTime.Now.AddHours(1),
                Category = new Category(),
                Registrations = new List<Registration>(),
                EventType = new EventType(),
                Status = new Status(),
                LocationInformation = "At some new location",
                LogoPath = "http://google/someimage"
            };
            Context.Events.Add(newEvent);
            var newRegistration = new Registration()
            {
                Event = newEvent,
                EventType = new EventType(),
                RegisterDateTime = DateTime.Now,
                Title = "A title"
            };

            //act
            Context.Registrations.Add(newRegistration);
            Context.SaveChanges();

            //assert
            int rowCount = Context.Registrations.Count();
            rowCount.ShouldBeGreaterThan(0);
        }
        public void TestInit()
        {
            Context.RemoveAllDbSetDataDatabase();

            var newEvent = new Event
            {
                Title = "Sample Event",
                Description = "Sample Event Description",
                StartDateTime = DateTime.Now,
                EndDateTime = DateTime.Now.AddHours(1),
                Category = new Category(),
                Registrations = new List<Registration>(),
                EventType = new EventType(),
                Status = new Status(),
                LocationInformation = "At some new location",
                LogoPath = "http://google/someimage"
            };
            _sampleRegistration = new Registration()
            {
                Event = newEvent,
                EventType = new EventType(),
                RegisterDateTime = DateTime.Now,
                Title = "Sample Registration"
            };
        }
        public void Should_Populate_ID()
        {
            // arrange
            var newEvent = new Event
            {
                Title = "Sample Event",
                Description = "Sample Event Description",
                StartDateTime = DateTime.Now,
                EndDateTime = DateTime.Now.AddHours(1),
                Category = new Category(),
                Registrations = new List<Registration>(),
                EventType = new EventType(),
                Status = new Status(),
                LocationInformation = "At some new location",
                LogoPath = "http://google/someimage"
            };
            Context.Events.Add(newEvent);
            var newRegistration = new Registration()
            {
                Event = newEvent,
                EventType = new EventType(),
                RegisterDateTime = DateTime.Now,
                Title = "A title"
            };

            // act
            Context.Registrations.Add(newRegistration);
            Context.SaveChanges();

            // assert
            Context.Registrations.First().Id.ShouldBe(1);
        }
        public void Add_Registration_With_Nonexistent_FK()
        {
            //arrange
            var newEventType = new EventType()
            {
                Title = "EventType Title"
            };

            Context.EventType.Add(newEventType);
            Context.SaveChanges();

            var newEvent = new Event
            {
                Title = "Sample Event",
                Description = "Sample Event Description",
                StartDateTime = DateTime.Now,
                EndDateTime = DateTime.Now.AddHours(1),
                Category = new Category(),
                Registrations = new List<Registration>(),
                EventType = newEventType,
                Status = new Status(),
                LocationInformation = "At some new location",
                LogoPath = "http://google/someimage"
            };

            Context.Events.Add(newEvent);
            Context.SaveChanges();

            var newRegistration = new Registration()
            {
                Event = newEvent,
                EventType = newEventType,
                RegisterDateTime = DateTime.Now,
                Title = "A title"
            };

            //act
            Context.Registrations.Add(newRegistration);
            Context.SaveChanges();

            //assert
            Context.EventType.ShouldContain(newEventType);
        }
        public void Update_Registration_From_Defaults()
        {
            // arrange
            var newEvent = new Event
            {
                Title = "Sample Event",
                Description = "Sample Event Description",
                StartDateTime = DateTime.Now,
                EndDateTime = DateTime.Now.AddHours(1),
                Category = new Category(),
                Registrations = new List<Registration>(),
                EventType = new EventType(),
                Status = new Status(),
                LocationInformation = "At some new location",
                LogoPath = "http://google/someimage"
            };

            Context.Events.Add(newEvent);
            Context.SaveChanges();

            var newRegistration = new Registration()
            {
                Event = newEvent,
                EventType = new EventType(),
                RegisterDateTime = DateTime.Now,
                Title = "A title"
            };

            //act
            Context.Registrations.Add(newRegistration);
            Context.SaveChanges();

            Registration oldRegistration = Context.Registrations.First(r => r.Title == "A title");
            var oldId = oldRegistration.Id;

            oldRegistration.Title =  "New Title";
            oldRegistration.RegisterDateTime = new DateTime(2015, 4, 28);

            Context.Entry(oldRegistration).State = EntityState.Modified;
            Context.SaveChanges();

            //assert
            Registration modifiedRegistration = Context.Registrations.Find(oldId);
            modifiedRegistration.Title.ShouldBe("New Title");
            modifiedRegistration.RegisterDateTime.ShouldBe(new DateTime(2015, 4, 28));
        }
        public void Should_Not_Allow_Duplicate_ID()
        {
            // arrange
            Context.Registrations.Add(_sampleRegistration);
            Context.SaveChanges();

            var newEvent = new Event
            {
                Title = "Sample Event",
                Description = "Sample Event Description",
                StartDateTime = DateTime.Now,
                EndDateTime = DateTime.Now.AddHours(1),
                Category = new Category(),
                Registrations = new List<Registration>(),
                EventType = new EventType(),
                Status = new Status(),
                LocationInformation = "At some new location",
                LogoPath = "http://google/someimage"
            };
            Registration duplicateRegistration = new Registration
            {
                Id = 1,
                Event = newEvent,
                EventType = new EventType(),
                RegisterDateTime = DateTime.Now,
                Title = "Unique Registration"
            };

            // act
            Context.Registrations.Add(duplicateRegistration);
            Context.SaveChanges();
            Registration correctedDuplicateRegistration = Context.Registrations.First(e => e.Title == "Unique Registration");

            // assert
            correctedDuplicateRegistration.Id.ShouldNotBe(1);
        }