Ejemplo n.º 1
0
        public void Mutation_CreateBill()
        {
            Database.WriteAsync(realm => realm.Add(new Room
            {
                Id       = 120,
                IsActive = true,
                Name     = "Tên phòng",
                Floor    = FloorBusiness.Get(1),
                RoomKind = RoomKindBusiness.Get(1)
            })).Wait();

            SchemaHelper.Execute(
                @"/_GraphQL/Bill/mutation.createBill.gql",
                @"/_GraphQL/Bill/mutation.createBill.schema.json",
                new
            {
                bookings = new[]
                {
                    new
                    {
                        bookCheckInTime  = DateTimeOffset.Now.AddDays(1),
                        bookCheckOutTime = DateTimeOffset.Now.AddDays(2),
                        room             = new { id = 120 },
                        listOfPatrons    = new[] { new { id = 1 } }
                    }
                },
                bill = new
                {
                    patron = new { id = 1 }
                }
            },
                p => p.PermissionManageRentingRoom = true
                );
        }
Ejemplo n.º 2
0
        public void Mutation_AddBookingToBill_InvalidBill()
        {
            Database.WriteAsync(realm => realm.Add(new Room
            {
                Id       = 201,
                IsActive = true,
                Name     = "Tên phòng",
                Floor    = FloorBusiness.Get(1),
                RoomKind = RoomKindBusiness.Get(1)
            })).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Mã hóa đơn không tồn tại",
                @"/_GraphQL/Booking/mutation.addBookingToBill.gql",
                new
            {
                booking = new
                {
                    bookCheckInTime  = DateTimeOffset.Now.AddDays(1),
                    bookCheckOutTime = DateTimeOffset.Now.AddDays(2),
                    room             = new { id = 201 },
                    listOfPatrons    = new[]
                    {
                        new { id = 1 }
                    }
                },
                bill = new
                {
                    id = 1
                }
            },
                p => p.PermissionManageRentingRoom = true
                );
        }
Ejemplo n.º 3
0
        public void Mutation_BookAndCheckIn_InvalidRoom_Overlap()
        {
            Database.WriteAsync(realm => realm.Add(new Room
            {
                Id       = 111,
                IsActive = true,
                Name     = "Tên phòng",
                Floor    = FloorBusiness.Get(1),
                RoomKind = RoomKindBusiness.Get(1)
            })).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Có booking trùng nhau",
                @"/_GraphQL/Bill/mutation.bookAndCheckIn.gql",
                new
            {
                bookings = new[]
                {
                    new
                    {
                        bookCheckOutTime = DateTimeOffset.Now.AddDays(2),
                        room             = new { id = 111 },
                        listOfPatrons    = new[] { new { id = 1 } }
                    }
                },
                bill = new { patron = new { id = 1 } }
            },
                p => p.PermissionManageRentingRoom = true
                );
        }
Ejemplo n.º 4
0
        public void Mutation_UpdateRate_InvalidRoomKind()
        {
            Database.WriteAsync(realm => realm.Add(new Rate
            {
                Id       = 21,
                RoomKind = RoomKindBusiness.Get(1),
                Employee = EmployeeBusiness.Get("admin")
            })).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Mã loại phòng không tồn tại",
                @"/_GraphQL/Rate/mutation.updateRate.gql",
                new
            {
                input = new
                {
                    id                 = 21,
                    dayRate            = 5,
                    nightRate          = 5,
                    weekRate           = 5,
                    monthRate          = 5,
                    lateCheckOutFee    = 5,
                    earlyCheckInFee    = 5,
                    effectiveStartDate = DateTimeOffset.MinValue,
                    roomKind           = new
                    {
                        id = 100
                    }
                }
            },
                p => p.PermissionManageRate = true
                );
        }
Ejemplo n.º 5
0
 public void Mutation_UpdateRoom_InvalidRoom_InActive()
 {
     Database.WriteAsync(realm => realm.Add(new Room
     {
         Id       = 35,
         IsActive = false,
         Name     = "Tên phòng",
         Floor    = FloorBusiness.Get(1),
         RoomKind = RoomKindBusiness.Get(1)
     })).Wait();
     SchemaHelper.ExecuteAndExpectError(
         "Phòng 35 đã ngưng hoại động. Không thể cập nhật/xóa!",
         @"/_GraphQL/Room/mutation.updateRoom.gql",
         new
     {
         input = new
         {
             id       = 35,
             name     = "Phòng 2",
             roomKind = new
             {
                 id = 1
             },
             floor = new
             {
                 id = 1
             }
         }
     },
         p => p.PermissionManageMap = true
         );
 }
