示例#1
0
        public async Task Should_create_room_with_items()
        {
            var attribute1 = new RoomAttribute
            {
                Name = "Size", Value = "400 Square Ft"
            };
            var attribute2 = new RoomAttribute
            {
                Name = "Windows", Value = "5"
            };
            var attribute3 = new RoomAttribute
            {
                Name = "Entrance Door", Value = "1"
            };
            var attribute4 = new RoomAttribute
            {
                Name = "Projector", Value = ""
            };

            await InsertAsync(attribute1, attribute2, attribute3, attribute4);

            var cmd = new Create.Command
            {
                Name = "Room 1",
                SelectedAttributes = new int[] { attribute1.Id, attribute2.Id, attribute3.Id, attribute4.Id }
            };

            int roomId = await SendAsync(cmd);

            var room = await FindAsync <Room>(roomId);

            room.ShouldNotBeNull();
            room.Name.ShouldBe(cmd.Name);
        }
示例#2
0
        public async Task <IActionResult> PutRoomAttribute([FromRoute] int id, [FromBody] RoomAttribute roomAttribute)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != roomAttribute.Id)
            {
                return(BadRequest());
            }

            _context.Entry(roomAttribute).State = EntityState.Modified;

            try {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) {
                if (!RoomAttributeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task Should_get_details()
        {
            var room = new Room
            {
                Name = "Room 1"
            };

            await InsertAsync(room);

            var attribute1 = new RoomAttribute
            {
                Name = "Size", Value = "400 Square Ft"
            };
            var attribute2 = new RoomAttribute
            {
                Name = "Windows", Value = "5"
            };
            var attribute3 = new RoomAttribute
            {
                Name = "Entrance Door", Value = "1"
            };
            var attribute4 = new RoomAttribute
            {
                Name = "Projector", Value = ""
            };

            await InsertAsync(attribute1, attribute2, attribute3, attribute4);

            var roomItem1 = new RoomItem
            {
                RoomId = room.Id, RoomAttributeId = attribute1.Id
            };
            var roomItem2 = new RoomItem
            {
                RoomId = room.Id, RoomAttributeId = attribute2.Id
            };
            var roomItem3 = new RoomItem
            {
                RoomId = room.Id, RoomAttributeId = attribute3.Id
            };
            var roomItem4 = new RoomItem
            {
                RoomId = room.Id, RoomAttributeId = attribute4.Id
            };

            await InsertAsync(roomItem1, roomItem2, roomItem3, roomItem4);

            var details = await SendAsync(new Details.Query {
                Id = room.Id
            });

            details.ShouldNotBeNull();
            details.Name.ShouldBe(room.Name);
            details.Items.Count.ShouldBe(4);
        }
示例#4
0
        public async Task <IActionResult> PostRoomAttribute([FromBody] RoomAttribute roomAttribute)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.RoomAttributes.Add(roomAttribute);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRoomAttribute", new { id = roomAttribute.Id }, roomAttribute));
        }
        public static void Initialize(ExamContext context)
        {
            var rooms = new Room[0];

            // Look for any rooms.
            if (!context.Rooms.Any())
            {
                rooms = new Room[]
                {
                    new Room {
                        Name = "Room 1"
                    },
                    new Room {
                        Name = "Room 2"
                    },
                    new Room {
                        Name = "Room 3"
                    },
                    new Room {
                        Name = "Room 4"
                    }
                };

                foreach (var r in rooms)
                {
                    context.Rooms.Add(r);
                }
                context.SaveChanges();
            }

            var attributes = new RoomAttribute[0];

            // Look for any room attributes.
            if (!context.RoomAttributes.Any())
            {
                attributes = new RoomAttribute[]
                {
                    new RoomAttribute {
                        Name = "Size", Value = "400 Square Ft"
                    },
                    new RoomAttribute {
                        Name = "Windows", Value = "5"
                    },
                    new RoomAttribute {
                        Name = "Entrance Door", Value = "1"
                    },
                    new RoomAttribute {
                        Name = "Boardroom Style Table", Value = "10 Chairs"
                    },
                    new RoomAttribute {
                        Name = "Projector", Value = ""
                    },
                    new RoomAttribute {
                        Name = "Projector Screen", Value = ""
                    },
                    new RoomAttribute {
                        Name = "Flipchart", Value = ""
                    },
                    new RoomAttribute {
                        Name = "Conference Telephone", Value = ""
                    }
                };

                foreach (var a in attributes)
                {
                    context.RoomAttributes.Add(a);
                }
                context.SaveChanges();
            }

            var roomItems = new RoomItem[0];

            if (!context.RoomItems.Any())
            {
                roomItems = new RoomItem[]
                {
                    new RoomItem {
                        RoomId          = rooms.Single(r => r.Name == "Room 1").Id,
                        RoomAttributeId = attributes.Single(a => a.Name == "Size").Id
                    },
                    new RoomItem {
                        RoomId          = rooms.Single(r => r.Name == "Room 1").Id,
                        RoomAttributeId = attributes.Single(a => a.Name == "Windows").Id
                    },
                    new RoomItem {
                        RoomId          = rooms.Single(r => r.Name == "Room 1").Id,
                        RoomAttributeId = attributes.Single(a => a.Name == "Entrance Door").Id
                    },
                    new RoomItem {
                        RoomId          = rooms.Single(r => r.Name == "Room 3").Id,
                        RoomAttributeId = attributes.Single(a => a.Name == "Size").Id
                    },
                    new RoomItem {
                        RoomId          = rooms.Single(r => r.Name == "Room 3").Id,
                        RoomAttributeId = attributes.Single(a => a.Name == "Windows").Id
                    },
                    new RoomItem {
                        RoomId          = rooms.Single(r => r.Name == "Room 3").Id,
                        RoomAttributeId = attributes.Single(a => a.Name == "Entrance Door").Id
                    },
                    new RoomItem {
                        RoomId          = rooms.Single(r => r.Name == "Room 3").Id,
                        RoomAttributeId = attributes.Single(a => a.Name == "Projector").Id
                    },
                    new RoomItem {
                        RoomId          = rooms.Single(r => r.Name == "Room 3").Id,
                        RoomAttributeId = attributes.Single(a => a.Name == "Projector Screen").Id
                    }
                };

                foreach (var r in roomItems)
                {
                    context.RoomItems.Add(r);
                }
                context.SaveChanges();
            }

            var foodItems = new Food[0];

            if (!context.FoodItems.Any())
            {
                foodItems = new Food[]
                {
                    new Food {
                        Name = "Tea"
                    },
                    new Food {
                        Name = "Coffee"
                    },
                    new Food {
                        Name = "Biscuits"
                    },
                    new Food {
                        Name = "Buffets"
                    }
                };

                foreach (var f in foodItems)
                {
                    context.FoodItems.Add(f);
                }
                context.SaveChanges();
            }

            var schedules = new Schedule[0];

            if (!context.Schedules.Any())
            {
                DateTime now = DateTime.Now;

                schedules = new Schedule[]
                {
                    new Schedule {
                        RoomId    = rooms.Single(r => r.Name == "Room 1").Id,
                        Name      = "Schedule 1",
                        StartTime = new DateTime(now.Year, now.Month, now.Day) + new TimeSpan(7, 0, 0),
                        EndTime   = new DateTime(now.Year, now.Month, now.Day) + new TimeSpan(10, 0, 0)
                    },
                    new Schedule {
                        RoomId    = rooms.Single(r => r.Name == "Room 1").Id,
                        Name      = "Schedule 2",
                        StartTime = new DateTime(now.Year, now.Month, now.Day) + new TimeSpan(13, 0, 0),
                        EndTime   = new DateTime(now.Year, now.Month, now.Day) + new TimeSpan(15, 0, 0)
                    },
                };

                foreach (var s in schedules)
                {
                    context.Schedules.Add(s);
                }
                context.SaveChanges();
            }
        }