public void Database_Delete_PendingAdd() { //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", }; //act Context.Events.Add(newEvent); Context.SaveChanges(); Context.RemoveDbSetDataDatabase(Context.Events); //assert Context.Events.Count().ShouldBe(0); }
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_Not_Allow_Nulls() { // arrange Event defaultEvent = new Event(); // act Context.Events.Add(defaultEvent); Should.Throw<DbUpdateException>( () => { Context.SaveChanges(); }); //clean up Context.Events.Local.Clear(); }
public void Should_Not_Allow_Duplicate_ID() { // arrange Context.Events.Add(_sampleEvent); Context.SaveChanges(); Event duplicatEvent = new Event { Id = 1, Title = "Unique 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", }; // act Context.Events.Add(duplicatEvent); Context.SaveChanges(); Event correctedDuplicateEvent = Context.Events.First(e => e.Title == "Unique Event"); // assert correctedDuplicateEvent.Id.ShouldNotBe(1); }
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)); }