Ejemplo n.º 6
0
        public void Mutation_UpdateRoom_InvalidRoomKind()
        {
            Database.WriteAsync(realm => realm.Add(new Room
            {
                Id       = 33,
                IsActive = true,
                Name     = "Tên phòng",
                Floor    = FloorBusiness.Get(1),
                RoomKind = RoomKindBusiness.Get(1)
            })).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Mã loại phòng không tồn tại",
                @"/_GraphQL/Room/mutation.updateRoom.gql",
                new
            {
                input = new
                {
                    id       = 33,
                    name     = "Phòng 2",
                    roomKind = new
                    {
                        id = 100
                    },
                    floor = new
                    {
                        id = 1
                    }
                }
            },
                p => p.PermissionManageMap = true
                );
        }
Ejemplo n.º 7
0
 public void Mutation_UpdateRoom()
 {
     Database.WriteAsync(realm => realm.Add(new Room
     {
         Id       = 30,
         IsActive = true,
         Name     = "Tên phòng",
         Floor    = FloorBusiness.Get(1),
         RoomKind = RoomKindBusiness.Get(1)
     })).Wait();
     SchemaHelper.Execute(
         @"/_GraphQL/Room/mutation.updateRoom.gql",
         @"/_GraphQL/Room/mutation.updateRoom.schema.json",
         new
     {
         input = new
         {
             id       = 30,
             name     = "Phòng 2",
             roomKind = new
             {
                 id = 1
             },
             floor = new
             {
                 id = 1
             }
         }
     },
         p => p.PermissionManageMap = true
         );
 }
Ejemplo n.º 8
0
        public void Mutation_SetIsActiveRoom_InvalidFloor_InActive()
        {
            Database.WriteAsync(realm =>
            {
                realm.Add(new Floor
                {
                    Id       = 110,
                    Name     = "Tầng tạo ra để xóa",
                    IsActive = false
                });
                realm.Add(new Room
                {
                    Id       = 21,
                    IsActive = true,
                    Name     = "Tên phòng",
                    Floor    = FloorBusiness.Get(110),
                    RoomKind = RoomKindBusiness.Get(1)
                });
            }).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Loại phòng thuộc tầng đã bị vô hiệu hóa. Không thể kích hoạt",
                @"/_GraphQL/Room/mutation.setIsActiveRoom.gql",
                new { id = 21, isActive = true },
                p => p.PermissionManageMap = true
                );
        }
Ejemplo n.º 9
0
        public void Mutation_CreateBill_InvalidRoom_InActive()
        {
            Database.WriteAsync(realm => realm.Add(new Room
            {
                Id       = 121,
                IsActive = false,
                Name     = "Tên phòng",
                Floor    = FloorBusiness.Get(1),
                RoomKind = RoomKindBusiness.Get(1)
            })).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Phòng 121 đã ngừng hoạt động",
                @"/_GraphQL/Bill/mutation.createBill.gql",
                new
            {
                bookings = new[]
                {
                    new
                    {
                        bookCheckInTime  = DateTimeOffset.Now.AddDays(1),
                        bookCheckOutTime = DateTimeOffset.Now.AddDays(2),
                        room             = new { id = 121 },
                        listOfPatrons    = new[] { new { id = 1 } }
                    }
                },
                bill = new
                {
                    patron = new { id = 1 }
                }
            },
                p => p.PermissionManageRentingRoom = true
                );
        }
Ejemplo n.º 10
0
        public RoomKindMutation()
        {
            Field <NonNullGraphType <RoomKindType> >(
                _Creation,
                "Tạo và trả về một loại phòng",
                _InputArgument <RoomKindCreateInput>(),
                _CheckPermission_TaskObject(
                    p => p.PermissionManageMap,
                    context => RoomKindBusiness.Add(_GetInput(context))
                    )
                );

            Field <NonNullGraphType <RoomKindType> >(
                _Updation,
                "Cập nhật và trả về loại phòng vừa cập nhật",
                _InputArgument <RoomKindUpdateInput>(),
                _CheckPermission_TaskObject(
                    p => p.PermissionManageMap,
                    context => RoomKindBusiness.Update(_GetInput(context))
                    )
                );

            Field <NonNullGraphType <StringGraphType> >(
                _Deletion,
                "Xóa một loại phòng",
                _IdArgument(),
                _CheckPermission_String(
                    p => p.PermissionManageMap,
                    context =>
            {
                RoomKindBusiness.Delete(_GetId <int>(context));
                return("Xóa thành công");
            }
                    )
                );

            Field <NonNullGraphType <StringGraphType> >(
                _SetIsActive,
                "Cập nhật trạng thái hoạt động của loại phòng",
                new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <BooleanGraphType> > {
                Name = "isActive"
            }
                    ),
                _CheckPermission_String(
                    p => p.PermissionManageMap,
                    context =>
            {
                var id       = context.GetArgument <int>("id");
                var isActive = context.GetArgument <bool>("isActive");
                RoomKindBusiness.SetIsActive(id, isActive);
                return("Cập nhật trạng thái thành công");
            }
                    )
                );
        }
Ejemplo n.º 11
0
        public RoomKind GetManaged()
        {
            var roomKind = RoomKindBusiness.Get(Id);

            if (roomKind == null)
            {
                throw new Exception("Mã loại phòng không tồn tại");
            }
            return(roomKind);
        }
Ejemplo n.º 12
0
        public void Mutation_UpdateVolatilityRate_InvalidRoomKind_InActive()
        {
            Database.WriteAsync(realm =>
            {
                realm.Add(new RoomKind
                {
                    Id             = 201,
                    Name           = "Tên loại phòng",
                    AmountOfPeople = 1,
                    NumberOfBeds   = 1,
                    IsActive       = false
                });
                realm.Add(new VolatilityRate
                {
                    Id       = 22,
                    RoomKind = RoomKindBusiness.Get(1),
                    Employee = EmployeeBusiness.Get("admin")
                });
            }).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Loại phòng 201 đã ngưng hoại động",
                @"/_GraphQL/VolatilityRate/mutation.updateVolatilityRate.gql",
                new
            {
                input = new
                {
                    id                   = 22,
                    dayRate              = 1,
                    nightRate            = 1,
                    weekRate             = 1,
                    monthRate            = 1,
                    lateCheckOutFee      = 1,
                    earlyCheckInFee      = 1,
                    effectiveStartDate   = "0001-01-01T00:00:00+00:00",
                    effectiveEndDate     = "0001-01-01T00:00:00+00:00",
                    effectiveOnMonday    = true,
                    effectiveOnTuesday   = true,
                    effectiveOnWednesday = true,
                    effectiveOnThursday  = true,
                    effectiveOnFriday    = true,
                    effectiveOnSaturday  = true,
                    effectiveOnSunday    = true,
                    roomKind             = new
                    {
                        id = 201
                    }
                }
            },
                p => p.PermissionManageRate = true
                );
        }
Ejemplo n.º 13
0
 public void Query_Rate()
 {
     Database.WriteAsync(realm => realm.Add(new Rate
     {
         Id       = 30,
         RoomKind = RoomKindBusiness.Get(1),
         Employee = EmployeeBusiness.Get("admin")
     })).Wait();
     SchemaHelper.Execute(
         @"/_GraphQL/Rate/query.rate.gql",
         @"/_GraphQL/Rate/query.rate.schema.json",
         new { id = 30 },
         p => p.PermissionGetRate = true
         );
 }
Ejemplo n.º 14
0
 public void Mutation_SetIsActiveRoom()
 {
     Database.WriteAsync(realm => realm.Add(new Room
     {
         Id       = 20,
         IsActive = true,
         Name     = "Tên phòng",
         Floor    = FloorBusiness.Get(1),
         RoomKind = RoomKindBusiness.Get(1)
     })).Wait();
     SchemaHelper.Execute(
         @"/_GraphQL/Room/mutation.setIsActiveRoom.gql",
         @"/_GraphQL/Room/mutation.setIsActiveRoom.schema.json",
         new { id = 20, isActive = true },
         p => p.PermissionManageMap = true
         );
 }
Ejemplo n.º 15
0
 public void Mutation_DeleteRate()
 {
     Database.WriteAsync(realm => realm.Add(new Rate
     {
         Id       = 10,
         RoomKind = RoomKindBusiness.Get(1),
         Employee = EmployeeBusiness.Get("admin")
     })).Wait();
     SchemaHelper.Execute(
         @"/_GraphQL/Rate/mutation.deleteRate.gql",
         @"/_GraphQL/Rate/mutation.deleteRate.schema.json",
         new
     {
         id = 10
     },
         p => p.PermissionManageRate = true
         );
 }
Ejemplo n.º 16
0
        public void Mutation_UpdateRate_InvalidRoomKind_InActive()
        {
            Database.WriteAsync(realm =>
            {
                realm.Add(new Rate
                {
                    Id       = 22,
                    RoomKind = RoomKindBusiness.Get(1),
                    Employee = EmployeeBusiness.Get("admin")
                });
                realm.Add(new RoomKind
                {
                    Id             = 110,
                    Name           = "Tên loại phòng",
                    AmountOfPeople = 1,
                    NumberOfBeds   = 1,
                    IsActive       = false
                });
            }).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Loại phòng 110 đã ngưng hoại động",
                @"/_GraphQL/Rate/mutation.updateRate.gql",
                new
            {
                input = new
                {
                    id                 = 22,
                    dayRate            = 5,
                    nightRate          = 5,
                    weekRate           = 5,
                    monthRate          = 5,
                    lateCheckOutFee    = 5,
                    earlyCheckInFee    = 5,
                    effectiveStartDate = DateTimeOffset.MinValue,
                    roomKind           = new
                    {
                        id = 110
                    }
                }
            },
                p => p.PermissionManageRate = true
                );
        }
Ejemplo n.º 17
0
        public void Mutation_UpdateRoom_InvalidRoomKind_InActive()
        {
            Database.WriteAsync(realm =>
            {
                realm.Add(new RoomKind
                {
                    Id             = 102,
                    Name           = "Tên loại phòng",
                    AmountOfPeople = 1,
                    NumberOfBeds   = 1,
                    IsActive       = false
                });
                realm.Add(new Room
                {
                    Id       = 34,
                    IsActive = true,
                    Name     = "Tên phòng",
                    Floor    = FloorBusiness.Get(1),
                    RoomKind = RoomKindBusiness.Get(1)
                });
            }).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Loại phòng có ID: 102 đã ngưng hoại động",
                @"/_GraphQL/Room/mutation.updateRoom.gql",
                new
            {
                input = new
                {
                    id       = 34,
                    name     = "Phòng 2",
                    roomKind = new
                    {
                        id = 102
                    },
                    floor = new
                    {
                        id = 1
                    }
                }
            },
                p => p.PermissionManageMap = true
                );
        }
Ejemplo n.º 18
0
 public void Mutation_UpdateRoom_InvalidFloor_InActive()
 {
     Database.WriteAsync(realm =>
     {
         realm.Add(new Floor
         {
             Id       = 102,
             Name     = "Tầng tạo ra để kiểm tra inactive",
             IsActive = false
         });
         realm.Add(new Room
         {
             Id       = 32,
             IsActive = true,
             Name     = "Tên phòng",
             Floor    = FloorBusiness.Get(1),
             RoomKind = RoomKindBusiness.Get(1)
         });
     }).Wait();
     SchemaHelper.ExecuteAndExpectError(
         "Tầng có ID: 102 đã ngưng hoại động",
         @"/_GraphQL/Room/mutation.updateRoom.gql",
         new
     {
         input = new
         {
             id       = 32,
             name     = "Phòng 2",
             roomKind = new
             {
                 id = 1
             },
             floor = new
             {
                 id = 102
             }
         }
     },
         p => p.PermissionManageMap = true
         );
 }
Ejemplo n.º 19
0
        public RoomKindQuery()
        {
            Field <NonNullGraphType <ListGraphType <NonNullGraphType <RoomKindType> > > >(
                _List,
                "Trả về một danh sách các loại phòng",
                resolve: _CheckPermission_List(
                    p => p.PermissionGetMap,
                    context => RoomKindBusiness.Get()
                    )
                );

            Field <NonNullGraphType <RoomKindType> >(
                nameof(RoomKind),
                "Trả về thông tin của một loại phòng",
                _IdArgument(),
                _CheckPermission_Object(
                    p => p.PermissionGetMap,
                    context => RoomKindBusiness.Get(_GetId <int>(context))
                    )
                );
        }
Ejemplo n.º 20
0
 public void Mutation_UpdateVolatilityRate_InvalidRoomKind()
 {
     Database.WriteAsync(realm => realm.Add(new VolatilityRate
     {
         Id       = 21,
         RoomKind = RoomKindBusiness.Get(1),
         Employee = EmployeeBusiness.Get("admin")
     })).Wait();
     SchemaHelper.Execute(
         @"/_GraphQL/VolatilityRate/mutation.updateVolatilityRate.gql",
         @"/_GraphQL/VolatilityRate/mutation.updateVolatilityRate.schema.json",
         new
     {
         input = new
         {
             id                   = 21,
             dayRate              = 1,
             nightRate            = 1,
             weekRate             = 1,
             monthRate            = 1,
             lateCheckOutFee      = 1,
             earlyCheckInFee      = 1,
             effectiveStartDate   = "0001-01-01T00:00:00+00:00",
             effectiveEndDate     = "0001-01-01T00:00:00+00:00",
             effectiveOnMonday    = true,
             effectiveOnTuesday   = true,
             effectiveOnWednesday = true,
             effectiveOnThursday  = true,
             effectiveOnFriday    = true,
             effectiveOnSaturday  = true,
             effectiveOnSunday    = true,
             roomKind             = new
             {
                 id = 1
             }
         }
     },
         p => p.PermissionManageRate = true
         );
 }